From: Ben Pfaff Date: Mon, 20 Sep 2004 06:44:03 +0000 (+0000) Subject: Introduce PID_ERROR as an invalid exec return value. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8caa92eb58d76d3819876c87a20fabe0aab11378;p=pintos-anon Introduce PID_ERROR as an invalid exec return value. Make shell example check for invalid join return, because passing an invalid value to exec is allowed to kill the process. --- diff --git a/src/lib/user/syscall.h b/src/lib/user/syscall.h index d0a2250..188576d 100644 --- a/src/lib/user/syscall.h +++ b/src/lib/user/syscall.h @@ -5,6 +5,7 @@ #include typedef int pid_t; +#define PID_ERROR ((pid_t) -1) void halt (void) NO_RETURN; void exit (int status) NO_RETURN; diff --git a/src/tests/userprog/shell.c b/src/tests/userprog/shell.c index 905e18b..7b9570a 100644 --- a/src/tests/userprog/shell.c +++ b/src/tests/userprog/shell.c @@ -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"); + } } }