Introduce PID_ERROR as an invalid exec return value.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 20 Sep 2004 06:44:03 +0000 (06:44 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 20 Sep 2004 06:44:03 +0000 (06:44 +0000)
Make shell example check for invalid join return,
because passing an invalid value to exec is allowed to kill the
process.

src/lib/user/syscall.h
src/tests/userprog/shell.c

index d0a22500dd8f36f7090ca57ee23173ff85ecfff4..188576d35edbe205507fa2d61e6dc4644014be87 100644 (file)
@@ -5,6 +5,7 @@
 #include <debug.h>
 
 typedef int pid_t;
+#define PID_ERROR ((pid_t) -1)
 
 void halt (void) NO_RETURN;
 void exit (int status) NO_RETURN;
index 905e18b0275570ce2f678cc9d87b8f72ee84bc03..7b9570ac9d564df88b3aef8c71d14600b1a481e6 100644 (file)
@@ -23,6 +23,12 @@ main (void)
       
       /* Execute command. */
       if (cp > command) 
-        join (exec (command));
+        {
+          pid_t pid = exec (command);
+          if (pid != PID_ERROR)
+            join (pid);
+          else
+            printf ("exec failed\n");
+        }
     }
 }