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

Diff of /trunk/src/sandbox.c

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

Revision 140 Revision 141
34#include "sandbox.h" 34#include "sandbox.h"
35 35
36struct sandbox_info_t { 36struct sandbox_info_t {
37 char sandbox_log[SB_PATH_MAX]; 37 char sandbox_log[SB_PATH_MAX];
38 char sandbox_debug_log[SB_PATH_MAX]; 38 char sandbox_debug_log[SB_PATH_MAX];
39 char sandbox_dir[SB_PATH_MAX];
40 char sandbox_lib[SB_PATH_MAX]; 39 char sandbox_lib[SB_PATH_MAX];
41 char sandbox_rc[SB_PATH_MAX]; 40 char sandbox_rc[SB_PATH_MAX];
42 char portage_tmp_dir[SB_PATH_MAX]; 41 char portage_tmp_dir[SB_PATH_MAX];
43 char var_tmp_dir[SB_PATH_MAX]; 42 char var_tmp_dir[SB_PATH_MAX];
44 char tmp_dir[SB_PATH_MAX]; 43 char tmp_dir[SB_PATH_MAX];
48static char *tmp_dir; 47static char *tmp_dir;
49 48
50static int print_debug = 0; 49static int print_debug = 0;
51static int stop_called = 0; 50static int stop_called = 0;
52 51
53int sandbox_setup(char *argv[], struct sandbox_info_t *sandbox_info) 52int sandbox_setup(struct sandbox_info_t *sandbox_info)
54{ 53{
55 if (NULL == realpath(getenv(ENV_PORTAGE_TMPDIR) ? getenv(ENV_PORTAGE_TMPDIR) 54 if (NULL == realpath(getenv(ENV_PORTAGE_TMPDIR) ? getenv(ENV_PORTAGE_TMPDIR)
56 : PORTAGE_TMPDIR, 55 : PORTAGE_TMPDIR,
57 sandbox_info->portage_tmp_dir)) { 56 sandbox_info->portage_tmp_dir)) {
58 perror(">>> get portage_tmp_dir"); 57 perror(">>> get portage_tmp_dir");
75 sandbox_info->home_dir = getenv("HOME"); 74 sandbox_info->home_dir = getenv("HOME");
76 if (!sandbox_info->home_dir) { 75 if (!sandbox_info->home_dir) {
77 sandbox_info->home_dir = tmp_dir; 76 sandbox_info->home_dir = tmp_dir;
78 setenv("HOME", sandbox_info->home_dir, 1); 77 setenv("HOME", sandbox_info->home_dir, 1);
79 } 78 }
80
81 /* Generate base sandbox path */
82 get_sandbox_path(argv[0], sandbox_info->sandbox_dir);
83 79
84 /* Generate sandbox lib path */ 80 /* Generate sandbox lib path */
85 get_sandbox_lib(sandbox_info->sandbox_lib); 81 get_sandbox_lib(sandbox_info->sandbox_lib);
86 82
87 /* Generate sandbox bashrc path */ 83 /* Generate sandbox bashrc path */
252 char *ld_preload_envvar = NULL; 248 char *ld_preload_envvar = NULL;
253 char *orig_ld_preload_envvar = NULL; 249 char *orig_ld_preload_envvar = NULL;
254 250
255 /* Unset these, as its easier than replacing when setting up our 251 /* Unset these, as its easier than replacing when setting up our
256 * new environment below */ 252 * new environment below */
257 unsetenv(ENV_SANDBOX_DIR);
258 unsetenv(ENV_SANDBOX_LIB); 253 unsetenv(ENV_SANDBOX_LIB);
259 unsetenv(ENV_SANDBOX_BASHRC); 254 unsetenv(ENV_SANDBOX_BASHRC);
260 unsetenv(ENV_SANDBOX_LOG); 255 unsetenv(ENV_SANDBOX_LOG);
261 unsetenv(ENV_SANDBOX_DEBUG_LOG); 256 unsetenv(ENV_SANDBOX_DEBUG_LOG);
262 257
296 if (NULL == new_environ) 291 if (NULL == new_environ)
297 return NULL; 292 return NULL;
298 293
299 /* First add our new variables to the beginning - this is due to some 294 /* First add our new variables to the beginning - this is due to some
300 * weirdness that I cannot remember */ 295 * weirdness that I cannot remember */
301 sandbox_setenv(new_environ, ENV_SANDBOX_DIR, sandbox_info->sandbox_dir);
302 sandbox_setenv(new_environ, ENV_SANDBOX_LIB, sandbox_info->sandbox_lib); 296 sandbox_setenv(new_environ, ENV_SANDBOX_LIB, sandbox_info->sandbox_lib);
303 sandbox_setenv(new_environ, ENV_SANDBOX_BASHRC, sandbox_info->sandbox_rc); 297 sandbox_setenv(new_environ, ENV_SANDBOX_BASHRC, sandbox_info->sandbox_rc);
304 sandbox_setenv(new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log); 298 sandbox_setenv(new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log);
305 sandbox_setenv(new_environ, ENV_SANDBOX_DEBUG_LOG, 299 sandbox_setenv(new_environ, ENV_SANDBOX_DEBUG_LOG,
306 sandbox_info->sandbox_debug_log); 300 sandbox_info->sandbox_debug_log);
405 399
406 /* determine the location of all the sandbox support files */ 400 /* determine the location of all the sandbox support files */
407 if (print_debug) 401 if (print_debug)
408 printf("Detection of the support files.\n"); 402 printf("Detection of the support files.\n");
409 403
410 if (-1 == sandbox_setup(argv, &sandbox_info)) { 404 if (-1 == sandbox_setup(&sandbox_info)) {
411 perror(">>> setup"); 405 perror(">>> setup");
412 exit(1); 406 exit(1);
413 } 407 }
414 408
415 /* verify the existance of required files */ 409 /* verify the existance of required files */

Legend:
Removed from v.140  
changed lines
  Added in v.141

  ViewVC Help
Powered by ViewVC 1.1.20