comparison toys/other/timeout.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 ce0519f6457c
children cbb1aca81eca
comparison
equal deleted inserted replaced
1326:78a3eaf5555f 1327:85f297591693
58 TT.ktv.tv_sec = xparsetime(TT.k_timeout, 1000000, &TT.ktv.tv_usec); 58 TT.ktv.tv_sec = xparsetime(TT.k_timeout, 1000000, &TT.ktv.tv_usec);
59 TT.nextsig = SIGTERM; 59 TT.nextsig = SIGTERM;
60 if (TT.s_signal && -1 == (TT.nextsig = sig_to_num(TT.s_signal))) 60 if (TT.s_signal && -1 == (TT.nextsig = sig_to_num(TT.s_signal)))
61 error_exit("bad -s: '%s'", TT.s_signal); 61 error_exit("bad -s: '%s'", TT.s_signal);
62 62
63 if (!(TT.pid = fork())) xexec_optargs(1); 63 if (!(TT.pid = xfork())) xexec_optargs(1);
64 else { 64 else {
65 int status; 65 int status;
66 66
67 signal(SIGALRM, handler); 67 signal(SIGALRM, handler);
68 setitimer(ITIMER_REAL, &TT.itv, (void *)&toybuf); 68 setitimer(ITIMER_REAL, &TT.itv, (void *)&toybuf);
69 while (-1 == waitpid(TT.pid, &status, 0) && errno == EINTR); 69 while (-1 == waitpid(TT.pid, &status, 0) && errno == EINTR);
70 if (WIFEXITED(status)) toys.exitval = WEXITSTATUS(status); 70 toys.exitval = WIFEXITED(status)
71 else if (WIFSIGNALED(status)) toys.exitval = WTERMSIG(status); 71 ? WEXITSTATUS(status) : WTERMSIG(status) + 127;
72 else toys.exitval = 1;
73 } 72 }
74 } 73 }