aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtrace
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtrace')
-rw-r--r--src/libtrace/libtrace.c25
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);
46static orig_fopen_t orig_fopen = NULL; 46static orig_fopen_t orig_fopen = NULL;
47typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode); 47typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode);
48static orig_fopen64_t orig_fopen64 = NULL; 48static orig_fopen64_t orig_fopen64 = NULL;
49typedef int (*orig_access_t)(const char *pathname, int mode);
50static 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
479typedef int (*orig_access_t)(const char *pathname, int mode);
480static orig_access_t orig_access = NULL;
481int access(const char *pathname, int mode) { 492int 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");