Revision abdeed06

b/vl.c
211 211
CharDriverState *serial_hds[MAX_SERIAL_PORTS];
212 212
CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
213 213
CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
214
CharDriverState *monitor_hds[MAX_MONITOR_DEVICES];
214 215
#ifdef TARGET_I386
215 216
int win2k_install_hack = 0;
216 217
int rtc_td_hack = 0;
......
273 274

  
274 275
static int default_serial = 1;
275 276
static int default_parallel = 1;
277
static int default_monitor = 1;
276 278

  
277 279
static struct {
278 280
    const char *driver;
......
4628 4630
        DEV_BT,        /* -bt          */
4629 4631
        DEV_SERIAL,    /* -serial      */
4630 4632
        DEV_PARALLEL,  /* -parallel    */
4633
        DEV_MONITOR,   /* -monitor     */
4631 4634
    } type;
4632 4635
    const char *cmdline;
4633 4636
    QTAILQ_ENTRY(device_config) next;
......
4659 4662
    return 0;
4660 4663
}
4661 4664

  
4662
static void serial_monitor_mux(const char *monitor_devices[])
4665
static void serial_monitor_mux(void)
4663 4666
{
4664
    struct device_config *serial;
4667
    struct device_config *mon0, *serial;
4665 4668
    const char *devname;
4666 4669

  
4667
    if (strcmp(monitor_devices[0],"stdio") != 0)
4668
        return;
4670
    QTAILQ_FOREACH(mon0, &device_configs, next) {
4671
        if (mon0->type != DEV_MONITOR)
4672
            continue;
4673
        if (strcmp(mon0->cmdline,"stdio") != 0)
4674
            return;
4675
        break;
4676
    }
4669 4677
    QTAILQ_FOREACH(serial, &device_configs, next) {
4670 4678
        if (serial->type != DEV_SERIAL)
4671 4679
            continue;
4672 4680
        devname = serial->cmdline;
4673 4681
        if (devname && !strcmp(devname,"mon:stdio")) {
4674
            monitor_devices[0] = NULL;
4682
            QTAILQ_REMOVE(&device_configs, mon0, next);
4675 4683
            break;
4676 4684
        } else if (devname && !strcmp(devname,"stdio")) {
4677
            monitor_devices[0] = NULL;
4685
            QTAILQ_REMOVE(&device_configs, mon0, next);
4678 4686
            serial->cmdline = "mon:stdio";
4679 4687
            break;
4680 4688
        }
......
4725 4733
    return 0;
4726 4734
}
4727 4735

  
4736
static int monitor_parse(const char *devname)
4737
{
4738
    static int index = 0;
4739
    char label[32];
4740

  
4741
    if (strcmp(devname, "none") == 0)
4742
        return 0;
4743
    if (index == MAX_MONITOR_DEVICES) {
4744
        fprintf(stderr, "qemu: too many monitor devices\n");
4745
        exit(1);
4746
    }
4747
    if (index == 0) {
4748
        snprintf(label, sizeof(label), "monitor");
4749
    } else {
4750
        snprintf(label, sizeof(label), "monitor%d", index);
4751
    }
4752
    monitor_hds[index] = qemu_chr_open(label, devname, NULL);
4753
    if (!monitor_hds[index]) {
4754
        fprintf(stderr, "qemu: could not open monitor device '%s'\n",
4755
                devname);
4756
        return -1;
4757
    }
4758
    index++;
4759
    return 0;
4760
}
4761

  
4728 4762
int main(int argc, char **argv, char **envp)
4729 4763
{
4730 4764
    const char *gdbstub_dev = NULL;
......
4740 4774
    QemuOpts *hda_opts = NULL, *opts;
4741 4775
    int optind;
4742 4776
    const char *r, *optarg;
4743
    CharDriverState *monitor_hds[MAX_MONITOR_DEVICES];
4744
    const char *monitor_devices[MAX_MONITOR_DEVICES];
4745
    int monitor_device_index;
4746 4777
    const char *virtio_consoles[MAX_VIRTIO_CONSOLES];
4747 4778
    int virtio_console_index;
4748 4779
    const char *loadvm = NULL;
......
4814 4845
        virtio_consoles[i] = NULL;
4815 4846
    virtio_console_index = 0;
4816 4847

  
4817
    monitor_devices[0] = "vc:80Cx24C";
4818
    for (i = 1; i < MAX_MONITOR_DEVICES; i++) {
4819
        monitor_devices[i] = NULL;
4820
    }
4821
    monitor_device_index = 0;
4822

  
4823 4848
    for (i = 0; i < MAX_NODES; i++) {
4824 4849
        node_mem[i] = 0;
4825 4850
        node_cpumask[i] = 0;
......
5237 5262
                    break;
5238 5263
                }
5239 5264
            case QEMU_OPTION_monitor:
5240
                if (monitor_device_index >= MAX_MONITOR_DEVICES) {
5241
                    fprintf(stderr, "qemu: too many monitor devices\n");
5242
                    exit(1);
5243
                }
5244
                monitor_devices[monitor_device_index] = optarg;
5245
                monitor_device_index++;
5265
                add_device_config(DEV_MONITOR, optarg);
5266
                default_monitor = 0;
5246 5267
                break;
5247 5268
            case QEMU_OPTION_chardev:
5248 5269
                opts = qemu_opts_parse(&qemu_chardev_opts, optarg, "backend");
......
5557 5578
            add_device_config(DEV_SERIAL, "stdio");
5558 5579
        if (default_parallel)
5559 5580
            add_device_config(DEV_PARALLEL, "null");
5560
       if (strncmp(monitor_devices[0], "vc", 2) == 0) {
5561
           monitor_devices[0] = "stdio";
5562
       }
5581
        if (default_monitor)
5582
            add_device_config(DEV_MONITOR, "stdio");
5563 5583
    } else {
5564 5584
        if (default_serial)
5565 5585
            add_device_config(DEV_SERIAL, "vc:80Cx24C");
5566 5586
        if (default_parallel)
5567 5587
            add_device_config(DEV_PARALLEL, "vc:80Cx24C");
5588
        if (default_monitor)
5589
            add_device_config(DEV_MONITOR, "vc:80Cx24C");
5568 5590
    }
5569 5591

  
5570 5592
    if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0)
......
5716 5738
                         ram_load, NULL);
5717 5739

  
5718 5740
    /* Maintain compatibility with multiple stdio monitors */
5719
    serial_monitor_mux(monitor_devices);
5741
    serial_monitor_mux();
5720 5742

  
5721 5743
    if (nb_numa_nodes > 0) {
5722 5744
        int i;
......
5760 5782
        }
5761 5783
    }
5762 5784

  
5763
    for (i = 0; i < MAX_MONITOR_DEVICES; i++) {
5764
        const char *devname = monitor_devices[i];
5765
        if (devname && strcmp(devname, "none")) {
5766
            char label[32];
5767
            if (i == 0) {
5768
                snprintf(label, sizeof(label), "monitor");
5769
            } else {
5770
                snprintf(label, sizeof(label), "monitor%d", i);
5771
            }
5772
            monitor_hds[i] = qemu_chr_open(label, devname, NULL);
5773
            if (!monitor_hds[i]) {
5774
                fprintf(stderr, "qemu: could not open monitor device '%s'\n",
5775
                        devname);
5776
                exit(1);
5777
            }
5778
        }
5779
    }
5780

  
5785
    if (foreach_device_config(DEV_MONITOR, monitor_parse) < 0)
5786
        exit(1);
5781 5787
    if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
5782 5788
        exit(1);
5783 5789
    if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
......
5903 5909
    text_consoles_set_display(display_state);
5904 5910

  
5905 5911
    for (i = 0; i < MAX_MONITOR_DEVICES; i++) {
5906
        if (monitor_devices[i] && monitor_hds[i]) {
5912
        if (monitor_hds[i]) {
5907 5913
            monitor_init(monitor_hds[i],
5908 5914
                         MONITOR_USE_READLINE |
5909 5915
                         ((i == 0) ? MONITOR_IS_DEFAULT : 0));

Also available in: Unified diff