From 4465f7686194b9da8d1cf1a0e5813b794b84aa38 Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Mon, 21 Jan 2013 02:50:15 +0000 Subject: [PATCH] Isolate: Add chdir flag. Repurpose --cg shorthand flag. Using -c is consistent with mo-box. --- isolate/isolate.1.txt | 6 +++++- isolate/isolate.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/isolate/isolate.1.txt b/isolate/isolate.1.txt index b3252de..f59dadf 100644 --- a/isolate/isolate.1.txt +++ b/isolate/isolate.1.txt @@ -92,6 +92,10 @@ OPTIONS Redirect standard error output to 'file'. The 'file' has to be accessible inside the sandbox. +*-c, --chdir=*'dir':: + Change directory to 'dir' before executing the program. This path must be + relative to the root of the sandbox. + *-p, --processes*[*=*'max']:: Permit the program to create up to 'max' processes and/or threads. Please keep in mind that time and memory limit do not work with multiple processes @@ -169,7 +173,7 @@ to constrain programs consisting of multiple processes. Please note that this feature needs special system setup described in the REQUIREMENTS section. -*-c, --cg*:: +*--cg*:: Enable use of control groups. *--cg-mem=*'size':: diff --git a/isolate/isolate.c b/isolate/isolate.c index 16ea06e..1131ddb 100644 --- a/isolate/isolate.c +++ b/isolate/isolate.c @@ -47,6 +47,7 @@ static int block_quota; static int inode_quota; static int max_processes = 1; static char *redir_stdin, *redir_stdout, *redir_stderr; +static char *set_cwd; static int cg_enable; static int cg_memory_limit; @@ -1134,6 +1135,9 @@ box_inside(void *arg) setup_rlimits(); char **env = setup_environment(); + if (set_cwd && chdir(set_cwd)) + die("chdir: %m"); + execve(args[0], args, env); die("execve(\"%s\"): %m", args[0]); } @@ -1287,6 +1291,7 @@ enum opt_code { OPT_RUN, OPT_CLEANUP, OPT_VERSION, + OPT_CG, OPT_CG_MEM, OPT_CG_TIMING, }; @@ -1295,7 +1300,8 @@ static const char short_opts[] = "b:c:d:eE:i:k:m:M:o:p::q:r:t:vw:x:"; static const struct option long_opts[] = { { "box-id", 1, NULL, 'b' }, - { "cg", 1, NULL, 'c' }, + { "chdir", 1, NULL, 'c' }, + { "cg", 0, NULL, OPT_CG }, { "cg-mem", 1, NULL, OPT_CG_MEM }, { "cg-timing", 0, NULL, OPT_CG_TIMING }, { "cleanup", 0, NULL, OPT_CLEANUP }, @@ -1336,6 +1342,9 @@ main(int argc, char **argv) box_id = atoi(optarg); break; case 'c': + set_cwd = optarg; + break; + case OPT_CG: cg_enable = 1; break; case 'd': -- 2.39.2