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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 324 - (show annotations) (download) (as text)
Tue Jul 11 16:27:38 2006 UTC (12 years, 2 months ago) by azarah
File MIME type: text/x-csrc
File size: 19176 byte(s)
Check log size before we open it.

1 /*
2 ** Path sandbox for the gentoo linux portage package system, initially
3 ** based on the ROCK Linux Wrapper for getting a list of created files
4 **
5 ** to integrate with bash, bash should have been built like this
6 **
7 ** ./configure --prefix=<prefix> --host=<host> --without-gnu-malloc
8 **
9 ** it's very important that the --enable-static-link option is NOT specified
10 **
11 ** Copyright (C) 2001 Geert Bevin, Uwyn, http://www.uwyn.com
12 ** Distributed under the terms of the GNU General Public License, v2 or later
13 ** Author : Geert Bevin <gbevin@uwyn.com>
14 ** $Header$
15 */
16
17 /* #define _GNU_SOURCE */
18
19 #include <errno.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <limits.h>
24 #include <string.h>
25 #include <sys/wait.h>
26 #include <signal.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "sbutil.h"
31
32 struct sandbox_info_t {
33 char sandbox_log[SB_PATH_MAX];
34 char sandbox_debug_log[SB_PATH_MAX];
35 char sandbox_lib[SB_PATH_MAX];
36 char sandbox_rc[SB_PATH_MAX];
37 char work_dir[SB_PATH_MAX];
38 char var_tmp_dir[SB_PATH_MAX];
39 char tmp_dir[SB_PATH_MAX];
40 char *home_dir;
41 } sandbox_info_t;
42
43 static int print_debug = 0;
44
45 volatile static int stop_called = 0;
46 volatile static pid_t child_pid = 0;
47
48 static char log_domain[] = "sandbox";
49
50 extern char **environ;
51
52 int sandbox_setup(struct sandbox_info_t *sandbox_info, bool interactive)
53 {
54 if (NULL != getenv(ENV_PORTAGE_TMPDIR)) {
55 /* Portage handle setting SANDBOX_WRITE itself. */
56 sandbox_info->work_dir[0] = '\0';
57 } else {
58 if (NULL == getcwd(sandbox_info->work_dir, SB_PATH_MAX)) {
59 perror("sandbox: Failed to get current directory");
60 return -1;
61 }
62 if (interactive)
63 setenv(ENV_SANDBOX_WORKDIR, sandbox_info->work_dir, 1);
64 }
65
66 /* Do not resolve symlinks, etc .. libsandbox will handle that. */
67 if (!rc_is_dir(VAR_TMPDIR, TRUE)) {
68 perror("sandbox: Failed to get var_tmp_dir");
69 return -1;
70 }
71 snprintf(sandbox_info->var_tmp_dir, SB_PATH_MAX, "%s", VAR_TMPDIR);
72
73 if (-1 == get_tmp_dir(sandbox_info->tmp_dir)) {
74 perror("sandbox: Failed to get tmp_dir");
75 return -1;
76 }
77 setenv(ENV_TMPDIR, sandbox_info->tmp_dir, 1);
78
79 sandbox_info->home_dir = getenv("HOME");
80 if (!sandbox_info->home_dir) {
81 sandbox_info->home_dir = sandbox_info->tmp_dir;
82 setenv("HOME", sandbox_info->home_dir, 1);
83 }
84
85 /* Generate sandbox lib path */
86 get_sandbox_lib(sandbox_info->sandbox_lib);
87
88 /* Generate sandbox bashrc path */
89 get_sandbox_rc(sandbox_info->sandbox_rc);
90
91 /* Generate sandbox log full path */
92 get_sandbox_log(sandbox_info->sandbox_log);
93 if (rc_file_exists(sandbox_info->sandbox_log)) {
94 if (-1 == unlink(sandbox_info->sandbox_log)) {
95 perror("sandbox: Could not unlink old log file");
96 return -1;
97 }
98 }
99
100 /* Generate sandbox debug log full path */
101 get_sandbox_debug_log(sandbox_info->sandbox_debug_log);
102 if (rc_file_exists(sandbox_info->sandbox_debug_log)) {
103 if (-1 == unlink(sandbox_info->sandbox_debug_log)) {
104 perror("sandbox: Could not unlink old debug log file");
105 return -1;
106 }
107 }
108
109 return 0;
110 }
111
112 int print_sandbox_log(char *sandbox_log)
113 {
114 int sandbox_log_file = -1;
115 char *beep_count_env = NULL;
116 int i, color, beep_count = 0;
117 off_t len = 0;
118 char *buffer = NULL;
119
120 if (!rc_is_file(sandbox_log, FALSE)) {
121 perror("sandbox: Log file is not a regular file");
122 return 0;
123 }
124
125 len = rc_get_size(sandbox_log, TRUE);
126 if (0 == len)
127 return 0;
128
129 sandbox_log_file = sb_open(sandbox_log, O_RDONLY, 0);
130 if (-1 == sandbox_log_file) {
131 perror("sandbox: Could not open Log file");
132 return 0;
133 }
134
135 buffer = (char *)xmalloc((len + 1) * sizeof(char));
136 if (NULL == buffer) {
137 perror("sandbox: Could not allocate buffer for Log file");
138 return 0;
139 }
140 memset(buffer, 0, len + 1);
141 if (-1 == sb_read(sandbox_log_file, buffer, len)) {
142 perror("sandbox: Could read Log file");
143 return 0;
144 }
145 sb_close(sandbox_log_file);
146
147 color = ((is_env_on(ENV_NOCOLOR)) ? 0 : 1);
148
149 SB_EERROR(color,
150 "--------------------------- ACCESS VIOLATION SUMMARY ---------------------------",
151 "\n");
152 SB_EERROR(color, "LOG FILE = \"%s\"", "\n\n", sandbox_log);
153 fprintf(stderr, "%s", buffer);
154 free(buffer);
155 SB_EERROR(color,
156 "--------------------------------------------------------------------------------",
157 "\n");
158
159 beep_count_env = getenv(ENV_SANDBOX_BEEP);
160 if (beep_count_env)
161 beep_count = atoi(beep_count_env);
162 else
163 beep_count = DEFAULT_BEEP_COUNT;
164
165 for (i = 0; i < beep_count; i++) {
166 fputc('\a', stderr);
167 if (i < beep_count - 1)
168 sleep(1);
169 }
170
171 return 1;
172 }
173
174 void stop(int signum)
175 {
176 if (0 == stop_called) {
177 stop_called = 1;
178 printf("sandbox: Caught signal %d in pid %d\n",
179 signum, getpid());
180 } else {
181 fprintf(stderr,
182 "sandbox: Signal already caught and busy still cleaning up!\n");
183 }
184 }
185
186 void usr1_handler(int signum, siginfo_t *siginfo, void *ucontext)
187 {
188 if (0 == stop_called) {
189 stop_called = 1;
190 printf("sandbox: Caught signal %d in pid %d\n",
191 signum, getpid());
192
193 /* FIXME: This is really bad form, as we should kill the whole process
194 * tree, but currently that is too much work and not worth the
195 * effort. Thus we only kill the calling process and our child
196 * for now.
197 */
198 if (siginfo->si_pid > 0)
199 kill(siginfo->si_pid, SIGKILL);
200 kill(child_pid, SIGKILL);
201 } else {
202 fprintf(stderr,
203 "sandbox: Signal already caught and busy still cleaning up!\n");
204 }
205 }
206
207 char *sandbox_subst_env_vars(dyn_buf_t *env_data)
208 {
209 dyn_buf_t *new_data = NULL;
210 char *tmp_ptr, *tmp_data = NULL;
211 char *var_start, *var_stop;
212
213 new_data = new_dyn_buf();
214 if (NULL == new_data)
215 return NULL;
216
217 tmp_data = read_line_dyn_buf(env_data);
218 if (NULL == tmp_data)
219 goto error;
220 tmp_ptr = tmp_data;
221
222 while (NULL != (var_start = strchr(tmp_ptr, '$'))) {
223 char *env = NULL;
224
225 var_stop = strchr(var_start, '}');
226
227 /* We only support ${} style env var names, so just skip any
228 * '$' that do not follow this syntax */
229 if (('{' != var_start[1]) || (NULL == var_stop)) {
230 tmp_ptr = var_start + 1;
231 continue;
232 }
233
234 /* Terminate part before env string so that we can copy it */
235 var_start[0] = '\0';
236 /* Move var_start past '${' */
237 var_start += 2;
238 /* Terminate the name of the env var */
239 var_stop[0] = '\0';
240
241 if (strlen(var_start) > 0)
242 env = getenv(var_start);
243 if (-1 == sprintf_dyn_buf(new_data, "%s%s",
244 tmp_ptr ? tmp_ptr : "",
245 env ? env : ""))
246 goto error;
247
248 /* Move tmp_ptr past the '}' of the env var */
249 tmp_ptr = var_stop + 1;
250 }
251
252 if (0 != strlen(tmp_ptr))
253 if (-1 == write_dyn_buf(new_data, tmp_ptr, strlen(tmp_ptr)))
254 goto error;
255
256 free(tmp_data);
257
258 tmp_data = read_line_dyn_buf(new_data);
259 if (NULL == tmp_data)
260 goto error;
261
262 free_dyn_buf(new_data);
263
264 return tmp_data;
265
266 error:
267 if (NULL != new_data)
268 free_dyn_buf(new_data);
269 if (NULL != tmp_data)
270 free(tmp_data);
271
272 return NULL;
273 }
274
275 void sandbox_set_env_var(const char *env_var)
276 {
277 char *config;
278
279 /* We check if the variable is set in the environment, and if not, we
280 * get it from sandbox.conf, and if they exist, we just add them to the
281 * environment if not already present. */
282 config = rc_get_cnf_entry(SANDBOX_CONF_FILE, env_var, NULL);
283 if (NULL != config) {
284 setenv(ENV_SANDBOX_VERBOSE, config, 0);
285 free(config);
286 }
287 }
288
289 int sandbox_set_env_access_var(const char *access_var)
290 {
291 dyn_buf_t *env_data = NULL;
292 int count = 0;
293 char *config = NULL;
294 char **confd_files = NULL;
295 bool use_confd = TRUE;
296
297 env_data = new_dyn_buf();
298 if (NULL == env_data)
299 return -1;
300
301 /* Now get the defaults for the access variable from sandbox.conf.
302 * These do not get overridden via the environment. */
303 config = rc_get_cnf_entry(SANDBOX_CONF_FILE, access_var, ":");
304 if (NULL != config) {
305 if (-1 == write_dyn_buf(env_data, config, strlen(config)))
306 goto error;
307 free(config);
308 config = NULL;
309 }
310 /* Append whatever might be already set. If anything is set, we do
311 * not process the sandbox.d/ files for this variable. */
312 if (NULL != getenv(access_var)) {
313 use_confd = FALSE;
314 if (-1 == sprintf_dyn_buf(env_data, env_data->wr_index ? ":%s" : "%s",
315 getenv(access_var)))
316 goto error;
317 }
318
319 if (!use_confd)
320 goto done;
321
322 /* Now scan the files in sandbox.d/ if the access variable was not
323 * alreay set. */
324 confd_files = rc_ls_dir(SANDBOX_CONFD_DIR, FALSE, TRUE);
325 if (NULL != confd_files) {
326 while (NULL != confd_files[count]) {
327 config = rc_get_cnf_entry(confd_files[count], access_var, ":");
328 if (NULL != config) {
329 if (-1 == sprintf_dyn_buf(env_data,
330 env_data->wr_index ? ":%s" : "%s",
331 config))
332 goto error;
333 free(config);
334 config = NULL;
335 }
336 count++;
337 }
338
339 str_list_free(confd_files);
340 }
341
342 done:
343 if (env_data->wr_index > 0) {
344 char *subst;
345
346 subst = sandbox_subst_env_vars(env_data);
347 if (NULL == subst)
348 goto error;
349
350 setenv(access_var, subst, 1);
351 free(subst);
352 }
353
354 free_dyn_buf(env_data);
355
356 return 0;
357
358 error:
359 if (NULL != env_data)
360 free_dyn_buf(env_data);
361 if (NULL != config)
362 free(config);
363 if (NULL != confd_files)
364 str_list_free(confd_files);
365
366 return -1;
367 }
368
369 int sandbox_setup_env_config(struct sandbox_info_t *sandbox_info)
370 {
371 sandbox_set_env_var(ENV_SANDBOX_VERBOSE);
372 sandbox_set_env_var(ENV_SANDBOX_DEBUG);
373 sandbox_set_env_var(ENV_SANDBOX_BEEP);
374 sandbox_set_env_var(ENV_NOCOLOR);
375
376 if (-1 == sandbox_set_env_access_var(ENV_SANDBOX_DENY))
377 return -1;
378 if (NULL == getenv(ENV_SANDBOX_DENY))
379 setenv(ENV_SANDBOX_DENY, LD_PRELOAD_FILE, 1);
380
381 if (-1 == sandbox_set_env_access_var(ENV_SANDBOX_READ))
382 return -1;
383 if (NULL == getenv(ENV_SANDBOX_READ))
384 setenv(ENV_SANDBOX_READ, "/", 1);
385
386 if (-1 == sandbox_set_env_access_var(ENV_SANDBOX_WRITE))
387 return -1;
388 if ((NULL == getenv(ENV_SANDBOX_WRITE)) &&
389 (NULL != sandbox_info->work_dir))
390 setenv(ENV_SANDBOX_WRITE, sandbox_info->work_dir, 1);
391
392 if (-1 == sandbox_set_env_access_var(ENV_SANDBOX_PREDICT))
393 return -1;
394 if ((NULL == getenv(ENV_SANDBOX_PREDICT)) &&
395 (NULL != sandbox_info->home_dir))
396 setenv(ENV_SANDBOX_PREDICT, sandbox_info->home_dir, 1);
397
398 return 0;
399 }
400
401 int sandbox_setenv(char ***envp, const char *name, const char *val) {
402 char *tmp_string = NULL;
403
404 /* strlen(name) + strlen(val) + '=' + '\0' */
405 tmp_string = xmalloc((strlen(name) + strlen(val) + 2) * sizeof(char));
406 if (NULL == tmp_string)
407 goto error;
408
409 snprintf(tmp_string, strlen(name) + strlen(val) + 2,
410 "%s=%s", name, val);
411
412 str_list_add_item((*envp), tmp_string, error);
413
414 return 0;
415
416 error:
417 perror("sandbox: Out of memory (sandbox_setenv)");
418 exit(EXIT_FAILURE);
419 }
420
421 /* We setup the environment child side only to prevent issues with
422 * setting LD_PRELOAD parent side */
423 char **sandbox_setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
424 {
425 int have_ld_preload = 0;
426
427 char **new_environ = NULL;
428 char **env_ptr;
429 char *ld_preload_envvar = NULL;
430 char *orig_ld_preload_envvar = NULL;
431 char sb_pid[64];
432
433 if (-1 == sandbox_setup_env_config(sandbox_info))
434 return NULL;
435
436 /* Unset these, as its easier than replacing when setting up our
437 * new environment below */
438 unsetenv(ENV_SANDBOX_ON);
439 unsetenv(ENV_SANDBOX_PID);
440 unsetenv(ENV_SANDBOX_LIB);
441 unsetenv(ENV_SANDBOX_BASHRC);
442 unsetenv(ENV_SANDBOX_LOG);
443 unsetenv(ENV_SANDBOX_DEBUG_LOG);
444 unsetenv(ENV_SANDBOX_WORKDIR);
445 unsetenv(ENV_SANDBOX_ACTIVE);
446 unsetenv(ENV_SANDBOX_INTRACTV);
447 unsetenv(ENV_BASH_ENV);
448
449 if (NULL != getenv(ENV_LD_PRELOAD)) {
450 have_ld_preload = 1;
451 orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD);
452
453 ld_preload_envvar = xcalloc(strlen(orig_ld_preload_envvar) +
454 strlen(sandbox_info->sandbox_lib) + 2,
455 sizeof(char));
456 if (NULL == ld_preload_envvar)
457 return NULL;
458 snprintf(ld_preload_envvar, strlen(orig_ld_preload_envvar) +
459 strlen(sandbox_info->sandbox_lib) + 2, "%s %s",
460 sandbox_info->sandbox_lib, orig_ld_preload_envvar);
461 } else {
462 ld_preload_envvar = rc_strndup(sandbox_info->sandbox_lib,
463 strlen(sandbox_info->sandbox_lib));
464 if (NULL == ld_preload_envvar)
465 return NULL;
466 }
467 /* Do not unset this, as strange things might happen */
468 /* unsetenv(ENV_LD_PRELOAD); */
469
470 snprintf(sb_pid, sizeof(sb_pid), "%i", getpid());
471
472 /* First add our new variables to the beginning - this is due to some
473 * weirdness that I cannot remember */
474 sandbox_setenv(&new_environ, ENV_SANDBOX_ON, "1");
475 sandbox_setenv(&new_environ, ENV_SANDBOX_PID, sb_pid);
476 sandbox_setenv(&new_environ, ENV_SANDBOX_LIB, sandbox_info->sandbox_lib);
477 sandbox_setenv(&new_environ, ENV_SANDBOX_BASHRC, sandbox_info->sandbox_rc);
478 sandbox_setenv(&new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log);
479 sandbox_setenv(&new_environ, ENV_SANDBOX_DEBUG_LOG,
480 sandbox_info->sandbox_debug_log);
481 /* Is this an interactive session? */
482 if (interactive)
483 sandbox_setenv(&new_environ, ENV_SANDBOX_INTRACTV, "1");
484 /* Just set the these if not already set so that is_env_on() work */
485 if (!getenv(ENV_SANDBOX_VERBOSE))
486 sandbox_setenv(&new_environ, ENV_SANDBOX_VERBOSE, "1");
487 if (!getenv(ENV_SANDBOX_DEBUG))
488 sandbox_setenv(&new_environ, ENV_SANDBOX_DEBUG, "0");
489 if (!getenv(ENV_NOCOLOR))
490 sandbox_setenv(&new_environ, ENV_NOCOLOR, "no");
491 /* If LD_PRELOAD was not set, set it here, else do it below */
492 if (1 != have_ld_preload)
493 sandbox_setenv(&new_environ, ENV_LD_PRELOAD, ld_preload_envvar);
494
495 /* Make sure our bashrc gets preference */
496 sandbox_setenv(&new_environ, ENV_BASH_ENV, sandbox_info->sandbox_rc);
497
498 /* This one should NEVER be set in ebuilds, as it is the one
499 * private thing libsandbox.so use to test if the sandbox
500 * should be active for this pid, or not.
501 *
502 * azarah (3 Aug 2002)
503 */
504
505 sandbox_setenv(&new_environ, ENV_SANDBOX_ACTIVE, SANDBOX_ACTIVE);
506
507 /* Now add the rest */
508 env_ptr = environ;
509 while (NULL != *env_ptr) {
510 if ((1 == have_ld_preload) &&
511 (strstr(*env_ptr, LD_PRELOAD_EQ) == *env_ptr))
512 /* If LD_PRELOAD was set, and this is it in the original
513 * environment, replace it with our new copy */
514 /* XXX: The following works as it just add whatever as
515 * the last variable to nev_environ */
516 sandbox_setenv(&new_environ, ENV_LD_PRELOAD,
517 ld_preload_envvar);
518 else
519 str_list_add_item_copy(new_environ, (*env_ptr), error);
520
521 env_ptr++;
522 }
523
524 if (NULL != ld_preload_envvar)
525 free(ld_preload_envvar);
526
527 return new_environ;
528
529 error:
530 if (NULL != new_environ)
531 str_list_free(new_environ);
532 if (NULL != ld_preload_envvar)
533 free(ld_preload_envvar);
534
535 return NULL;
536 }
537
538 int spawn_shell(char *argv_bash[], char **env, int debug)
539 {
540 int status = 0;
541 int ret = 0;
542
543 child_pid = fork();
544
545 /* Child's process */
546 if (0 == child_pid) {
547 execve(argv_bash[0], argv_bash, env);
548 _exit(EXIT_FAILURE);
549 } else if (child_pid < 0) {
550 if (debug)
551 fprintf(stderr, "Process failed to spawn!\n");
552 return 0;
553 }
554
555 /* fork() creates a copy of this, so no need to use more memory than
556 * absolutely needed. */
557 str_list_free(argv_bash);
558 str_list_free(env);
559
560 ret = waitpid(child_pid, &status, 0);
561 if ((-1 == ret) || (status > 0)) {
562 if (debug)
563 fprintf(stderr, "Process returned with failed exit status!\n");
564 return 0;
565 }
566
567 return 1;
568 }
569
570 int main(int argc, char **argv)
571 {
572 struct sigaction act_new;
573
574 int success = 1;
575 int sandbox_log_presence = 0;
576
577 struct sandbox_info_t sandbox_info;
578
579 char **sandbox_environ;
580 char **argv_bash = NULL;
581
582 char *run_str = "-c";
583
584 rc_log_domain(log_domain);
585
586 /* Only print info if called with no arguments .... */
587 if (argc < 2)
588 print_debug = 1;
589
590 if (print_debug)
591 printf("========================== Gentoo linux path sandbox ===========================\n");
592
593 /* check if a sandbox is already running */
594 if (NULL != getenv(ENV_SANDBOX_ACTIVE)) {
595 fprintf(stderr, "Not launching a new sandbox instance\n");
596 fprintf(stderr, "Another one is already running in this process hierarchy.\n");
597 exit(EXIT_FAILURE);
598 }
599
600 /* determine the location of all the sandbox support files */
601 if (print_debug)
602 printf("Detection of the support files.\n");
603
604 if (-1 == sandbox_setup(&sandbox_info, print_debug)) {
605 fprintf(stderr, "sandbox: Failed to setup sandbox.");
606 exit(EXIT_FAILURE);
607 }
608
609 /* verify the existance of required files */
610 if (print_debug)
611 printf("Verification of the required files.\n");
612
613 #ifndef SB_HAVE_MULTILIB
614 if (!rc_file_exists(sandbox_info.sandbox_lib)) {
615 perror("sandbox: Could not open the sandbox library");
616 exit(EXIT_FAILURE);
617 }
618 #endif
619 if (!rc_file_exists(sandbox_info.sandbox_rc)) {
620 perror("sandbox: Could not open the sandbox rc file");
621 exit(EXIT_FAILURE);
622 }
623
624 /* set up the required environment variables */
625 if (print_debug)
626 printf("Setting up the required environment variables.\n");
627
628 /* If not in portage, cd into it work directory */
629 if ('\0' != sandbox_info.work_dir[0])
630 chdir(sandbox_info.work_dir);
631
632 /* Setup bash argv */
633 str_list_add_item_copy(argv_bash, "/bin/bash", oom_error);
634 str_list_add_item_copy(argv_bash, "-rcfile", oom_error);
635 str_list_add_item_copy(argv_bash, sandbox_info.sandbox_rc, oom_error);
636 if (argc >= 2) {
637 int i;
638
639 str_list_add_item_copy(argv_bash, run_str, oom_error);
640 str_list_add_item_copy(argv_bash, argv[1], oom_error);
641 for (i = 2; i < argc; i++) {
642 char *tmp_ptr;
643
644 tmp_ptr = xrealloc(argv_bash[4],
645 (strlen(argv_bash[4]) +
646 strlen(argv[i]) + 2) *
647 sizeof(char));
648 if (NULL == tmp_ptr)
649 goto oom_error;
650
651 snprintf(argv_bash[4] + strlen(argv_bash[4]),
652 strlen(argv[i]) + 2, " %s",
653 argv[i]);
654 }
655 }
656
657 /* Setup the child environment stuff.
658 * XXX: We free this in spawn_shell(). */
659 sandbox_environ = sandbox_setup_environ(&sandbox_info, print_debug);
660 if (NULL == sandbox_environ)
661 goto oom_error;
662
663 /* set up the required signal handlers */
664 signal(SIGHUP, &stop);
665 signal(SIGINT, &stop);
666 signal(SIGQUIT, &stop);
667 signal(SIGTERM, &stop);
668 act_new.sa_sigaction = usr1_handler;
669 sigemptyset (&act_new.sa_mask);
670 act_new.sa_flags = SA_SIGINFO | SA_RESTART;
671 sigaction (SIGUSR1, &act_new, NULL);
672
673 /* STARTING PROTECTED ENVIRONMENT */
674 if (print_debug) {
675 printf("The protected environment has been started.\n");
676 printf("--------------------------------------------------------------------------------\n");
677 }
678
679 if (print_debug)
680 printf("Process being started in forked instance.\n");
681
682 /* Start Bash */
683 if (!spawn_shell(argv_bash, sandbox_environ, print_debug))
684 success = 0;
685
686 /* As spawn_shell() free both argv_bash and sandbox_environ, make sure
687 * we do not run into issues in future if we need a OOM error below
688 * this ... */
689 argv_bash = NULL;
690 sandbox_environ = NULL;
691
692 if (print_debug)
693 printf("Cleaning up sandbox process\n");
694
695 if (print_debug) {
696 printf("========================== Gentoo linux path sandbox ===========================\n");
697 printf("The protected environment has been shut down.\n");
698 }
699
700 if (rc_file_exists(sandbox_info.sandbox_log)) {
701 sandbox_log_presence = 1;
702 print_sandbox_log(sandbox_info.sandbox_log);
703 } else if (print_debug) {
704 printf("--------------------------------------------------------------------------------\n");
705 }
706
707 if ((sandbox_log_presence) || (!success))
708 return 1;
709 else
710 return 0;
711
712 oom_error:
713 if (NULL != argv_bash)
714 str_list_free(argv_bash);
715
716 perror("sandbox: Out of memory (environ)");
717 exit(EXIT_FAILURE);
718 }
719
720 // vim:noexpandtab noai:cindent ai

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20