diff options
author | 2019-09-15 07:00:09 -0500 | |
---|---|---|
committer | 2019-09-15 07:00:09 -0500 | |
commit | 38ace01bf5a501f8cd3de5c1384297c3163f9c35 (patch) | |
tree | aab0f8277a0ae1de922b8a9268b01428e8febd73 /src/libtrace/libtrace.c | |
parent | Fix #2899 (diff) | |
parent | Merge branch 'master' into fix-profile-builder (diff) | |
download | firejail-38ace01bf5a501f8cd3de5c1384297c3163f9c35.tar.gz firejail-38ace01bf5a501f8cd3de5c1384297c3163f9c35.tar.zst firejail-38ace01bf5a501f8cd3de5c1384297c3163f9c35.zip |
Merge pull request #2935 from crass/fix-profile-builder
Fix profile builder
Diffstat (limited to 'src/libtrace/libtrace.c')
-rw-r--r-- | src/libtrace/libtrace.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 11e98d95e..0c21b9b70 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 |
@@ -62,10 +64,20 @@ void init(void) { | |||
62 | return; | 64 | return; |
63 | 65 | ||
64 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); | 66 | orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); |
65 | 67 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | |
66 | // tty | 68 | |
67 | ftty = orig_fopen("/dev/tty", "w"); | 69 | // allow environment variable to override defaults |
68 | tprintf(ftty, "=== tracelib init() === \n"); | 70 | char *logfile = getenv("FIREJAIL_TRACEFILE"); |
71 | if (!logfile) { | ||
72 | // if exists, log to trace file | ||
73 | logfile = RUN_TRACE_FILE; | ||
74 | if (orig_access(logfile, F_OK)) | ||
75 | // else log to associated tty | ||
76 | logfile = "/dev/tty"; | ||
77 | } | ||
78 | |||
79 | // logfile | ||
80 | ftty = orig_fopen(logfile, "a"); | ||
69 | 81 | ||
70 | // pid | 82 | // pid |
71 | mypid = getpid(); | 83 | mypid = getpid(); |
@@ -85,6 +97,7 @@ void init(void) { | |||
85 | if (ptr) | 97 | if (ptr) |
86 | *ptr = '\0'; | 98 | *ptr = '\0'; |
87 | 99 | ||
100 | tprintf(ftty, "=== tracelib init() [%d:%s] === \n", mypid, myname); | ||
88 | fclose(fp); | 101 | fclose(fp); |
89 | free(fname); | 102 | free(fname); |
90 | } | 103 | } |
@@ -476,8 +489,6 @@ DIR *opendir(const char *pathname) { | |||
476 | } | 489 | } |
477 | 490 | ||
478 | // access | 491 | // access |
479 | typedef int (*orig_access_t)(const char *pathname, int mode); | ||
480 | static orig_access_t orig_access = NULL; | ||
481 | int access(const char *pathname, int mode) { | 492 | int access(const char *pathname, int mode) { |
482 | if (!orig_access) | 493 | if (!orig_access) |
483 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); | 494 | orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); |