/[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 98 Revision 99
31#include <sys/wait.h> 31#include <sys/wait.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <fcntl.h> 33#include <fcntl.h>
34#include "sandbox.h" 34#include "sandbox.h"
35 35
36static char tmp_dir[SB_PATH_MAX];
37
36int cleaned_up = 0; 38static int cleaned_up = 0;
37int print_debug = 0; 39static int print_debug = 0;
38int stop_called = 0; 40static int stop_called = 0;
39 41
40/* Read pids file, and load active pids into an array. Return number of pids in array */ 42/* Read pids file, and load active pids into an array. Return number of pids in array */
41int load_active_pids(int fd, int **pids) 43int load_active_pids(int fd, int **pids)
42{ 44{
43 char *data = NULL; 45 char *data = NULL;
100 int *pids_array = NULL; 102 int *pids_array = NULL;
101 char pid_string[SB_BUF_LEN]; 103 char pid_string[SB_BUF_LEN];
102 char *sandbox_pids_file; 104 char *sandbox_pids_file;
103 105
104 /* Generate sandbox pids-file path */ 106 /* Generate sandbox pids-file path */
105 sandbox_pids_file = get_sandbox_pids_file(); 107 sandbox_pids_file = get_sandbox_pids_file(tmp_dir);
106 108
107 /* Remove this sandbox's bash pid from the global pids 109 /* Remove this sandbox's bash pid from the global pids
108 * file if we have not already done so */ 110 * file if we have not already done so */
109 if (0 == cleaned_up) { 111 if (0 == cleaned_up) {
110 cleaned_up = 1; 112 cleaned_up = 1;
426 char sandbox_lib[SB_PATH_MAX]; 428 char sandbox_lib[SB_PATH_MAX];
427 char sandbox_rc[SB_PATH_MAX]; 429 char sandbox_rc[SB_PATH_MAX];
428 char *sandbox_pids_file; 430 char *sandbox_pids_file;
429 char portage_tmp_dir[SB_PATH_MAX]; 431 char portage_tmp_dir[SB_PATH_MAX];
430 char var_tmp_dir[SB_PATH_MAX]; 432 char var_tmp_dir[SB_PATH_MAX];
431 char tmp_dir[SB_PATH_MAX];
432 char sandbox_write_envvar[SB_BUF_LEN]; 433 char sandbox_write_envvar[SB_BUF_LEN];
433 char sandbox_predict_envvar[SB_BUF_LEN]; 434 char sandbox_predict_envvar[SB_BUF_LEN];
434 char pid_string[SB_BUF_LEN]; 435 char pid_string[SB_BUF_LEN];
435 char **argv_bash = NULL; 436 char **argv_bash = NULL;
436 437
454 455
455 /* determine the location of all the sandbox support files */ 456 /* determine the location of all the sandbox support files */
456 if (print_debug) 457 if (print_debug)
457 printf("Detection of the support files.\n"); 458 printf("Detection of the support files.\n");
458 459
460 if (NULL == realpath(getenv(ENV_PORTAGE_TMPDIR) ? getenv(ENV_PORTAGE_TMPDIR)
461 : PORTAGE_TMPDIR,
462 portage_tmp_dir)) {
463 perror(">>> get portage_tmp_dir");
464 exit(1);
465 }
466 if (NULL == realpath(VAR_TMPDIR, var_tmp_dir)) {
467 perror(">>> get var_tmp_dir");
468 exit(1);
469 }
470 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
471 : TMPDIR,
472 tmp_dir)) {
473 perror(">>> get tmp_dir");
474 exit(1);
475 }
476
459 /* Generate base sandbox path */ 477 /* Generate base sandbox path */
460 snprintf(sandbox_dir, SB_PATH_MAX, "%s/", 478 snprintf(sandbox_dir, SB_PATH_MAX, "%s/",
461 get_sandbox_path(argv[0])); 479 get_sandbox_path(argv[0]));
462 480
463 /* Generate sandbox lib path */ 481 /* Generate sandbox lib path */
464 snprintf(sandbox_lib, SB_PATH_MAX, "%s", 482 snprintf(sandbox_lib, SB_PATH_MAX, "%s",
465 get_sandbox_lib(sandbox_dir)); 483 get_sandbox_lib(sandbox_dir));
466 484
467 /* Generate sandbox pids-file path */ 485 /* Generate sandbox pids-file path */
468 sandbox_pids_file = get_sandbox_pids_file(); 486 sandbox_pids_file = get_sandbox_pids_file(tmp_dir);
469 487
470 /* Generate sandbox bashrc path */ 488 /* Generate sandbox bashrc path */
471 snprintf(sandbox_rc, SB_PATH_MAX, "%s", 489 snprintf(sandbox_rc, SB_PATH_MAX, "%s",
472 get_sandbox_rc(sandbox_dir)); 490 get_sandbox_rc(sandbox_dir));
473 491
488 506
489 /* set up the required environment variables */ 507 /* set up the required environment variables */
490 if (print_debug) 508 if (print_debug)
491 printf("Setting up the required environment variables.\n"); 509 printf("Setting up the required environment variables.\n");
492 510
493 /* Generate sandbox log full path */
494 snprintf(sandbox_log, SB_PATH_MAX, "%s",
495 get_sandbox_log());
496
497 /* Generate sandbox debug log full path */
498 snprintf(sandbox_debug_log, SB_PATH_MAX, "%s",
499 get_sandbox_debug_log());
500
501 home_dir = getenv("HOME"); 511 home_dir = getenv("HOME");
502 if (!home_dir) { 512 if (!home_dir) {
503 home_dir = "/tmp"; 513 home_dir = "/tmp";
504 setenv("HOME", home_dir, 1); 514 setenv("HOME", home_dir, 1);
505 } 515 }
506 516
507 if (NULL == realpath(getenv("PORTAGE_TMPDIR") ? getenv("PORTAGE_TMPDIR") 517 /* Generate sandbox log full path */
508 : "/var/tmp/portage", 518 snprintf(sandbox_log, SB_PATH_MAX, "%s",
509 portage_tmp_dir)) { 519 get_sandbox_log(tmp_dir));
510 perror(">>> get portage_tmp_dir"); 520
511 exit(1); 521 /* Generate sandbox debug log full path */
512 } 522 snprintf(sandbox_debug_log, SB_PATH_MAX, "%s",
513 if (NULL == realpath("/var/tmp", var_tmp_dir)) { 523 get_sandbox_debug_log(tmp_dir));
514 perror(">>> get var_tmp_dir");
515 exit(1);
516 }
517 if (NULL == realpath("/tmp", tmp_dir)) {
518 perror(">>> get tmp_dir");
519 exit(1);
520 }
521 524
522 /* This one should not be child only, as we check above to see 525 /* This one should not be child only, as we check above to see
523 * if we are already running (check sandbox_setup_environ). 526 * if we are already running (check sandbox_setup_environ).
524 * This needs to be set before calling sandbox_setup_environ(), 527 * This needs to be set before calling sandbox_setup_environ(),
525 * else its not set for the child */ 528 * else its not set for the child */

Legend:
Removed from v.98  
changed lines
  Added in v.99

  ViewVC Help
Powered by ViewVC 1.1.20