diff options
author | smitsohu <smitsohu@gmail.com> | 2019-10-04 19:12:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-04 19:12:46 +0000 |
commit | 34e5ad65b238b698c55e4921c9ac9294e6548cc7 (patch) | |
tree | 317d9400f53a8281408381aa36c47169ba204f4b /src/libtrace | |
parent | break out of libtrace file open loop (diff) | |
download | firejail-34e5ad65b238b698c55e4921c9ac9294e6548cc7.tar.gz firejail-34e5ad65b238b698c55e4921c9ac9294e6548cc7.tar.zst firejail-34e5ad65b238b698c55e4921c9ac9294e6548cc7.zip |
fix concurrent writing to trace file
Diffstat (limited to 'src/libtrace')
-rw-r--r-- | src/libtrace/libtrace.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libtrace/libtrace.c b/src/libtrace/libtrace.c index 3798cb998..9a944d0f6 100644 --- a/src/libtrace/libtrace.c +++ b/src/libtrace/libtrace.c | |||
@@ -55,7 +55,7 @@ static orig_access_t orig_access = NULL; | |||
55 | // Using fprintf to /dev/tty instead of printf in order to fix #561 | 55 | // Using fprintf to /dev/tty instead of printf in order to fix #561 |
56 | static FILE *ftty = NULL; | 56 | static FILE *ftty = NULL; |
57 | static pid_t mypid = 0; | 57 | static pid_t mypid = 0; |
58 | #define MAXNAME 16 | 58 | #define MAXNAME 16 // 8 or larger |
59 | static char myname[MAXNAME] = "unknown"; | 59 | static char myname[MAXNAME] = "unknown"; |
60 | 60 | ||
61 | static void init(void) __attribute__((constructor)); | 61 | static void init(void) __attribute__((constructor)); |
@@ -85,6 +85,8 @@ void init(void) { | |||
85 | } | 85 | } |
86 | sleep(1); | 86 | sleep(1); |
87 | } | 87 | } |
88 | // unbuffered stream | ||
89 | setvbuf(ftty, NULL, _IONBF, 0); | ||
88 | 90 | ||
89 | // pid | 91 | // pid |
90 | mypid = getpid(); | 92 | mypid = getpid(); |
@@ -96,7 +98,7 @@ void init(void) { | |||
96 | free(fname); | 98 | free(fname); |
97 | if (fp) { | 99 | if (fp) { |
98 | if (fgets(myname, MAXNAME, fp) == NULL) | 100 | if (fgets(myname, MAXNAME, fp) == NULL) |
99 | strncpy(myname, "unknown", MAXNAME-1); | 101 | strcpy(myname, "unknown"); |
100 | fclose(fp); | 102 | fclose(fp); |
101 | } | 103 | } |
102 | } | 104 | } |