diff options
author | Kevin Wolf <kwolf@redhat.com> | 2020-02-24 15:30:05 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2020-03-06 17:21:28 +0100 |
commit | f27a9bb3e9c3bd822243f6fc1d921f1334e37acf (patch) | |
tree | b49d9e73ae76af2c65765aee34cbf63cb2a9e7b3 /monitor/monitor.c | |
parent | f2098725aa3ebdb4095bc1951c1c0680adbdecc7 (diff) |
qmp: Fail gracefully if chardev is already in use
Trying to attach a QMP monitor to a chardev that is already in use
results in a crash because monitor_init_qmp() passes &error_abort to
qemu_chr_fe_init():
$ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=foo --mon foo,mode=control --mon foo,mode=control
Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220:
qemu-system-x86_64: --mon foo,mode=control: Device 'foo' is in use
Abgebrochen (Speicherabzug geschrieben)
Fix this by allowing monitor_init_qmp() to return an error and passing
any error in qemu_chr_fe_init() to its caller instead of aborting.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200224143008.13362-18-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'monitor/monitor.c')
-rw-r--r-- | monitor/monitor.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/monitor/monitor.c b/monitor/monitor.c index f8a6ef795b..00d287655e 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -614,6 +614,7 @@ void monitor_init_globals_core(void) int monitor_init(MonitorOptions *opts, Error **errp) { Chardev *chr; + Error *local_err = NULL; chr = qemu_chr_find(opts->chardev); if (chr == NULL) { @@ -623,7 +624,7 @@ int monitor_init(MonitorOptions *opts, Error **errp) switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty); + monitor_init_qmp(chr, opts->pretty, &local_err); break; case MONITOR_MODE_READLINE: if (opts->pretty) { @@ -636,6 +637,10 @@ int monitor_init(MonitorOptions *opts, Error **errp) g_assert_not_reached(); } + if (local_err) { + error_propagate(errp, local_err); + return -1; + } return 0; } |