Lines 124-129
static const char *sb_get_fd_dir(void)
Link Here
|
124 |
#endif |
124 |
#endif |
125 |
} |
125 |
} |
126 |
|
126 |
|
|
|
127 |
#if !HAVE_LIBKVM |
127 |
static const char *sb_get_cmdline(pid_t pid) |
128 |
static const char *sb_get_cmdline(pid_t pid) |
128 |
{ |
129 |
{ |
129 |
#if !defined(SANDBOX_PROC_1_CMDLINE) && !defined(SANDBOX_PROC_SELF_CMDLINE) && !defined(SANDBOX_PROC_dd_CMDLINE) |
130 |
#if !defined(SANDBOX_PROC_1_CMDLINE) && !defined(SANDBOX_PROC_SELF_CMDLINE) && !defined(SANDBOX_PROC_dd_CMDLINE) |
Lines 135-140
static const char *sb_get_cmdline(pid_t pid)
Link Here
|
135 |
sprintf(path, "/proc/%i/cmdline", pid); |
136 |
sprintf(path, "/proc/%i/cmdline", pid); |
136 |
return path; |
137 |
return path; |
137 |
} |
138 |
} |
|
|
139 |
#else /* !HAVE_LIBKVM */ |
140 |
static char **sb_get_kvm_cmdline(pid_t pid) |
141 |
{ |
142 |
int cnt = 0; |
143 |
char** ret; |
144 |
kvm_t * kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); |
145 |
struct kinfo_proc * proc = kvm_getprocs(kt, KERN_PROC_PID | KERN_PROC_ALL, ( pid ? pid : getpid() ), &cnt); |
146 |
ret = ( cnt > 0 ? kvm_getargv(kt, proc, 0) : NULL); |
147 |
kvm_close(kt); |
148 |
return ret; |
149 |
} |
150 |
#endif /* !HAVE_LIBKVM */ |
138 |
|
151 |
|
139 |
int canonicalize(const char *path, char *resolved_path) |
152 |
int canonicalize(const char *path, char *resolved_path) |
140 |
{ |
153 |
{ |
Lines 358-363
char *egetcwd(char *buf, size_t size)
Link Here
|
358 |
return tmpbuf; |
371 |
return tmpbuf; |
359 |
} |
372 |
} |
360 |
|
373 |
|
|
|
374 |
#if !HAVE_LIBKVM |
361 |
static int sb_copy_file_to_fd(const char *file, int ofd) |
375 |
static int sb_copy_file_to_fd(const char *file, int ofd) |
362 |
{ |
376 |
{ |
363 |
int ret = -1; |
377 |
int ret = -1; |
Lines 388-393
static int sb_copy_file_to_fd(const char *file, int ofd)
Link Here
|
388 |
free(buf); |
402 |
free(buf); |
389 |
return ret; |
403 |
return ret; |
390 |
} |
404 |
} |
|
|
405 |
#endif /* !HAVE_LIBKVM */ |
391 |
|
406 |
|
392 |
void sb_dump_backtrace(void) |
407 |
void sb_dump_backtrace(void) |
393 |
{ |
408 |
{ |
Lines 397-406
void sb_dump_backtrace(void)
Link Here
|
397 |
num_funcs = backtrace(funcs, ARRAY_SIZE(funcs)); |
412 |
num_funcs = backtrace(funcs, ARRAY_SIZE(funcs)); |
398 |
backtrace_symbols_fd(funcs, num_funcs, STDERR_FILENO); |
413 |
backtrace_symbols_fd(funcs, num_funcs, STDERR_FILENO); |
399 |
#endif |
414 |
#endif |
|
|
415 |
#if !HAVE_LIBKVM |
400 |
const char *cmdline = sb_get_cmdline(trace_pid); |
416 |
const char *cmdline = sb_get_cmdline(trace_pid); |
401 |
sb_printf("%s: ", cmdline); |
417 |
sb_printf("%s: ", cmdline); |
402 |
sb_copy_file_to_fd(cmdline, STDERR_FILENO); |
418 |
sb_copy_file_to_fd(cmdline, STDERR_FILENO); |
403 |
sb_printf("\n\n"); |
419 |
sb_printf("\n\n"); |
|
|
420 |
#else /* !HAVE_LIBKVM */ |
421 |
char **cmdline = sb_get_kvm_cmdline(trace_pid); |
422 |
if(cmdline) { |
423 |
int i; |
424 |
for(i=0;cmdline[i];i++) sb_printf("%s ", cmdline[i]); |
425 |
sb_printf("\n\n"); |
426 |
} |
427 |
else |
428 |
sb_printf("libkvm: unable to get cmdline\n\n"); |
429 |
#endif /* !HAVE_LIBKVM */ |
404 |
} |
430 |
} |
405 |
|
431 |
|
406 |
__attribute__((noreturn)) |
432 |
__attribute__((noreturn)) |
Lines 492-502
static bool write_logfile(const char *logfile, const char *func, const char *pat
Link Here
|
492 |
_SB_WRITE_STR(rpath); |
518 |
_SB_WRITE_STR(rpath); |
493 |
|
519 |
|
494 |
_SB_WRITE_STR("\nC: "); |
520 |
_SB_WRITE_STR("\nC: "); |
|
|
521 |
#if !HAVE_LIBKVM |
495 |
const char *cmdline = sb_get_cmdline(trace_pid); |
522 |
const char *cmdline = sb_get_cmdline(trace_pid); |
496 |
if (sb_copy_file_to_fd(cmdline, logfd)) { |
523 |
if (sb_copy_file_to_fd(cmdline, logfd)) { |
497 |
_SB_WRITE_STR("unable to read "); |
524 |
_SB_WRITE_STR("unable to read "); |
498 |
_SB_WRITE_STR(cmdline); |
525 |
_SB_WRITE_STR(cmdline); |
499 |
} |
526 |
} |
|
|
527 |
#else /* !HAVE_LIBKVM */ |
528 |
char **cmdline = sb_get_kvm_cmdline(trace_pid); |
529 |
if(cmdline) { |
530 |
int i; |
531 |
for(i=0;cmdline[i];i++){ |
532 |
_SB_WRITE_STR(cmdline[i]); |
533 |
_SB_WRITE_STR(" "); |
534 |
} |
535 |
} |
536 |
else |
537 |
_SB_WRITE_STR("unable to get cmdline from libkvm"); |
538 |
#endif /* !HAVE_LIBKVM */ |
500 |
_SB_WRITE_STR("\n"); |
539 |
_SB_WRITE_STR("\n"); |
501 |
|
540 |
|
502 |
return true; |
541 |
return true; |