From e859eda58501cd20a2e6988fb4acc1756bc4d278 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:47 +0200 Subject: qemu-char: check optional fields using has_* Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index a030e6b01e..a538217b00 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3493,7 +3493,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) { HANDLE out; - if (file->in) { + if (file->has_in) { error_setg(errp, "input file not supported"); return NULL; } @@ -3544,7 +3544,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) return NULL; } - if (file->in) { + if (file->has_in) { flags = O_RDONLY; in = qmp_chardev_open_file_source(file->in, flags, errp); if (error_is_set(errp)) { -- cgit v1.2.3 From 20c397607cb54905f452921259b4baa9c8a1d008 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:48 +0200 Subject: qemu-char: use more specific error_setg_* variants Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index a538217b00..e3b3224886 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2604,7 +2604,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, memset(&ss, 0, ss_len); if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) != 0) { - error_setg(errp, "getsockname: %s", strerror(errno)); + error_setg_errno(errp, errno, "getsockname"); return NULL; } @@ -3529,7 +3529,7 @@ static int qmp_chardev_open_file_source(char *src, int flags, TFR(fd = qemu_open(src, flags, 0666)); if (fd == -1) { - error_setg(errp, "open %s: %s", src, strerror(errno)); + error_setg_file_open(errp, errno, src); } return fd; } -- cgit v1.2.3 From fdca2124adc293f84f2b7aaf0df43faa6b6bf420 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:49 +0200 Subject: qemu-char: print notification to stderr Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index e3b3224886..371f6308c5 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2666,8 +2666,8 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, } if (is_listen && is_waitconnect) { - printf("QEMU waiting for connection on: %s\n", - chr->filename); + fprintf(stderr, "QEMU waiting for connection on: %s\n", + chr->filename); tcp_chr_accept(s->listen_chan, G_IO_IN, chr); qemu_set_nonblock(s->listen_fd); } -- cgit v1.2.3 From e668287d4413395be1a0f9ef292bb6d0c1006e29 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:51 +0200 Subject: qemu-char: don't leak opts on error Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 371f6308c5..0cda56cbca 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3178,7 +3178,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, if (i == NULL) { error_setg(errp, "chardev: backend \"%s\" not found", qemu_opt_get(opts, "backend")); - return NULL; + goto err; } if (!cd->open) { -- cgit v1.2.3 From 99aec0123ce5ba307dc357c5bf1e0f22d2be0931 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:52 +0200 Subject: qemu-char: use ChardevBackendKind in CharDriver Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 0cda56cbca..90754e68de 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3120,7 +3120,7 @@ typedef struct CharDriver { /* old, pre qapi */ CharDriverState *(*open)(QemuOpts *opts); /* new, qapi-based */ - int kind; + ChardevBackendKind kind; void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); } CharDriver; @@ -3137,7 +3137,7 @@ void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *) backends = g_slist_append(backends, s); } -void register_char_driver_qapi(const char *name, int kind, +void register_char_driver_qapi(const char *name, ChardevBackendKind kind, void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)) { CharDriver *s; -- cgit v1.2.3 From dc2c4eca89ec5ee7b7a4c2563c991a14a7c5ee84 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:53 +0200 Subject: qemu-char: minor mux chardev fixes mux failure path has a memory leak. creating a mux chardev can't fail though, so just assert() that instead of fixing an error path which never ever runs anyway ... Also fix bid being leaked while being at it. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 90754e68de..392de29a91 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3186,7 +3186,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, ChardevBackend *backend = g_new0(ChardevBackend, 1); ChardevReturn *ret = NULL; const char *id = qemu_opts_id(opts); - const char *bid = NULL; + char *bid = NULL; if (qemu_opt_get_bool(opts, "mux", 0)) { bid = g_strdup_printf("%s-base", id); @@ -3213,9 +3213,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, backend->kind = CHARDEV_BACKEND_KIND_MUX; backend->mux->chardev = g_strdup(bid); ret = qmp_chardev_add(id, backend, errp); - if (error_is_set(errp)) { - goto qapi_out; - } + assert(!error_is_set(errp)); } chr = qemu_chr_find(id); @@ -3223,6 +3221,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, qapi_out: qapi_free_ChardevBackend(backend); qapi_free_ChardevReturn(ret); + g_free(bid); return chr; } -- cgit v1.2.3 From bb6fb7c0857aeda7982ac14460328edf3c29cfc8 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:54 +0200 Subject: qemu-char: add -chardev mux support Allow to explicitly create mux chardevs on the command line, like you can using QMP. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 392de29a91..c097ca16d1 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3115,6 +3115,19 @@ static void qemu_chr_parse_memory(QemuOpts *opts, ChardevBackend *backend, } } +static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + const char *chardev = qemu_opt_get(opts, "chardev"); + + if (chardev == NULL) { + error_setg(errp, "chardev: mux: no chardev given"); + return; + } + backend->mux = g_new0(ChardevMux, 1); + backend->mux->chardev = g_strdup(chardev); +} + typedef struct CharDriver { const char *name; /* old, pre qapi */ @@ -3481,6 +3494,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "size", .type = QEMU_OPT_SIZE, + },{ + .name = "chardev", + .type = QEMU_OPT_STRING, }, { /* end of list */ } }, @@ -3771,6 +3787,8 @@ static void register_types(void) register_char_driver_qapi("console", CHARDEV_BACKEND_KIND_CONSOLE, NULL); register_char_driver_qapi("pipe", CHARDEV_BACKEND_KIND_PIPE, qemu_chr_parse_pipe); + register_char_driver_qapi("mux", CHARDEV_BACKEND_KIND_MUX, + qemu_chr_parse_mux); } type_init(register_types); -- cgit v1.2.3 From 58a3714c529b1b97ee078ea25b58f731aabcbfff Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jun 2013 08:39:55 +0200 Subject: qemu-char: report udp backend errors Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Signed-off-by: Michael Tokarev --- qemu-char.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index c097ca16d1..5a8f9c09c6 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2255,6 +2255,8 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts *opts) fd = inet_dgram_opts(opts, &local_err); if (fd < 0) { + qerror_report_err(local_err); + error_free(local_err); return NULL; } return qemu_chr_open_udp_fd(fd); -- cgit v1.2.3