comparison 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
comparison
equal deleted inserted replaced
1326:78a3eaf5555f 1327:85f297591693
56 * waits for the child to exit and return the status to parent 56 * waits for the child to exit and return the status to parent
57 */ 57 */
58 static int exec_wait(char **args) 58 static int exec_wait(char **args)
59 { 59 {
60 int status = 0; 60 int status = 0;
61 pid_t pid = fork(); 61 pid_t pid = xfork();
62 62
63 if (!pid) xexec(args); 63 if (!pid) xexec(args);
64 else if (pid > 0) waitpid(pid, &status, 0); 64 else if waitpid(pid, &status, 0);
65 else perror_exit("fork failed"); 65
66 return WEXITSTATUS(status); 66 return WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status)+127;
67 } 67 }
68 68
69 /* create_copy_skel(), This function will create the home directory of the 69 /* create_copy_skel(), This function will create the home directory of the
70 * user, by copying /etc/skel/ contents to /home/<username>. 70 * user, by copying /etc/skel/ contents to /home/<username>.
71 * Then change the ownership of home dir to the UID and GID of new user, 71 * Then change the ownership of home dir to the UID and GID of new user,