9 #include <sys/resource.h>
13 static void handler(int s)
17 static int start(char *argv[])
23 t_setrlim(RLIMIT_STACK, 100*1024);
24 t_setrlim(RLIMIT_CPU, 2);
26 t_error("%s exec failed: %s\n", argv[0], strerror(errno));
30 t_error("%s fork failed: %s\n", argv[0], strerror(errno));
36 int main(int argc, char *argv[])
45 t_error("usage: ./run cmd [args..]\n");
50 sigaddset(&set, SIGCHLD);
51 sigprocmask(SIG_BLOCK, &set, 0);
52 signal(SIGCHLD, handler);
54 if (sigtimedwait(&set, 0, &(struct timespec){5,0}) == -1) {
57 if (kill(pid, SIGKILL) == -1)
58 t_error("%s kill failed: %s\n", argv[0], strerror(errno));
60 if (waitpid(pid, &status, 0) != pid) {
61 t_error("%s waitpid failed: %s\n", argv[0], strerror(errno));
64 if (WIFEXITED(status)) {
65 if (WEXITSTATUS(status) == 0)
67 t_printf("FAIL %s [status %d]\n", argv[0], WEXITSTATUS(status));
69 t_printf("FAIL %s [timed out]\n", argv[0]);
70 } else if (WIFSIGNALED(status)) {
71 t_printf("FAIL %s [signal %s]\n", argv[0], strsignal(WTERMSIG(status)));
73 t_printf("FAIL %s [unknown]\n", argv[0]);