Gerd Hoffmann <kra...@redhat.com> writes: > Switch over monitor to the new defaults system.
Even terser. > > Signed-off-by: Gerd Hoffmann <kra...@redhat.com> > --- > vl.c | 90 +++++++++++++++++++++++++++++++++-------------------------------- > 1 files changed, 46 insertions(+), 44 deletions(-) > > diff --git a/vl.c b/vl.c > index 739c3a7..4edc4a3 100644 > --- a/vl.c > +++ b/vl.c > @@ -210,6 +210,7 @@ int no_quit = 0; > CharDriverState *serial_hds[MAX_SERIAL_PORTS]; > CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; > CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; > +CharDriverState *monitor_hds[MAX_MONITOR_DEVICES]; > #ifdef TARGET_I386 > int win2k_install_hack = 0; > int rtc_td_hack = 0; > @@ -272,6 +273,7 @@ static void *boot_set_opaque; > > static int default_serial = 1; > static int default_parallel = 1; > +static int default_monitor = 1; > > static struct { > const char *driver; > @@ -4571,6 +4573,7 @@ struct device_config { > DEV_BT, /* -bt */ > DEV_SERIAL, /* -serial */ > DEV_PARALLEL, /* -parallel */ > + DEV_MONITOR, /* -monitor */ > } type; > const char *cmdline; > QTAILQ_ENTRY(device_config) next; > @@ -4602,22 +4605,27 @@ static int foreach_device_config(int type, int > (*func)(const char *cmdline)) > return 0; > } > > -static void serial_monitor_mux(const char *monitor_devices[]) > +static void serial_monitor_mux(void) > { > - struct device_config *serial; > + struct device_config *mon0, *serial; > const char *devname; > > - if (strcmp(monitor_devices[0],"stdio") != 0) > - return; > + QTAILQ_FOREACH(mon0, &device_configs, next) { > + if (mon0->type != DEV_MONITOR) > + continue; > + if (strcmp(mon0->cmdline,"stdio") != 0) > + return; > + break; > + } > QTAILQ_FOREACH(serial, &device_configs, next) { > if (serial->type != DEV_SERIAL) > continue; > devname = serial->cmdline; > if (devname && !strcmp(devname,"mon:stdio")) { > - monitor_devices[0] = NULL; > + QTAILQ_REMOVE(&device_configs, mon0, next); > break; > } else if (devname && !strcmp(devname,"stdio")) { > - monitor_devices[0] = NULL; > + QTAILQ_REMOVE(&device_configs, mon0, next); > serial->cmdline = "mon:stdio"; > break; > } > @@ -4668,6 +4676,28 @@ static int parallel_parse(const char *devname) > return 0; > } > > +static int monitor_parse(const char *devname) > +{ > + static int index = 0; > + char label[32]; > + > + if (strcmp(devname, "none") == 0) > + return 0; > + if (index == 0) { > + snprintf(label, sizeof(label), "monitor"); > + } else { > + snprintf(label, sizeof(label), "monitor%d", index); > + } > + monitor_hds[index] = qemu_chr_open(label, devname, NULL); Like for serial_parse(): don't you have to catch index >= MAX_MONITOR_DEVICES here? > + if (!monitor_hds[index]) { > + fprintf(stderr, "qemu: could not open monitor device '%s'\n", > + devname); > + return -1; > + } > + index++; > + return 0; > +} > + > int main(int argc, char **argv, char **envp) > { > const char *gdbstub_dev = NULL; [...]