summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/baum.c1
-rw-r--r--backends/msmouse.c3
-rw-r--r--backends/testdev.c1
-rw-r--r--include/sysemu/char.h12
-rw-r--r--qemu-char.c55
-rw-r--r--spice-qemu-char.c5
-rw-r--r--ui/console.c11
-rw-r--r--ui/gtk.c3
8 files changed, 59 insertions, 32 deletions
diff --git a/backends/baum.c b/backends/baum.c
index a51643496e..919844e7f0 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -566,6 +566,7 @@ static void baum_free(struct CharDriverState *chr)
static CharDriverState *chr_baum_init(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevCommon *common = backend->u.braille.data;
diff --git a/backends/msmouse.c b/backends/msmouse.c
index 448369fd1c..733ca80f48 100644
--- a/backends/msmouse.c
+++ b/backends/msmouse.c
@@ -151,6 +151,7 @@ static QemuInputHandler msmouse_handler = {
static CharDriverState *qemu_chr_open_msmouse(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevCommon *common = backend->u.msmouse.data;
@@ -164,7 +165,7 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,
chr->chr_write = msmouse_chr_write;
chr->chr_free = msmouse_chr_free;
chr->chr_accept_input = msmouse_chr_accept_input;
- chr->explicit_be_open = true;
+ *be_opened = false;
mouse = g_new0(MouseState, 1);
mouse->hs = qemu_input_handler_register((DeviceState *)mouse,
diff --git a/backends/testdev.c b/backends/testdev.c
index 1ba8bf25a1..60156e320e 100644
--- a/backends/testdev.c
+++ b/backends/testdev.c
@@ -112,6 +112,7 @@ static void testdev_free(struct CharDriverState *chr)
static CharDriverState *chr_testdev_init(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
TestdevCharState *testdev;
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 0628b14531..0a149428cf 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -109,7 +109,6 @@ struct CharDriverState {
char *filename;
int logfd;
int be_open;
- int explicit_be_open;
int is_mux;
guint fd_in_tag;
bool replay;
@@ -474,10 +473,15 @@ void qemu_chr_set_feature(CharDriverState *chr,
CharDriverFeature feature);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
+typedef void CharDriverParse(QemuOpts *opts, ChardevBackend *backend,
+ Error **errp);
+typedef CharDriverState *CharDriverCreate(const char *id,
+ ChardevBackend *backend,
+ ChardevReturn *ret, bool *be_opened,
+ Error **errp);
+
void register_char_driver(const char *name, ChardevBackendKind kind,
- void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp),
- CharDriverState *(*create)(const char *id, ChardevBackend *backend,
- ChardevReturn *ret, Error **errp));
+ CharDriverParse *parse, CharDriverCreate *create);
extern int term_escape_char;
diff --git a/qemu-char.c b/qemu-char.c
index 5e9684d61d..6dd779fc3c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -509,6 +509,7 @@ static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
static CharDriverState *qemu_chr_open_null(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -519,7 +520,7 @@ static CharDriverState *qemu_chr_open_null(const char *id,
return NULL;
}
chr->chr_write = null_chr_write;
- chr->explicit_be_open = true;
+ *be_opened = false;
return chr;
}
@@ -836,7 +837,9 @@ static void mux_set_focus(MuxDriver *d, int focus)
static CharDriverState *qemu_chr_open_mux(const char *id,
ChardevBackend *backend,
- ChardevReturn *ret, Error **errp)
+ ChardevReturn *ret,
+ bool *be_opened,
+ Error **errp)
{
ChardevMux *mux = backend->u.mux.data;
CharDriverState *chr, *drv;
@@ -868,7 +871,7 @@ static CharDriverState *qemu_chr_open_mux(const char *id,
/* only default to opened state if we've realized the initial
* set of muxes
*/
- chr->explicit_be_open = muxes_realized ? 0 : 1;
+ *be_opened = muxes_realized;
chr->is_mux = 1;
if (!qemu_chr_fe_init(&d->chr, drv, errp)) {
qemu_chr_free(chr);
@@ -1280,6 +1283,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out,
static CharDriverState *qemu_chr_open_pipe(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevHostdev *opts = backend->u.pipe.data;
@@ -1362,6 +1366,7 @@ static void qemu_chr_free_stdio(struct CharDriverState *chr)
static CharDriverState *qemu_chr_open_stdio(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevStdio *opts = backend->u.stdio.data;
@@ -1609,6 +1614,7 @@ static void pty_chr_free(struct CharDriverState *chr)
static CharDriverState *qemu_chr_open_pty(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -1645,7 +1651,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
chr->chr_update_read_handler = pty_chr_update_read_handler;
chr->chr_free = pty_chr_free;
chr->chr_add_watch = pty_chr_add_watch;
- chr->explicit_be_open = true;
+ *be_opened = false;
s->ioc = QIO_CHANNEL(qio_channel_file_new_fd(master_fd));
s->timer_tag = 0;
@@ -1845,6 +1851,7 @@ static void qemu_chr_free_tty(CharDriverState *chr)
static CharDriverState *qemu_chr_open_tty_fd(int fd,
ChardevCommon *backend,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -1975,6 +1982,7 @@ static void pp_free(CharDriverState *chr)
static CharDriverState *qemu_chr_open_pp_fd(int fd,
ChardevCommon *backend,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -2047,6 +2055,7 @@ static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
static CharDriverState *qemu_chr_open_pp_fd(int fd,
ChardevCommon *backend,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -2058,7 +2067,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd,
chr->opaque = (void *)(intptr_t)fd;
chr->chr_write = null_chr_write;
chr->chr_ioctl = pp_ioctl;
- chr->explicit_be_open = true;
+ *be_opened = false;
return chr;
}
#endif
@@ -2387,6 +2396,7 @@ static int win_chr_pipe_init(CharDriverState *chr, const char *filename,
static CharDriverState *qemu_chr_open_pipe(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevHostdev *opts = backend->u.pipe.data;
@@ -2433,6 +2443,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out,
static CharDriverState *qemu_chr_open_win_con(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevCommon *common = backend->u.console.data;
@@ -2578,6 +2589,7 @@ static void win_stdio_free(CharDriverState *chr)
static CharDriverState *qemu_chr_open_stdio(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -2753,6 +2765,7 @@ static void udp_chr_free(CharDriverState *chr)
static CharDriverState *qemu_chr_open_udp(QIOChannelSocket *sioc,
ChardevCommon *backend,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr = NULL;
@@ -2772,7 +2785,7 @@ static CharDriverState *qemu_chr_open_udp(QIOChannelSocket *sioc,
chr->chr_update_read_handler = udp_chr_update_read_handler;
chr->chr_free = udp_chr_free;
/* be isn't opened until we get a connection */
- chr->explicit_be_open = true;
+ *be_opened = false;
return chr;
}
@@ -3504,6 +3517,7 @@ static void ringbuf_chr_free(struct CharDriverState *chr)
static CharDriverState *qemu_chr_open_ringbuf(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevRingbuf *opts = backend->u.ringbuf.data;
@@ -4032,17 +4046,14 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
typedef struct CharDriver {
const char *name;
ChardevBackendKind kind;
- void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
- CharDriverState *(*create)(const char *id, ChardevBackend *backend,
- ChardevReturn *ret, Error **errp);
+ CharDriverParse *parse;
+ CharDriverCreate *create;
} CharDriver;
static GSList *backends;
void register_char_driver(const char *name, ChardevBackendKind kind,
- void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp),
- CharDriverState *(*create)(const char *id, ChardevBackend *backend,
- ChardevReturn *ret, Error **errp))
+ CharDriverParse *parse, CharDriverCreate *create)
{
CharDriver *s;
@@ -4429,6 +4440,7 @@ QemuOptsList qemu_chardev_opts = {
static CharDriverState *qmp_chardev_open_file(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevFile *file = backend->u.file.data;
@@ -4464,6 +4476,7 @@ static CharDriverState *qmp_chardev_open_file(const char *id,
static CharDriverState *qmp_chardev_open_serial(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevHostdev *serial = backend->u.serial.data;
@@ -4488,6 +4501,7 @@ static int qmp_chardev_open_file_source(char *src, int flags,
static CharDriverState *qmp_chardev_open_file(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevFile *file = backend->u.file.data;
@@ -4522,6 +4536,7 @@ static CharDriverState *qmp_chardev_open_file(const char *id,
static CharDriverState *qmp_chardev_open_serial(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevHostdev *serial = backend->u.serial.data;
@@ -4533,7 +4548,7 @@ static CharDriverState *qmp_chardev_open_serial(const char *id,
return NULL;
}
qemu_set_nonblock(fd);
- return qemu_chr_open_tty_fd(fd, common, errp);
+ return qemu_chr_open_tty_fd(fd, common, be_opened, errp);
}
#endif
@@ -4541,6 +4556,7 @@ static CharDriverState *qmp_chardev_open_serial(const char *id,
static CharDriverState *qmp_chardev_open_parallel(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevHostdev *parallel = backend->u.parallel.data;
@@ -4551,7 +4567,7 @@ static CharDriverState *qmp_chardev_open_parallel(const char *id,
if (fd < 0) {
return NULL;
}
- return qemu_chr_open_pp_fd(fd, common, errp);
+ return qemu_chr_open_pp_fd(fd, common, be_opened, errp);
}
#endif
@@ -4580,6 +4596,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
static CharDriverState *qmp_chardev_open_socket(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
CharDriverState *chr;
@@ -4656,7 +4673,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,
chr->chr_add_watch = tcp_chr_add_watch;
chr->chr_update_read_handler = tcp_chr_update_read_handler;
/* be isn't opened until we get a connection */
- chr->explicit_be_open = true;
+ *be_opened = false;
chr->filename = SocketAddress_to_str("disconnected:",
addr, is_listen, is_telnet);
@@ -4712,6 +4729,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,
static CharDriverState *qmp_chardev_open_udp(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevUdp *udp = backend->u.udp.data;
@@ -4724,7 +4742,7 @@ static CharDriverState *qmp_chardev_open_udp(const char *id,
object_unref(OBJECT(sioc));
return NULL;
}
- return qemu_chr_open_udp(sioc, common, errp);
+ return qemu_chr_open_udp(sioc, common, be_opened, errp);
}
@@ -4748,6 +4766,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
Error *local_err = NULL;
GSList *i;
CharDriver *cd;
+ bool be_opened = true;
chr = qemu_chr_find(id);
if (chr) {
@@ -4759,7 +4778,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
cd = i->data;
if (cd->kind == backend->type) {
- chr = cd->create(id, backend, ret, &local_err);
+ chr = cd->create(id, backend, ret, &be_opened, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto out_error;
@@ -4778,7 +4797,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
if (!chr->filename) {
chr->filename = g_strdup(ChardevBackendKind_lookup[backend->type]);
}
- if (!chr->explicit_be_open) {
+ if (be_opened) {
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
}
QTAILQ_INSERT_TAIL(&chardevs, chr, next);
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 89fae6dc3f..276c4aef68 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -282,7 +282,6 @@ static CharDriverState *chr_open(const char *subtype,
chr->chr_add_watch = spice_chr_add_watch;
chr->chr_free = spice_chr_free;
chr->chr_set_fe_open = set_fe_open;
- chr->explicit_be_open = true;
chr->chr_accept_input = spice_chr_accept_input;
QLIST_INSERT_HEAD(&spice_chars, s, next);
@@ -293,6 +292,7 @@ static CharDriverState *chr_open(const char *subtype,
static CharDriverState *qemu_chr_open_spice_vmc(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevSpiceChannel *spicevmc = backend->u.spicevmc.data;
@@ -311,6 +311,7 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id,
return NULL;
}
+ *be_opened = false;
return chr_open(type, spice_vmc_set_fe_open, common, errp);
}
@@ -318,6 +319,7 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id,
static CharDriverState *qemu_chr_open_spice_port(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
+ bool *be_opened,
Error **errp)
{
ChardevSpicePort *spiceport = backend->u.spiceport.data;
@@ -335,6 +337,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id,
if (!chr) {
return NULL;
}
+ *be_opened = false;
s = chr->opaque;
s->sin.portname = g_strdup(name);
diff --git a/ui/console.c b/ui/console.c
index f490346780..ed888e55ea 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -2079,10 +2079,6 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)
s->chr = chr;
chr->opaque = s;
chr->chr_set_echo = text_console_set_echo;
- /* console/chardev init sometimes completes elsewhere in a 2nd
- * stage, so defer OPENED events until they are fully initialized
- */
- chr->explicit_be_open = true;
if (display_state) {
text_console_do_init(chr, display_state);
@@ -2093,8 +2089,13 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)
static VcHandler *vc_handler = text_console_init;
static CharDriverState *vc_init(const char *id, ChardevBackend *backend,
- ChardevReturn *ret, Error **errp)
+ ChardevReturn *ret, bool *be_opened,
+ Error **errp)
{
+ /* console/chardev init sometimes completes elsewhere in a 2nd
+ * stage, so defer OPENED events until they are fully initialized
+ */
+ *be_opened = false;
return vc_handler(backend->u.vc.data, errp);
}
diff --git a/ui/gtk.c b/ui/gtk.c
index 83984f6546..25e6d9969d 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1685,9 +1685,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)
/* Temporary, until gd_vc_vte_init runs. */
chr->opaque = g_new0(VirtualConsole, 1);
- /* defer OPENED events until our vc is fully initialized */
- chr->explicit_be_open = true;
-
vcs[nb_vcs++] = chr;
return chr;