2 * A Simple Sandbox for MO-Eval
4 * (c) 2001--2008 Martin Mares <mj@ucw.cz>
7 #define _LARGEFILE64_SOURCE
22 #include <sys/ptrace.h>
23 #include <sys/signal.h>
24 #include <sys/sysinfo.h>
25 #include <sys/syscall.h>
26 #include <sys/resource.h>
28 #define NONRET __attribute__((noreturn))
29 #define UNUSED __attribute__((unused))
30 #define ARRAY_SIZE(a) (int)(sizeof(a)/sizeof(a[0]))
32 static int filter_syscalls; /* 0=off, 1=liberal, 2=totalitarian */
33 static int timeout; /* milliseconds */
34 static int wall_timeout;
35 static int extra_timeout;
36 static int pass_environ;
37 static int file_access;
39 static int memory_limit;
40 static char *redir_stdin, *redir_stdout, *redir_stderr;
44 static int is_ptraced;
45 static volatile int timer_tick;
46 static struct timeval start_time;
47 static int ticks_per_sec;
49 static int partial_line;
51 static int mem_peak_kb;
52 static int total_ms, wall_ms;
54 static void die(char *msg, ...) NONRET;
55 static void sample_mem_peak(void);
59 static FILE *metafile;
62 meta_open(const char *name)
64 if (!strcmp(name, "-"))
69 metafile = fopen(name, "w");
71 die("Failed to open metafile '%s'",name);
77 if (metafile && metafile != stdout)
81 static void __attribute__((format(printf,1,2)))
82 meta_printf(const char *fmt, ...)
89 vfprintf(metafile, fmt, args);
94 final_stats(struct rusage *rus)
96 struct timeval total, now, wall;
97 timeradd(&rus->ru_utime, &rus->ru_stime, &total);
98 total_ms = total.tv_sec*1000 + total.tv_usec/1000;
99 gettimeofday(&now, NULL);
100 timersub(&now, &start_time, &wall);
101 wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
103 meta_printf("time:%d.%03d\n", total_ms/1000, total_ms%1000);
104 meta_printf("time-wall:%d.%03d\n", wall_ms/1000, wall_ms%1000);
105 meta_printf("mem:%llu\n", (unsigned long long) mem_peak_kb * 1024);
108 /*** Messages and exits ***/
117 ptrace(PTRACE_KILL, box_pid);
118 kill(-box_pid, SIGKILL);
119 kill(box_pid, SIGKILL);
123 int p = wait4(box_pid, &stat, 0, &rus);
125 fprintf(stderr, "UGH: Lost track of the process\n");
141 /* Report an error of the sandbox itself */
142 static void NONRET __attribute__((format(printf,1,2)))
149 vsnprintf(buf, sizeof(buf), msg, args);
150 meta_printf("status:XX\nmessage:%s\n", buf);
156 /* Report an error of the program inside the sandbox */
157 static void NONRET __attribute__((format(printf,1,2)))
163 if (msg[0] && msg[1] && msg[2] == ':' && msg[3] == ' ')
165 meta_printf("status:%c%c\n", msg[0], msg[1]);
169 vsnprintf(buf, sizeof(buf), msg, args);
170 meta_printf("message:%s\n", buf);
176 /* Write a message, but only if in verbose mode */
177 static void __attribute__((format(printf,1,2)))
184 int len = strlen(msg);
186 partial_line = (msg[len-1] != '\n');
187 vfprintf(stderr, msg, args);
196 void *p = malloc(size);
198 die("Out of memory");
202 /*** Syscall rules ***/
204 static const char * const syscall_names[] = {
205 #include "box/syscall-table.h"
207 #define NUM_SYSCALLS ARRAY_SIZE(syscall_names)
208 #define NUM_ACTIONS (NUM_SYSCALLS+64)
211 A_DEFAULT, // Use the default action
212 A_NO, // Always forbid
213 A_YES, // Always permit
214 A_FILENAME, // Permit if arg1 is a known filename
216 A_NO_RETVAL = 32, // Does not return a value
217 A_SAMPLE_MEM = 64, // Sample memory usage before the syscall
218 A_LIBERAL = 128, // Valid only in liberal mode
219 // Must fit in a unsigned char
222 static unsigned char syscall_action[NUM_ACTIONS] = {
223 #define S(x) [__NR_##x]
225 // Syscalls permitted for specific file names
226 S(open) = A_FILENAME,
227 S(creat) = A_FILENAME,
228 S(unlink) = A_FILENAME,
229 S(oldstat) = A_FILENAME,
230 S(access) = A_FILENAME,
231 S(oldlstat) = A_FILENAME,
232 S(truncate) = A_FILENAME,
233 S(stat) = A_FILENAME,
234 S(lstat) = A_FILENAME,
235 S(truncate64) = A_FILENAME,
236 S(stat64) = A_FILENAME,
237 S(lstat64) = A_FILENAME,
238 S(readlink) = A_FILENAME,
240 // Syscalls permitted always
241 S(exit) = A_YES | A_SAMPLE_MEM,
255 S(ftruncate) = A_YES,
257 S(personality) = A_YES,
261 S(getresuid) = A_YES,
269 S(ftruncate64) = A_YES,
279 S(set_thread_area) = A_YES,
280 S(get_thread_area) = A_YES,
281 S(set_tid_address) = A_YES,
282 S(exit_group) = A_YES | A_SAMPLE_MEM,
284 // Syscalls permitted only in liberal mode
285 S(time) = A_YES | A_LIBERAL,
286 S(alarm) = A_YES | A_LIBERAL,
287 S(pause) = A_YES | A_LIBERAL,
288 S(signal) = A_YES | A_LIBERAL,
289 S(fchmod) = A_YES | A_LIBERAL,
290 S(sigaction) = A_YES | A_LIBERAL,
291 S(sgetmask) = A_YES | A_LIBERAL,
292 S(ssetmask) = A_YES | A_LIBERAL,
293 S(sigsuspend) = A_YES | A_LIBERAL,
294 S(sigpending) = A_YES | A_LIBERAL,
295 S(getrlimit) = A_YES | A_LIBERAL,
296 S(getrusage) = A_YES | A_LIBERAL,
297 S(ugetrlimit) = A_YES | A_LIBERAL,
298 S(gettimeofday) = A_YES | A_LIBERAL,
299 S(select) = A_YES | A_LIBERAL,
300 S(readdir) = A_YES | A_LIBERAL,
301 S(setitimer) = A_YES | A_LIBERAL,
302 S(getitimer) = A_YES | A_LIBERAL,
303 S(sigreturn) = A_YES | A_LIBERAL | A_NO_RETVAL,
304 S(mprotect) = A_YES | A_LIBERAL,
305 S(sigprocmask) = A_YES | A_LIBERAL,
306 S(getdents) = A_YES | A_LIBERAL,
307 S(getdents64) = A_YES | A_LIBERAL,
308 S(_newselect) = A_YES | A_LIBERAL,
309 S(fdatasync) = A_YES | A_LIBERAL,
310 S(mremap) = A_YES | A_LIBERAL,
311 S(poll) = A_YES | A_LIBERAL,
312 S(getcwd) = A_YES | A_LIBERAL,
313 S(nanosleep) = A_YES | A_LIBERAL,
314 S(rt_sigreturn) = A_YES | A_LIBERAL | A_NO_RETVAL,
315 S(rt_sigaction) = A_YES | A_LIBERAL,
316 S(rt_sigprocmask) = A_YES | A_LIBERAL,
317 S(rt_sigpending) = A_YES | A_LIBERAL,
318 S(rt_sigtimedwait) = A_YES | A_LIBERAL,
319 S(rt_sigqueueinfo) = A_YES | A_LIBERAL,
320 S(rt_sigsuspend) = A_YES | A_LIBERAL,
321 S(_sysctl) = A_YES | A_LIBERAL,
326 syscall_name(unsigned int id, char *buf)
328 if (id < NUM_SYSCALLS && syscall_names[id])
329 return syscall_names[id];
332 sprintf(buf, "#%d", id);
338 syscall_by_name(char *name)
340 for (unsigned int i=0; i<NUM_SYSCALLS; i++)
341 if (syscall_names[i] && !strcmp(syscall_names[i], name))
348 unsigned long l = strtoul(name, &ep, 0);
351 if (l >= NUM_ACTIONS)
357 set_syscall_action(char *a)
359 char *sep = strchr(a, '=');
360 enum action act = A_YES;
364 if (!strcmp(sep, "yes"))
366 else if (!strcmp(sep, "no"))
368 else if (!strcmp(sep, "file"))
374 int sys = syscall_by_name(a);
376 die("Unknown syscall `%s'", a);
377 if (sys >= NUM_ACTIONS)
378 die("Syscall `%s' out of range", a);
379 syscall_action[sys] = act;
388 struct path_rule *next;
391 static struct path_rule default_path_rules[] = {
394 { "/usr/lib/", A_YES },
395 { "/opt/lib/", A_YES },
396 { "/usr/share/zoneinfo/", A_YES },
397 { "/usr/share/locale/", A_YES },
398 { "/dev/null", A_YES },
399 { "/dev/zero", A_YES },
400 { "/proc/meminfo", A_YES },
401 { "/proc/self/stat", A_YES },
402 { "/proc/self/exe", A_YES }, // Needed by FPC 2.0.x runtime
405 static struct path_rule *user_path_rules;
406 static struct path_rule **last_path_rule = &user_path_rules;
409 set_path_action(char *a)
411 char *sep = strchr(a, '=');
412 enum action act = A_YES;
416 if (!strcmp(sep, "yes"))
418 else if (!strcmp(sep, "no"))
424 struct path_rule *r = xmalloc(sizeof(*r) + strlen(a) + 1);
425 r->path = (char *)(r+1);
430 last_path_rule = &r->next;
435 match_path_rule(struct path_rule *r, char *path)
439 if (*rr++ != *path++)
441 if (rr[-1] == '/' && !path[-1])
445 if (rr > r->path && rr[-1] != '/' && *path)
450 /*** Environment rules ***/
453 char *var; // Variable to match
454 char *val; // ""=clear, NULL=inherit
456 struct env_rule *next;
459 static struct env_rule *first_env_rule;
460 static struct env_rule **last_env_rule = &first_env_rule;
462 static struct env_rule default_env_rules[] = {
463 { "LIBC_FATAL_STDERR_", "1" }
467 set_env_action(char *a0)
469 struct env_rule *r = xmalloc(sizeof(*r) + strlen(a0) + 1);
470 char *a = (char *)(r+1);
473 char *sep = strchr(a, '=');
485 last_env_rule = &r->next;
491 match_env_var(char *env_entry, struct env_rule *r)
493 if (strncmp(env_entry, r->var, r->var_len))
495 return (env_entry[r->var_len] == '=');
499 apply_env_rule(char **env, int *env_sizep, struct env_rule *r)
501 // First remove the variable if already set
503 while (pos < *env_sizep && !match_env_var(env[pos], r))
505 if (pos < *env_sizep)
508 env[pos] = env[*env_sizep];
509 env[*env_sizep] = NULL;
512 // What is the new value?
518 new = xmalloc(r->var_len + 1 + strlen(r->val) + 1);
519 sprintf(new, "%s=%s", r->var, r->val);
524 while (environ[pos] && !match_env_var(environ[pos], r))
526 if (!(new = environ[pos]))
530 // Add it at the end of the array
531 env[(*env_sizep)++] = new;
532 env[*env_sizep] = NULL;
536 setup_environment(void)
538 // Link built-in rules with user rules
539 for (int i=ARRAY_SIZE(default_env_rules)-1; i >= 0; i--)
541 default_env_rules[i].next = first_env_rule;
542 first_env_rule = &default_env_rules[i];
545 // Scan the original environment
546 char **orig_env = environ;
548 while (orig_env[orig_size])
551 // For each rule, reserve one more slot and calculate length
553 for (struct env_rule *r = first_env_rule; r; r=r->next)
556 r->var_len = strlen(r->var);
559 // Create a new environment
560 char **env = xmalloc((orig_size + num_rules + 1) * sizeof(char *));
564 memcpy(env, environ, orig_size * sizeof(char *));
571 // Apply the rules one by one
572 for (struct env_rule *r = first_env_rule; r; r=r->next)
573 apply_env_rule(env, &size, r);
575 // Return the new env and pass some gossip
578 fprintf(stderr, "Passing environment:\n");
579 for (int i=0; env[i]; i++)
580 fprintf(stderr, "\t%s\n", env[i]);
585 /*** Syscall checks ***/
588 valid_filename(unsigned long addr)
590 char namebuf[4096], *p, *end;
594 err("FA: File access forbidden");
595 if (file_access >= 9)
600 sprintf(namebuf, "/proc/%d/mem", (int) box_pid);
601 mem_fd = open(namebuf, O_RDONLY);
603 die("open(%s): %m", namebuf);
610 int remains = PAGE_SIZE - (addr & (PAGE_SIZE-1));
611 int l = namebuf + sizeof(namebuf) - end;
615 err("FA: Access to file with name too long");
616 if (lseek64(mem_fd, addr, SEEK_SET) < 0)
617 die("lseek64(mem): %m");
618 remains = read(mem_fd, end, l);
620 die("read(mem): %m");
622 err("FA: Access to file with name out of memory");
629 msg("[%s] ", namebuf);
630 if (file_access >= 3)
633 // Everything in current directory is permitted
634 if (!strchr(namebuf, '/') && strcmp(namebuf, ".."))
637 // ".." anywhere in the path is forbidden
638 enum action act = A_DEFAULT;
639 if (strstr(namebuf, ".."))
643 for (struct path_rule *r = user_path_rules; r && !act; r=r->next)
644 act = match_path_rule(r, namebuf);
646 // Scan built-in rules
647 if (file_access >= 2)
648 for (int i=0; i<ARRAY_SIZE(default_path_rules) && !act; i++)
649 act = match_path_rule(&default_path_rules[i], namebuf);
652 err("FA: Forbidden access to file `%s'", namebuf);
655 // Check syscall. If invalid, return -1, otherwise return the action mask.
657 valid_syscall(struct user *u)
659 unsigned int sys = u->regs.orig_eax;
660 unsigned int act = (sys < NUM_ACTIONS) ? syscall_action[sys] : A_DEFAULT;
664 if (filter_syscalls != 1)
668 switch (act & A_ACTION_MASK)
675 valid_filename(u->regs.ebx);
683 if (u->regs.ebx == box_pid)
685 meta_printf("exitsig:%d\n", (int)u->regs.ecx);
686 err("SG: Committed suicide by signal %d", (int)u->regs.ecx);
690 if (u->regs.ebx == box_pid && u->regs.ecx == box_pid)
692 meta_printf("exitsig:%d\n", (int)u->regs.edx);
693 err("SG: Committed suicide by signal %d", (int)u->regs.edx);
702 signal_alarm(int unused UNUSED)
704 /* Time limit checks are synchronous, so we only schedule them there. */
710 signal_int(int unused UNUSED)
712 /* Interrupts are fatal, so no synchronization requirements. */
713 meta_printf("exitsig:%d\n", SIGINT);
714 err("SG: Interrupted");
717 #define PROC_BUF_SIZE 4096
719 read_proc_file(char *buf, char *name, int *fdp)
725 sprintf(buf, "/proc/%d/%s", (int) box_pid, name);
726 *fdp = open(buf, O_RDONLY);
728 die("open(%s): %m", buf);
730 lseek(*fdp, 0, SEEK_SET);
731 if ((c = read(*fdp, buf, PROC_BUF_SIZE-1)) < 0)
732 die("read on /proc/$pid/%s: %m", name);
733 if (c >= PROC_BUF_SIZE-1)
734 die("/proc/$pid/%s too long", name);
743 struct timeval now, wall;
745 gettimeofday(&now, NULL);
746 timersub(&now, &start_time, &wall);
747 wall_ms = wall.tv_sec*1000 + wall.tv_usec/1000;
748 if (wall_ms > wall_timeout)
749 err("TO: Time limit exceeded (wall clock)");
751 fprintf(stderr, "[wall time check: %d msec]\n", wall_ms);
755 char buf[PROC_BUF_SIZE], *x;
756 int utime, stime, ms;
757 static int proc_stat_fd;
758 read_proc_file(buf, "stat", &proc_stat_fd);
760 while (*x && *x != ' ')
765 die("proc stat syntax error 1");
766 while (*x && (*x != ')' || x[1] != ' '))
768 while (*x == ')' || *x == ' ')
770 if (sscanf(x, "%*c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d %d", &utime, &stime) != 2)
771 die("proc stat syntax error 2");
772 ms = (utime + stime) * 1000 / ticks_per_sec;
774 fprintf(stderr, "[time check: %d msec]\n", ms);
775 if (ms > timeout && ms > extra_timeout)
776 err("TO: Time limit exceeded");
781 sample_mem_peak(void)
784 * We want to find out the peak memory usage of the process, which is
785 * maintained by the kernel, but unforunately it gets lost when the
786 * process exits (it is not reported in struct rusage). Therefore we
787 * have to sample it whenever we suspect that the process is about
790 char buf[PROC_BUF_SIZE], *x;
791 static int proc_status_fd;
792 read_proc_file(buf, "status", &proc_status_fd);
798 while (*x && *x != ':' && *x != '\n')
800 if (!*x || *x == '\n')
803 while (*x == ' ' || *x == '\t')
807 while (*x && *x != '\n')
813 if (!strcmp(key, "VmPeak"))
815 int peak = atoi(val);
816 if (peak > mem_peak_kb)
822 msg("[mem-peak: %u KB]\n", mem_peak_kb);
828 int syscall_count = 0;
832 bzero(&sa, sizeof(sa));
833 sa.sa_handler = signal_int;
834 sigaction(SIGINT, &sa, NULL);
835 gettimeofday(&start_time, NULL);
836 ticks_per_sec = sysconf(_SC_CLK_TCK);
837 if (ticks_per_sec <= 0)
838 die("Invalid ticks_per_sec!");
839 if (timeout || wall_timeout)
841 sa.sa_handler = signal_alarm;
842 sigaction(SIGALRM, &sa, NULL);
855 p = wait4(box_pid, &stat, WUNTRACED, &rus);
863 die("wait4: unknown pid %d exited!", p);
868 if (WEXITSTATUS(stat))
872 meta_printf("exitcode:%d\n", WEXITSTATUS(stat));
873 err("RE: Exited with error status %d", WEXITSTATUS(stat));
877 // Internal error happened inside the child process and it has been already reported.
881 if (timeout && total_ms > timeout)
882 err("TO: Time limit exceeded");
883 if (wall_timeout && wall_ms > wall_timeout)
884 err("TO: Time limit exceeded (wall clock)");
886 fprintf(stderr, "OK (%d.%03d sec real, %d.%03d sec wall, %d MB, %d syscalls)\n",
887 total_ms/1000, total_ms%1000,
888 wall_ms/1000, wall_ms%1000,
889 (mem_peak_kb + 1023) / 1024,
893 if (WIFSIGNALED(stat))
896 meta_printf("exitsig:%d\n", WTERMSIG(stat));
898 err("SG: Caught fatal signal %d%s", WTERMSIG(stat), (syscall_count ? "" : " during startup"));
900 if (WIFSTOPPED(stat))
902 int sig = WSTOPSIG(stat);
906 msg("[ptrace status %08x] ", stat);
907 static int stop_count;
908 if (!stop_count++) /* Traceme request */
909 msg(">> Traceme request caught\n");
911 err("SG: Breakpoint");
912 ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
914 else if (sig == (SIGTRAP | 0x80))
917 msg("[ptrace status %08x] ", stat);
919 static unsigned int sys_tick, last_sys, last_act;
920 if (ptrace(PTRACE_GETREGS, box_pid, NULL, &u) < 0)
921 die("ptrace(PTRACE_GETREGS): %m");
922 unsigned int sys = u.regs.orig_eax;
923 if (++sys_tick & 1) /* Syscall entry */
927 msg(">> Syscall %-12s (%08lx,%08lx,%08lx) ", syscall_name(sys, namebuf), u.regs.ebx, u.regs.ecx, u.regs.edx);
931 if (sys == __NR_execve)
934 else if ((act = valid_syscall(&u)) >= 0)
938 if (act & A_SAMPLE_MEM)
944 * Unfortunately, PTRACE_KILL kills _after_ the syscall completes,
945 * so we have to change it to something harmless (e.g., an undefined
946 * syscall) and make the program continue.
948 u.regs.orig_eax = 0xffffffff;
949 if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0)
950 die("ptrace(PTRACE_SETREGS): %m");
951 err("FO: Forbidden syscall %s", syscall_name(sys, namebuf));
955 else /* Syscall return */
957 if (sys == 0xffffffff)
959 /* Some syscalls (sigreturn et al.) do not return a value */
960 if (!(last_act & A_NO_RETVAL))
961 err("XX: Syscall does not return, but it should");
966 err("XX: Mismatched syscall entry/exit");
968 if (last_act & A_NO_RETVAL)
971 msg("= %ld\n", u.regs.eax);
973 ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
975 else if (sig == SIGSTOP)
978 if (ptrace(PTRACE_SETOPTIONS, box_pid, NULL, (void *) PTRACE_O_TRACESYSGOOD) < 0)
979 die("ptrace(PTRACE_SETOPTIONS): %m");
980 ptrace(PTRACE_SYSCALL, box_pid, 0, 0);
982 else if (sig != SIGXCPU && sig != SIGXFSZ)
984 msg(">> Signal %d\n", sig);
985 sample_mem_peak(); /* Signal might be fatal, so update mem-peak */
986 ptrace(PTRACE_SYSCALL, box_pid, 0, sig);
990 meta_printf("exitsig:%d", sig);
991 err("SG: Received signal %d", sig);
995 die("wait4: unknown status %x, giving up!", stat);
1000 box_inside(int argc, char **argv)
1005 memcpy(args, argv, argc * sizeof(char *));
1007 if (set_cwd && chdir(set_cwd))
1012 if (open(redir_stdin, O_RDONLY) != 0)
1013 die("open(\"%s\"): %m", redir_stdin);
1018 if (open(redir_stdout, O_WRONLY | O_CREAT | O_TRUNC, 0666) != 1)
1019 die("open(\"%s\"): %m", redir_stdout);
1024 if (open(redir_stderr, O_WRONLY | O_CREAT | O_TRUNC, 0666) != 2)
1025 die("open(\"%s\"): %m", redir_stderr);
1032 rl.rlim_cur = rl.rlim_max = memory_limit * 1024;
1033 if (setrlimit(RLIMIT_AS, &rl) < 0)
1034 die("setrlimit: %m");
1036 rl.rlim_cur = rl.rlim_max = 64;
1037 if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
1038 die("setrlimit: %m");
1039 char **env = setup_environment();
1040 if (filter_syscalls)
1042 if (ptrace(PTRACE_TRACEME) < 0)
1043 die("ptrace(PTRACE_TRACEME): %m");
1044 /* Trick: Make sure that we are stopped until the boxkeeper wakes up. */
1047 execve(args[0], args, env);
1048 die("execve(\"%s\"): %m", args[0]);
1054 fprintf(stderr, "Invalid arguments!\n");
1056 Usage: box [<options>] -- <command> <arguments>\n\
1059 -a <level>\tSet file access level (0=none, 1=cwd, 2=/etc,/lib,..., 3=whole fs, 9=no checks; needs -f)\n\
1060 -c <dir>\tChange directory to <dir> first\n\
1061 -e\t\tInherit full environment of the parent process\n\
1062 -E <var>\tInherit the environment variable <var> from the parent process\n\
1063 -E <var>=<val>\tSet the environment variable <var> to <val>; unset it if <var> is empty\n\
1064 -f\t\tFilter system calls (-ff=very restricted)\n\
1065 -i <file>\tRedirect stdin from <file>\n\
1066 -m <size>\tLimit address space to <size> KB\n\
1067 -M <file>\tOutput process information to <file> (name:value)\n\
1068 -o <file>\tRedirect stdout to <file>\n\
1069 -p <path>\tPermit access to the specified path (or subtree if it ends with a `/')\n\
1070 -p <path>=<act>\tDefine action for the specified path (<act>=yes/no)\n\
1071 -r <file>\tRedirect stderr to <file>\n\
1072 -s <sys>\tPermit the specified syscall (be careful)\n\
1073 -s <sys>=<act>\tDefine action for the specified syscall (<act>=yes/no/file)\n\
1074 -t <time>\tSet run time limit (seconds, fractions allowed)\n\
1075 -T\t\tAllow syscalls for measuring run time\n\
1076 -v\t\tBe verbose (use multiple times for even more verbosity)\n\
1077 -w <time>\tSet wall clock time limit (seconds, fractions allowed)\n\
1078 -x <time>\tSet extra timeout, before which a timing-out program is not yet killed,\n\
1079 \t\tso that its real execution time is reported (seconds, fractions allowed)\n\
1085 main(int argc, char **argv)
1090 while ((c = getopt(argc, argv, "a:c:eE:fi:m:M:o:p:r:s:t:Tvw:x:")) >= 0)
1094 file_access = atol(optarg);
1103 if (!set_env_action(optarg))
1110 redir_stdin = optarg;
1113 memory_limit = atol(optarg);
1119 redir_stdout = optarg;
1122 if (!set_path_action(optarg))
1126 redir_stderr = optarg;
1129 if (!set_syscall_action(optarg))
1133 timeout = 1000*atof(optarg);
1136 syscall_action[__NR_times] = A_YES;
1142 wall_timeout = 1000*atof(optarg);
1145 extra_timeout = 1000*atof(optarg);
1154 if (setreuid(uid, uid) < 0)
1155 die("setreuid: %m");
1160 box_inside(argc-optind, argv+optind);
1163 die("Internal error: fell over edge of the world");