Lines 124-129
static const char *sb_get_fd_dir(void)
Link Here
|
124 |
#endif |
124 |
#endif |
125 |
} |
125 |
} |
126 |
|
126 |
|
|
|
127 |
#ifdef HAVE_LIBKVM |
128 |
static const char *sb_get_cmdline(pid_t pid) |
129 |
{ |
130 |
return "libkvm"; /* we will get the command line directly later via libkvm */ |
131 |
} |
132 |
#else /* HAVE_LIBKVM */ |
127 |
static const char *sb_get_cmdline(pid_t pid) |
133 |
static const char *sb_get_cmdline(pid_t pid) |
128 |
{ |
134 |
{ |
129 |
#if !defined(SANDBOX_PROC_1_CMDLINE) && !defined(SANDBOX_PROC_SELF_CMDLINE) && !defined(SANDBOX_PROC_dd_CMDLINE) |
135 |
#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); |
141 |
sprintf(path, "/proc/%i/cmdline", pid); |
136 |
return path; |
142 |
return path; |
137 |
} |
143 |
} |
|
|
144 |
#endif /* HAVE_LIBKVM */ |
138 |
|
145 |
|
139 |
int canonicalize(const char *path, char *resolved_path) |
146 |
int canonicalize(const char *path, char *resolved_path) |
140 |
{ |
147 |
{ |
Lines 358-364
char *egetcwd(char *buf, size_t size)
Link Here
|
358 |
return tmpbuf; |
365 |
return tmpbuf; |
359 |
} |
366 |
} |
360 |
|
367 |
|
361 |
static int sb_copy_file_to_fd(const char *file, int ofd) |
368 |
#ifdef HAVE_LIBKVM |
|
|
369 |
static int sb_copy_file_or_pid_cmdline_to_fd(const char *file, pid_t pid, int ofd) |
370 |
{ |
371 |
int ret = -1; |
372 |
int cnt = 0; |
373 |
char **str; |
374 |
|
375 |
kvm_t *kt = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); |
376 |
if (!kt) |
377 |
return ret; |
378 |
|
379 |
struct kinfo_proc *proc = kvm_getprocs(kt, KERN_PROC_PID | KERN_PROC_ALL, pid ? pid : getpid(), &cnt); |
380 |
if (!proc || !cnt) |
381 |
goto error; |
382 |
|
383 |
str = kvm_getargv(kt, proc, 0); |
384 |
if (!str) |
385 |
goto error; |
386 |
|
387 |
for (cnt = 0; str[cnt]; cnt++) { |
388 |
size_t len = strlen(str[cnt]); |
389 |
if (sb_write(ofd, str[cnt], len) != len) |
390 |
goto error; |
391 |
if (str[cnt+1] && sb_write(ofd, " ", 1) != 1) |
392 |
goto error; |
393 |
} |
394 |
ret = 0; |
395 |
error: |
396 |
kvm_close(kt); |
397 |
return ret; |
398 |
} |
399 |
#else /* HAVE_LIBKVM */ |
400 |
static int sb_copy_file_or_pid_cmdline_to_fd(const char *file, pid_t pid, int ofd) |
362 |
{ |
401 |
{ |
363 |
int ret = -1; |
402 |
int ret = -1; |
364 |
|
403 |
|
Lines 388-393
static int sb_copy_file_to_fd(const char *file, int ofd)
Link Here
|
388 |
free(buf); |
427 |
free(buf); |
389 |
return ret; |
428 |
return ret; |
390 |
} |
429 |
} |
|
|
430 |
#endif /* HAVE_LIBKVM */ |
391 |
|
431 |
|
392 |
void sb_dump_backtrace(void) |
432 |
void sb_dump_backtrace(void) |
393 |
{ |
433 |
{ |
Lines 399-405
void sb_dump_backtrace(void)
Link Here
|
399 |
#endif |
439 |
#endif |
400 |
const char *cmdline = sb_get_cmdline(trace_pid); |
440 |
const char *cmdline = sb_get_cmdline(trace_pid); |
401 |
sb_printf("%s: ", cmdline); |
441 |
sb_printf("%s: ", cmdline); |
402 |
sb_copy_file_to_fd(cmdline, STDERR_FILENO); |
442 |
sb_copy_file_or_pid_cmdline_to_fd(cmdline, trace_pid, STDERR_FILENO); |
403 |
sb_printf("\n\n"); |
443 |
sb_printf("\n\n"); |
404 |
} |
444 |
} |
405 |
|
445 |
|
Lines 493-499
static bool write_logfile(const char *logfile, const char *func, const char *pat
Link Here
|
493 |
|
533 |
|
494 |
_SB_WRITE_STR("\nC: "); |
534 |
_SB_WRITE_STR("\nC: "); |
495 |
const char *cmdline = sb_get_cmdline(trace_pid); |
535 |
const char *cmdline = sb_get_cmdline(trace_pid); |
496 |
if (sb_copy_file_to_fd(cmdline, logfd)) { |
536 |
if (sb_copy_file_or_pid_cmdline_to_fd(cmdline, trace_pid, logfd)) { |
497 |
_SB_WRITE_STR("unable to read "); |
537 |
_SB_WRITE_STR("unable to read "); |
498 |
_SB_WRITE_STR(cmdline); |
538 |
_SB_WRITE_STR(cmdline); |
499 |
} |
539 |
} |