diff toys/pending/useradd.c @ 1327:85f297591693 draft

Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
author Rob Landley <rob@landley.net>
date Sat, 31 May 2014 12:33:24 -0500
parents 0752b2d58909
children c7bf4541d5be
line wrap: on
line diff
--- a/toys/pending/useradd.c	Thu May 29 08:21:48 2014 -0500
+++ b/toys/pending/useradd.c	Sat May 31 12:33:24 2014 -0500
@@ -58,12 +58,12 @@
 static int exec_wait(char **args)
 {
   int status = 0;
-  pid_t pid = fork();
+  pid_t pid = xfork();
 
   if (!pid) xexec(args);
-  else if (pid > 0) waitpid(pid, &status, 0);
-  else perror_exit("fork failed");
-  return WEXITSTATUS(status);
+  else if waitpid(pid, &status, 0);
+
+  return WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status)+127;
 }
 
 /* create_copy_skel(), This function will create the home directory of the