diff options
author | Glenn Washburn <development@efficientek.com> | 2019-08-29 21:53:46 -0500 |
---|---|---|
committer | Glenn Washburn <development@efficientek.com> | 2019-08-29 21:53:46 -0500 |
commit | 1b02467adfef544c17d1e1606c0167777100c328 (patch) | |
tree | 4559030625883cddc57d37dde069355eb895731f /src/libtrace | |
parent | Fix issue where strace output file path has leading space making it an invali... (diff) | |
download | firejail-1b02467adfef544c17d1e1606c0167777100c328.tar.gz firejail-1b02467adfef544c17d1e1606c0167777100c328.tar.zst firejail-1b02467adfef544c17d1e1606c0167777100c328.zip |
Allow libtrace preload library to use for trace output a logfile specified by the environment variable FIREJAIL_TRACEFILE or as the RUN_TRACE_FILE if it exists ortherwise use the console as before.
Diffstat (limited to 'src/libtrace')
-rw-r--r-- | src/libtrace/libtrace.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 745dd2260..b3f040e8f 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
33 | #include <syslog.h> | 33 | #include <syslog.h> |
34 | #include <dirent.h> | 34 | #include <dirent.h> |
35 | #include <limits.h> | 35 | #include "../include/rundefs.h" |
36 | 36 | ||
37 | #define tprintf(fp, args...) \ | 37 | #define tprintf(fp, args...) \ |
38 | do { \ | 38 | do { \ |
@@ -46,6 +46,8 @@ typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); | |||
46 | static orig_fopen_t orig_fopen = NULL; | 46 | static orig_fopen_t orig_fopen = NULL; |
47 | typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode); | 47 | typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode); |
48 | static orig_fopen64_t orig_fopen64 = NULL; | 48 | static orig_fopen64_t orig_fopen64 = NULL; |
49 | typedef int (*orig_access_t)(const char *pathname, int mode); | ||
50 | static orig_access_t orig_access = NULL; | ||
49 | 51 | ||
50 | // | 52 | // |
51 | // library constructor/destructor | 53 | // library constructor/destructor |
@@ -65,14 +67,24 @@ void init(void) { | |||
65 | return; | 67 | return; |
66 | 68 | ||
67 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); | 69 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); |
68 | 70 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | |
69 | // tty | 71 | |
72 | // allow environment variable to override defaults | ||
73 | char *logfile = getenv("FIREJAIL_TRACEFILE"); | ||
74 | if (!logfile) { | ||
75 | // if exists, log to trace file | ||
76 | logfile = RUN_TRACE_FILE; | ||
77 | if (orig_access(logfile, F_OK)) | ||
70 | #ifdef PRINTF_DEVTTY | 78 | #ifdef PRINTF_DEVTTY |
71 | ftty = orig_fopen("/dev/tty", "w"); | 79 | // else log to associated tty |
80 | logfile = "/dev/tty"; | ||
72 | #else | 81 | #else |
73 | ftty = stderr; | 82 | logfile = "/proc/self/fd/2"; |
74 | #endif | 83 | #endif |
75 | tprintf(ftty, "=== tracelib init() === \n"); | 84 | } |
85 | |||
86 | // logfile | ||
87 | ftty = orig_fopen(logfile, "a"); | ||
76 | 88 | ||
77 | // pid | 89 | // pid |
78 | mypid = getpid(); | 90 | mypid = getpid(); |
@@ -92,6 +104,7 @@ void init(void) { | |||
92 | if (ptr) | 104 | if (ptr) |
93 | *ptr = '\0'; | 105 | *ptr = '\0'; |
94 | 106 | ||
107 | tprintf(ftty, "=== tracelib init() [%d:%s] === \n", mypid, myname); | ||
95 | fclose(fp); | 108 | fclose(fp); |
96 | free(fname); | 109 | free(fname); |
97 | } | 110 | } |
@@ -483,8 +496,6 @@ DIR *opendir(const char *pathname) { | |||
483 | } | 496 | } |
484 | 497 | ||
485 | // access | 498 | // access |
486 | typedef int (*orig_access_t)(const char *pathname, int mode); | ||
487 | static orig_access_t orig_access = NULL; | ||
488 | int access(const char *pathname, int mode) { | 499 | int access(const char *pathname, int mode) { |
489 | if (!orig_access) | 500 | if (!orig_access) |
490 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | 501 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); |