/*
* A Simple Testing Sandbox
*
- * (c) 2001 Martin Mares <mj@ucw.cz>
+ * (c) 2001--2004 Martin Mares <mj@ucw.cz>
*/
#define _LARGEFILE64_SOURCE
static int file_access;
static int verbose;
static int memory_limit;
+static int allow_times;
static char *redir_stdin, *redir_stdout;
+static char *set_cwd;
static pid_t box_pid;
static int is_ptraced;
case SYS_munmap:
case SYS_ioctl:
case SYS_uname:
+ case 252:
return 1;
case SYS_time:
case SYS_alarm:
case SYS_mmap2:
case SYS__sysctl:
return (filter_syscalls == 1);
+ case SYS_times:
+ return allow_times;
+ case SYS_kill:
+ if (u->regs.ebx == box_pid)
+ die("Commited suicide by signal %d.", (int)u->regs.ecx);
+ return 0;
default:
return 0;
}
memcpy(args, argv, argc * sizeof(char *));
args[argc] = NULL;
+ if (set_cwd && chdir(set_cwd))
+ die("chdir: %m");
if (redir_stdin)
{
close(0);
if (open(redir_stdout, O_WRONLY | O_CREAT | O_TRUNC, 0666) != 1)
die("open(\"%s\"): %m", redir_stdout);
}
- close(2);
- dup(1);
+ dup2(1, 2);
setpgrp();
if (memory_limit)
{
-m <size>\tLimit address space to <size> KB\n\
-o <file>\tRedirect stdout to <file>\n\
-t <time>\tStop after <time> seconds\n\
+-T\t\tAllow syscalls for measuring run time\n\
-v\t\tBe verbose\n\
-w\t\tMeasure wall clock time instead of run time\n\
");
{
int c;
uid_t uid;
- char *cwd = NULL;
- while ((c = getopt(argc, argv, "a:c:efi:m:o:t:vw")) >= 0)
+ while ((c = getopt(argc, argv, "a:c:efi:m:o:t:Tvw")) >= 0)
switch (c)
{
case 'a':
file_access = atol(optarg);
break;
case 'c':
- cwd = optarg;
+ set_cwd = optarg;
break;
case 'e':
pass_environ = 1;
case 't':
timeout = atol(optarg);
break;
+ case 'T':
+ allow_times++;
+ break;
case 'v':
verbose++;
break;
uid = geteuid();
if (setreuid(uid, uid) < 0)
die("setreuid: %m");
- if (cwd && chdir(cwd))
- die("chdir: %m");
box_pid = fork();
if (box_pid < 0)
die("fork: %m");