From 8a0c402207a9c4b0dc58f417ae3bc169c6f62f0f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 20 Sep 2004 06:44:03 +0000 Subject: [PATCH] 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. --- src/lib/user/syscall.h | 1 + src/tests/userprog/shell.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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"); + } } } -- 2.30.2