9 #include <sys/resource.h>
13 static void handler(int s
)
17 static int start(char *wrap
, char *argv
[])
23 t_setrlim(RLIMIT_STACK
, 100*1024);
29 t_error("%s exec failed: %s\n", argv
[0], strerror(errno
));
35 static void usage(char *argv
[])
37 t_error("usage: %s [-t timeoutsec] [-w wrapcmd] cmd [args..]\n", argv
[0]);
41 int main(int argc
, char *argv
[])
51 while ((opt
= getopt(argc
, argv
, "w:t:")) != -1) {
57 timeoutsec
= atoi(optarg
);
67 sigaddset(&set
, SIGCHLD
);
68 sigprocmask(SIG_BLOCK
, &set
, 0);
69 signal(SIGCHLD
, handler
);
70 pid
= start(wrap
, argv
);
72 t_error("%s fork failed: %s\n", argv
[0], strerror(errno
));
73 t_printf("FAIL %s [internal]\n", argv
[0]);
76 if (sigtimedwait(&set
, 0, &(struct timespec
){timeoutsec
,0}) == -1) {
80 t_error("%s sigtimedwait failed: %s\n", argv
[0], strerror(errno
));
81 if (kill(pid
, SIGKILL
) == -1)
82 t_error("%s kill failed: %s\n", argv
[0], strerror(errno
));
84 if (waitpid(pid
, &status
, 0) != pid
) {
85 t_error("%s waitpid failed: %s\n", argv
[0], strerror(errno
));
86 t_printf("FAIL %s [internal]\n", argv
[0]);
89 if (WIFEXITED(status
)) {
90 if (WEXITSTATUS(status
) == 0)
92 t_printf("FAIL %s [status %d]\n", argv
[0], WEXITSTATUS(status
));
94 t_printf("FAIL %s [timed out]\n", argv
[0]);
95 } else if (WIFSIGNALED(status
)) {
96 t_printf("FAIL %s [signal %s]\n", argv
[0], strsignal(WTERMSIG(status
)));
98 t_printf("FAIL %s [unknown]\n", argv
[0]);