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=8a0c402207a9c4b0dc58f417ae3bc169c6f62f0f;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"); + } } }