diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-10-22 12:52:58 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-10-24 15:27:21 +0200 |
commit | c39860e6dc90f6ee2e82ee078f978c5d7f3df86a (patch) | |
tree | 7af723a578b9f33ee172254b20fd9bbdd519cd0c /qemu-char.c | |
parent | 5d300164d00cf9d37a4481831d2c993255dfa0e8 (diff) |
char: replace qemu_chr_claim/release with qemu_chr_fe_init/deinit
Now that all front end use qemu_chr_fe_init(), we can move chardev
claiming in init(), and add a function deinit() to release the chardev
and cleanup handlers.
The qemu_chr_fe_claim_no_fail() for property are gone, since the
property will raise an error instead. In other cases, where there is
already an error path, an error is raised instead. Finally, other cases
are handled by &error_abort in qemu_chr_fe_init().
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20161022095318.17775-19-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r-- | qemu-char.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/qemu-char.c b/qemu-char.c index 115909fd48..e5e80381d7 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -776,6 +776,7 @@ static void mux_chr_close(struct CharDriverState *chr) { MuxDriver *d = chr->opaque; + qemu_chr_fe_deinit(&d->chr); g_free(d); } @@ -884,6 +885,17 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp) return true; } +void qemu_chr_fe_deinit(CharBackend *b) +{ + assert(b); + + if (b->chr) { + qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL); + b->chr->avail_connections++; + b->chr = NULL; + } +} + void qemu_chr_fe_set_handlers(CharBackend *b, IOCanReadHandler *fd_can_read, IOReadHandler *fd_read, @@ -4114,7 +4126,6 @@ CharDriverState *qemu_chr_new_noreplay(const char *label, const char *filename) error_report_err(err); } if (chr && qemu_opt_get_bool(opts, "mux", 0)) { - qemu_chr_fe_claim_no_fail(chr); monitor_init(chr, MONITOR_USE_READLINE); } qemu_opts_del(opts); @@ -4190,29 +4201,6 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, return tag; } -int qemu_chr_fe_claim(CharDriverState *s) -{ - if (s->avail_connections < 1) { - return -1; - } - s->avail_connections--; - return 0; -} - -void qemu_chr_fe_claim_no_fail(CharDriverState *s) -{ - if (qemu_chr_fe_claim(s) != 0) { - fprintf(stderr, "%s: error chardev \"%s\" already used\n", - __func__, s->label); - exit(1); - } -} - -void qemu_chr_fe_release(CharDriverState *s) -{ - s->avail_connections++; -} - void qemu_chr_fe_disconnect(CharBackend *be) { CharDriverState *chr = be->chr; |