Fix `get' behavior.
[pintos-anon] / src / utils / pintos
index 798708ed912dd73a728773e66b0ec6ed477c707b..9b3d0e7adecc1a5d29b21bacf270e1add5233b16 100755 (executable)
@@ -73,7 +73,7 @@ die "no command specified; use --help for help\n"
     if @ARGV < 1;
 my ($cmd) = shift @ARGV;
 if ($cmd eq 'run') {
-    run_vm (@ARGV);
+    run_vm ('EXEC', @ARGV);
 } elsif ($cmd eq 'make-disk') {
     usage () if @ARGV != 2;
     my ($file, $mb) = @ARGV;
@@ -101,7 +101,7 @@ if ($cmd eq 'run') {
     # Do copy.
     my (@cmd) = ("-ci", $guestfn, $size, "-q");
     unshift (@cmd, "-f") if $format;
-    run_vm (@cmd);
+    run_vm ('EXEC', @cmd);
 } elsif ($cmd eq 'get') {
     usage () if @ARGV != 1 && @ARGV != 2;
     my ($guestfn, $hostfn) = @ARGV;
@@ -110,26 +110,26 @@ if ($cmd eq 'run') {
 
     # Create scratch disk big enough for any file in the filesystem
     # (modulo sparse files).
-    die "fs.dsk: $!\n" if ! -e "fs.dsk";
+    die "$disks[1]: $!\n" if ! -e $disks[1];
     my ($fs_size) = -s _;
-    my ($scratch_size) = -s "scratch.dsk";
+    my ($scratch_size) = -s $disks[2];
     $scratch_size = 0 if !defined $scratch_size;
-    create_disk ("scratch.dsk", $fs_size / 1024 + 16)
+    create_disk ($disks[2], $fs_size / 1024 + 16)
        if $scratch_size < $fs_size + 16384;
 
     # Do copy.
-    run_vm ("-co", $guestfn, "-q");
+    run_vm ('FORK', "-co", $guestfn, "-q");
 
     # Read out scratch disk.
-    print "copying $guestfn from scratch.dsk to $hostfn...\n";
-    open (SRC, "<scratch.dsk") or die "scratch.dsk: open: $!\n";
+    print "copying $guestfn from $disks[2] to $hostfn...\n";
+    open (SRC, "<$disks[2]") or die "$disks[2]: open: $!\n";
     open (DST, ">$hostfn") or die "$hostfn: create: $!\n";
     my ($input);
-    read (SRC, $input, 512) == 512 or die "scratch.dsk: read error\n";
-    my ($size) = unpack ("%V", $input);
-    $size != 0xffffffff or die "$guestfn: too big for scratch.dsk?";
+    read (SRC, $input, 512) == 512 or die "$disks[2]: read error\n";
+    my ($size) = unpack ("V", $input);
+    $size != 0xffffffff or die "$guestfn: too big for $disks[2]?";
     my ($src);
-    read (SRC, $src, $size) == $size or die "scratch.dsk: read error\n";
+    read (SRC, $src, $size) == $size or die "$disks[2]: read error\n";
     print DST $src or die "$hostfn: write error\n";
     close (DST);
     close (SRC);
@@ -185,6 +185,9 @@ sub create_disk {
 }
 
 sub run_vm {
+    my ($fork) = shift;
+    $fork eq 'FORK' || $fork eq 'EXEC' or die;
+
     our (@disks);
 
     die "$disks[0]: can't find OS disk\n" if ! -e $disks[0];
@@ -234,7 +237,8 @@ sub run_vm {
 
        my (@cmd) = ($bin, '-q');
        push (@cmd, '-j', $jitter) if defined $jitter;
-       run_command_no_die (@cmd);
+       print join (' ', @cmd), "\n";
+       $fork eq 'EXEC' ? exec (@cmd) : system (@cmd);
     } elsif ($sim eq 'qemu') {
        print "warning: qemu doesn't support --terminal\n"
            if $vga eq 'terminal';
@@ -329,11 +333,6 @@ sub run_command {
     die "command failed\n" if system (@_);
 }
 
-sub run_command_no_die {
-    print join (' ', @_), "\n";
-    system (@_);
-}
-
 sub search_path {
     my ($target) = @_;
     for my $dir (split (':', $ENV{PATH})) {