aboutsummaryrefslogtreecommitdiffstats
path: root/qemu-run
diff options
context:
space:
mode:
Diffstat (limited to 'qemu-run')
-rwxr-xr-xqemu-run36
1 files changed, 20 insertions, 16 deletions
diff --git a/qemu-run b/qemu-run
index e07cfa6..fcfd09a 100755
--- a/qemu-run
+++ b/qemu-run
@@ -15,12 +15,13 @@ my $showmon = defined($opts{'m'}) ? 1 : 0;
my $tapup = "/etc/qemu-virbr0-ifup";
my $tapdown = "/etc/qemu-virbr0-ifdown";
my $mondir = $ENV{HOME} . "/.qemu-gtk";
-my $monitor = $mondir . "/" . $name . ",server,nowait";
+my $monitor = $mondir . "/" . $name;
# vars
my ($xml, $help, $parser, @cmdline, $pid);
my $level = 0;
my $indent = 3;
+my $skip_qemu = 0;
my @xml_path;
my $xml_string;
@@ -246,7 +247,7 @@ foreach my $nic (@nics) {
# build cmdline -- hardwired stuff
push @cmdline, "-monitor";
-push @cmdline, "unix:$monitor";
+push @cmdline, "unix:" . $monitor . ",server,nowait";
push @cmdline, "-serial";
push @cmdline, "unix:,server,nowait";
if ($graphics) {
@@ -254,31 +255,34 @@ if ($graphics) {
push @cmdline, "127.0.0.1:0,to=128,password";
}
-print "-- \n" if $debug;
-
# prepare
+print "-- \n" if $debug;
mkdir $mondir unless -d $mondir;
-unlink($monitor);
# run qemu emulator
-$pid = fork();
-die "fork: $!" unless defined($pid);
-if (0 == $pid) {
- # child
- print join(", ", map { "\"$_\"" } @cmdline) . "\n"
- if $debug;
- exec(@cmdline);
- exit(1);
+if (-S $monitor and !system("fuser", "-s", $monitor)) {
+ # still running
+ printf "VM %s still running, reconnecting\n", $name;
+} else {
+ $pid = fork();
+ die "fork: $!" unless defined($pid);
+ if (0 == $pid) {
+ # child
+ print join(", ", map { "\"$_\"" } @cmdline) . "\n"
+ if $debug;
+ exec(@cmdline);
+ exit(1);
+ }
}
# run qemu-gtk
@cmdline = ();
push @cmdline, "qemu-gtk";
push @cmdline, "-m" if $showmon;
-push @cmdline, "unix:$monitor";
-foreach my $i (0 ... 256) {
+push @cmdline, "unix:" . $monitor . ",server,nowait";
+foreach my $i (0 ... 100) {
last if -S $monitor;
- sleep(0.03);
+ sleep(0.1);
}
print join(", ", map { "\"$_\"" } @cmdline) . "\n"
if $debug;