/[path-sandbox]/trunk/sandbox.c
Gentoo

Diff of /trunk/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 156 Revision 157
31struct sandbox_info_t { 31struct sandbox_info_t {
32 char sandbox_log[SB_PATH_MAX]; 32 char sandbox_log[SB_PATH_MAX];
33 char sandbox_debug_log[SB_PATH_MAX]; 33 char sandbox_debug_log[SB_PATH_MAX];
34 char sandbox_lib[SB_PATH_MAX]; 34 char sandbox_lib[SB_PATH_MAX];
35 char sandbox_rc[SB_PATH_MAX]; 35 char sandbox_rc[SB_PATH_MAX];
36 char portage_tmp_dir[SB_PATH_MAX]; 36 char work_dir[SB_PATH_MAX];
37 char var_tmp_dir[SB_PATH_MAX]; 37 char var_tmp_dir[SB_PATH_MAX];
38 char tmp_dir[SB_PATH_MAX]; 38 char tmp_dir[SB_PATH_MAX];
39 char *home_dir; 39 char *home_dir;
40} sandbox_info_t; 40} sandbox_info_t;
41 41
44static int print_debug = 0; 44static int print_debug = 0;
45static int stop_called = 0; 45static int stop_called = 0;
46 46
47int sandbox_setup(struct sandbox_info_t *sandbox_info) 47int sandbox_setup(struct sandbox_info_t *sandbox_info)
48{ 48{
49 char *workdir;
50
51 if (NULL != getenv(ENV_EBUILD)) {
52 workdir = getenv(ENV_PORTAGE_TMPDIR) ?
53 getenv(ENV_PORTAGE_TMPDIR) :
54 PORTAGE_TMPDIR;
49 /* Do not resolve symlinks, etc .. libsandbox will handle that. */ 55 /* Do not resolve symlinks, etc .. libsandbox will handle that. */
50 if (1 != is_dir(getenv(ENV_PORTAGE_TMPDIR) ? getenv(ENV_PORTAGE_TMPDIR) 56 if (1 != is_dir(workdir, 1)) {
51 : PORTAGE_TMPDIR, 1)) { 57 perror("sandbox: Failed to get " ENV_PORTAGE_TMPDIR);
52 perror("sandbox: Failed to get portage_tmp_dir");
53 return -1; 58 return -1;
54 } 59 }
55 snprintf(sandbox_info->portage_tmp_dir, SB_PATH_MAX, "%s", 60 snprintf(sandbox_info->work_dir, SB_PATH_MAX, "%s", workdir);
56 getenv(ENV_PORTAGE_TMPDIR) ? getenv(ENV_PORTAGE_TMPDIR)
57 : PORTAGE_TMPDIR);
58 setenv(ENV_PORTAGE_TMPDIR, sandbox_info->portage_tmp_dir, 1); 61 setenv(ENV_PORTAGE_TMPDIR, sandbox_info->work_dir, 1);
62 } else {
63 if (NULL == getcwd(sandbox_info->work_dir, SB_PATH_MAX)) {
64 perror("sandbox: Failed to get current directory");
65 return -1;
66 }
67 }
59 68
60 /* Do not resolve symlinks, etc .. libsandbox will handle that. */ 69 /* Do not resolve symlinks, etc .. libsandbox will handle that. */
61 if (1 != is_dir(VAR_TMPDIR, 1)) { 70 if (1 != is_dir(VAR_TMPDIR, 1)) {
62 perror("sandbox: Failed to get var_tmp_dir"); 71 perror("sandbox: Failed to get var_tmp_dir");
63 return -1; 72 return -1;
182 "/dev/shm/ngpt:/var/log/scrollkeeper.log:" 191 "/dev/shm/ngpt:/var/log/scrollkeeper.log:"
183 "/usr/tmp/conftest:/usr/lib/conftest:" 192 "/usr/tmp/conftest:/usr/lib/conftest:"
184 "/usr/lib32/conftest:/usr/lib64/conftest:" 193 "/usr/lib32/conftest:/usr/lib64/conftest:"
185 "/usr/tmp/cf:/usr/lib/cf:/usr/lib32/cf:/usr/lib64/cf", 194 "/usr/tmp/cf:/usr/lib/cf:/usr/lib32/cf:/usr/lib64/cf",
186 sandbox_info->home_dir, sandbox_info->home_dir, 195 sandbox_info->home_dir, sandbox_info->home_dir,
187 (NULL != sandbox_info->portage_tmp_dir) ? sandbox_info->portage_tmp_dir : tmp_dir, 196 (NULL != sandbox_info->work_dir) ? sandbox_info->work_dir : tmp_dir,
188 sandbox_info->tmp_dir, sandbox_info->var_tmp_dir, 197 sandbox_info->tmp_dir, sandbox_info->var_tmp_dir,
189 "/tmp/:/var/tmp/"); 198 "/tmp/:/var/tmp/");
190} 199}
191 200
192void get_sandbox_predict_envvar(char *buf, struct sandbox_info_t *sandbox_info) 201void get_sandbox_predict_envvar(char *buf, struct sandbox_info_t *sandbox_info)
450 perror("sandbox: Out of memory (environ)"); 459 perror("sandbox: Out of memory (environ)");
451 exit(EXIT_FAILURE); 460 exit(EXIT_FAILURE);
452 } 461 }
453 462
454 /* if the portage temp dir was present, cd into it */ 463 /* if the portage temp dir was present, cd into it */
455 if (NULL != sandbox_info.portage_tmp_dir) 464 if (NULL != sandbox_info.work_dir)
456 chdir(sandbox_info.portage_tmp_dir); 465 chdir(sandbox_info.work_dir);
457 466
458 argv_bash = (char **)malloc(6 * sizeof(char *)); 467 argv_bash = (char **)malloc(6 * sizeof(char *));
459 argv_bash[0] = strdup("/bin/bash"); 468 argv_bash[0] = strdup("/bin/bash");
460 argv_bash[1] = strdup("-rcfile"); 469 argv_bash[1] = strdup("-rcfile");
461 argv_bash[2] = strdup(sandbox_info.sandbox_rc); 470 argv_bash[2] = strdup(sandbox_info.sandbox_rc);

Legend:
Removed from v.156  
changed lines
  Added in v.157

  ViewVC Help
Powered by ViewVC 1.1.20