X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbox.c;h=bcfe233f84345b2043d0f4dbe5a22f18c12c8332;hb=3ee84a61340017dccf73f53194cd7ec4c7ec838b;hp=3dc4a199b0930908d38dde0cc4cac6280ae1e00a;hpb=b9ff9e0a4370eca27410e0295682d806576a42be;p=eval.git diff --git a/src/box.c b/src/box.c index 3dc4a19..bcfe233 100644 --- a/src/box.c +++ b/src/box.c @@ -1,7 +1,7 @@ /* * A Simple Testing Sandbox * - * (c) 2001 Martin Mares + * (c) 2001--2004 Martin Mares */ #define _LARGEFILE64_SOURCE @@ -37,6 +37,7 @@ 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; @@ -430,6 +431,8 @@ box_inside(int argc, char **argv) memcpy(args, argv, argc * sizeof(char *)); args[argc] = NULL; + if (set_cwd && chdir(set_cwd)) + die("chdir: %m"); if (redir_stdin) { close(0); @@ -442,8 +445,7 @@ box_inside(int argc, char **argv) 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) { @@ -488,7 +490,6 @@ main(int argc, char **argv) { int c; uid_t uid; - char *cwd = NULL; while ((c = getopt(argc, argv, "a:c:efi:m:o:t:Tvw")) >= 0) switch (c) @@ -497,7 +498,7 @@ main(int argc, char **argv) file_access = atol(optarg); break; case 'c': - cwd = optarg; + set_cwd = optarg; break; case 'e': pass_environ = 1; @@ -535,8 +536,6 @@ main(int argc, char **argv) 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");