/[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 133 Revision 139
62 62
63 if (NULL == realpath(VAR_TMPDIR, sandbox_info->var_tmp_dir)) { 63 if (NULL == realpath(VAR_TMPDIR, sandbox_info->var_tmp_dir)) {
64 perror(">>> get var_tmp_dir"); 64 perror(">>> get var_tmp_dir");
65 return -1; 65 return -1;
66 } 66 }
67 67
68 if (-1 == get_tmp_dir(sandbox_info->tmp_dir)) { 68 if (-1 == get_tmp_dir(sandbox_info->tmp_dir)) {
69 perror(">>> get tmp_dir"); 69 perror(">>> get tmp_dir");
70 return -1; 70 return -1;
71 } 71 }
72 tmp_dir = sandbox_info->tmp_dir; 72 tmp_dir = sandbox_info->tmp_dir;
90 snprintf(sandbox_info->sandbox_rc, SB_PATH_MAX, "%s", 90 snprintf(sandbox_info->sandbox_rc, SB_PATH_MAX, "%s",
91 get_sandbox_rc(sandbox_info->sandbox_dir)); 91 get_sandbox_rc(sandbox_info->sandbox_dir));
92 92
93 /* Generate sandbox log full path */ 93 /* Generate sandbox log full path */
94 snprintf(sandbox_info->sandbox_log, SB_PATH_MAX, "%s", 94 snprintf(sandbox_info->sandbox_log, SB_PATH_MAX, "%s",
95 get_sandbox_log(tmp_dir)); 95 get_sandbox_log());
96 96
97 /* Generate sandbox debug log full path */ 97 /* Generate sandbox debug log full path */
98 snprintf(sandbox_info->sandbox_debug_log, SB_PATH_MAX, "%s", 98 snprintf(sandbox_info->sandbox_debug_log, SB_PATH_MAX, "%s",
99 get_sandbox_debug_log(tmp_dir)); 99 get_sandbox_debug_log());
100 100
101 return 0; 101 return 0;
102} 102}
103 103
104int print_sandbox_log(char *sandbox_log) 104int print_sandbox_log(char *sandbox_log)
107 char *beep_count_env = NULL; 107 char *beep_count_env = NULL;
108 int i, color, beep_count = 0; 108 int i, color, beep_count = 0;
109 long len = 0; 109 long len = 0;
110 char *buffer = NULL; 110 char *buffer = NULL;
111 111
112 sandbox_log_file = file_open(sandbox_log, "r", 1, 0664, "portage"); 112 if (1 != is_file(sandbox_log)) {
113 if (-1 == sandbox_log_file) 113 perror(">>> log file not a regular file");
114 return 0; 114 return 0;
115 }
116
117 sandbox_log_file = open(sandbox_log, O_RDONLY);
118 if (-1 == sandbox_log_file) {
119 perror(">>> could not open log file");
120 return 0;
121 }
115 122
116 len = file_length(sandbox_log_file); 123 len = file_length(sandbox_log_file);
117 buffer = (char *)malloc((len + 1) * sizeof(char)); 124 buffer = (char *)malloc((len + 1) * sizeof(char));
118 memset(buffer, 0, len + 1); 125 memset(buffer, 0, len + 1);
119 read(sandbox_log_file, buffer, len); 126 read(sandbox_log_file, buffer, len);
120 file_close(sandbox_log_file); 127 close(sandbox_log_file);
121 128
122 color = ((getenv("NOCOLOR") != NULL) ? 0 : 1); 129 color = ((getenv("NOCOLOR") != NULL) ? 0 : 1);
123 130
124 if (color) 131 if (color)
125 printf("\e[31;01m"); 132 printf("\e[31;01m");
147 for (i = 0; i < beep_count; i++) { 154 for (i = 0; i < beep_count; i++) {
148 fputc('\a', stderr); 155 fputc('\a', stderr);
149 if (i < beep_count - 1) 156 if (i < beep_count - 1)
150 sleep(1); 157 sleep(1);
151 } 158 }
159
152 return 1; 160 return 1;
153} 161}
154 162
155void stop(int signum) 163void stop(int signum)
156{ 164{
412 /* verify the existance of required files */ 420 /* verify the existance of required files */
413 if (print_debug) 421 if (print_debug)
414 printf("Verification of the required files.\n"); 422 printf("Verification of the required files.\n");
415 423
416#ifndef SB_HAVE_64BIT_ARCH 424#ifndef SB_HAVE_64BIT_ARCH
417 if (file_exist(sandbox_info.sandbox_lib, 0) <= 0) { 425 if (0 >= exists(sandbox_info.sandbox_lib)) {
418 fprintf(stderr, "Could not open the sandbox library at '%s'.\n", 426 fprintf(stderr, "Could not open the sandbox library at '%s'.\n",
419 sandbox_info.sandbox_lib); 427 sandbox_info.sandbox_lib);
420 return -1; 428 return -1;
421 } 429 }
422#endif 430#endif
423 if (file_exist(sandbox_info.sandbox_rc, 0) <= 0) { 431 if (0 >= exists(sandbox_info.sandbox_rc)) {
424 fprintf(stderr, "Could not open the sandbox rc file at '%s'.\n", 432 fprintf(stderr, "Could not open the sandbox rc file at '%s'.\n",
425 sandbox_info.sandbox_rc); 433 sandbox_info.sandbox_rc);
426 return -1; 434 return -1;
427 } 435 }
428 436
517 if (print_debug) { 525 if (print_debug) {
518 printf("========================== Gentoo linux path sandbox ===========================\n"); 526 printf("========================== Gentoo linux path sandbox ===========================\n");
519 printf("The protected environment has been shut down.\n"); 527 printf("The protected environment has been shut down.\n");
520 } 528 }
521 529
522 if (file_exist(sandbox_info.sandbox_log, 0)) { 530 if (1 == exists(sandbox_info.sandbox_log)) {
523 sandbox_log_presence = 1; 531 sandbox_log_presence = 1;
524 print_sandbox_log(sandbox_info.sandbox_log); 532 print_sandbox_log(sandbox_info.sandbox_log);
525 } else if (print_debug) { 533 } else if (print_debug) {
526 printf("--------------------------------------------------------------------------------\n"); 534 printf("--------------------------------------------------------------------------------\n");
527 } 535 }

Legend:
Removed from v.133  
changed lines
  Added in v.139

  ViewVC Help
Powered by ViewVC 1.1.20