diff options
author | kraxel <kraxel> | 2009-03-18 08:05:50 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2009-03-18 08:05:50 +0000 |
commit | 24f9b290712cdbfadf38f57f4acc700932c56d66 (patch) | |
tree | 2aa16ed284056f1d416d57e92788369db6658b8e | |
parent | 1acc30b633345c2fb773605a83df36d97a79303b (diff) | |
download | qemu-gtk-24f9b290712cdbfadf38f57f4acc700932c56d66.tar.gz |
- make qemu-gtk handle qemu 0.10.0 monitor output.(info vnc change).
- qemu-run fixups (non-gfx mode, handle non-root case).
-rw-r--r-- | monitor.c | 71 | ||||
-rwxr-xr-x | qemu-run | 16 |
2 files changed, 63 insertions, 24 deletions
@@ -31,6 +31,56 @@ static void show_error(struct qemu_window *win, char *cmd, char *reply) gtk_widget_show_all(dialog); } +static void monitor_parse_vnc(struct qemu_window *win, char *reply) +{ + char *ptr, host[64]; + int vnc = 0; + int tty = 0; + int passwd = 0; + int port; + + if (strcmp(reply, "VNC server disabled") == 0 || /* qemu 0.9.x */ + strcmp(reply, "Server: disabled") == 0) { /* qemu 0.10.x */ + if (win->sercon) + tty = 1; + } else if (1 == sscanf(reply, "VNC server active on: %127[^\r\n]", + win->vnc_display)) { + /* qemu 0.9.x */ + if (strstr(reply, "No client connected")) { + vnc = 1; + if (strstr(win->vnc_display, ",password")) + passwd = 1; + } + } else if (strncmp(reply, "Server:",7) == 0) { + /* qemu 0.10.x */ + ptr = strstr(reply, "address: "); + if (2 == sscanf(ptr, "address: %63[^:]:%d", host, &port)) { + snprintf(win->vnc_display, sizeof(win->vnc_display), + "%s:%d", host, port - 5900); + vnc = 1; + if (strstr(reply, "auth: vnc")) + passwd = 1; + } + } + + if (vnc) { + if (passwd) { + win->vnc_password = malloc(32); +#if 1 + /* FIXME: do something less predictable */ + srand(time(NULL)+getpid()); + snprintf(win->vnc_password, 32, "%x", rand() & 0xfffffff); +#endif + win->vnc_send_password = 1; + monitor_append(win, "change vnc password"); + } else { + vnc_connect(win); + } + } else if (tty) { + conn_open_term(win, "serial0", win->sercon, 0); + } +} + static int monitor_parse(struct qemu_window *win, char *buf, int len) { char *reply, *prompt, *cmd; @@ -94,26 +144,7 @@ static int monitor_parse(struct qemu_window *win, char *buf, int len) conn_open_term(win, "serial0", win->sercon, 0); } else if (0 == strcmp(cmd, "info vnc")) { - if (1 == sscanf(reply, "VNC server active on: %127[^\r\n]", - win->vnc_display) && - strstr(reply, "No client connected")) { - if (strstr(win->vnc_display, ",password")) { - win->vnc_password = malloc(32); -#if 1 - /* FIXME: do something less predictable */ - srand(time(NULL)+getpid()); - snprintf(win->vnc_password, 32, "%x", rand() & 0xfffffff); -#endif - win->vnc_send_password = 1; - monitor_append(win, "change vnc password"); - } else { - vnc_connect(win); - } - } else if (strcmp(reply, "VNC server disabled") == 0) { - /* no vnc -> try opening serial console instead */ - if (win->sercon) - conn_open_term(win, "serial0", win->sercon, 0); - } + monitor_parse_vnc(win, reply); } else if (0 == strcmp(cmd, "change vnc password")) { vnc_connect(win); @@ -228,12 +228,18 @@ foreach my $nic (@nics) { $_ . "=" . $nic->{$_}; } keys %{$nic}) . "\n" if $debug; - $nic->{'netconfig'} = "tap,vlan=" . $nic->{'vlan'}; - $nic->{'nicconfig'} = "nic,vlan=" . $nic->{'vlan'}; - $nic->{'netconfig'} .= ",script=" . $tapup; - $nic->{'netconfig'} .= ",downscript=" . $tapdown; + if ($< == 0) { + # root + $nic->{'netconfig'} = "tap,vlan=" . $nic->{'vlan'}; + $nic->{'netconfig'} .= ",script=" . $tapup; + $nic->{'netconfig'} .= ",downscript=" . $tapdown; + } else { + # user + $nic->{'netconfig'} = "user,vlan=" . $nic->{'vlan'}; + } + $nic->{'nicconfig'} = "nic,vlan=" . $nic->{'vlan'}; $nic->{'nicconfig'} .= ",macaddr=" . $nic->{'mac-address'} if defined($nic->{'mac-address'}); $nic->{'nicconfig'} .= ",model=" . $nic->{'model-type'} @@ -253,6 +259,8 @@ push @cmdline, "unix:,server,nowait"; if ($graphics) { push @cmdline, "-vnc"; push @cmdline, "127.0.0.1:0,to=128,password"; +} else { + push @cmdline, "-nographic"; } # prepare |