diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-07-23 15:54:16 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-07-23 15:54:16 +0200 |
| commit | 334f32002698e3452c3a7c3b578743f7b8d80213 (patch) | |
| tree | 5fc219292bb531f0862746807d1ef514c71667aa /chattymalloc.c | |
| parent | 0f69b2f829de48c3aec7cd950ac49177b9cf041b (diff) | |
| download | chattymalloc-334f32002698e3452c3a7c3b578743f7b8d80213.tar.gz chattymalloc-334f32002698e3452c3a7c3b578743f7b8d80213.zip | |
[chattymalloc] add pid to trace file name to support fork/exec
When a process uses frok and exit both will open the same file and
truncated it when they are ready which leads to invalid writes.
Now we prepend the trace file name with the pid of the process
so each child has its own trace file.
Diffstat (limited to 'chattymalloc.c')
| -rw-r--r-- | chattymalloc.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/chattymalloc.c b/chattymalloc.c index fbea7dd..77f818f 100644 --- a/chattymalloc.c +++ b/chattymalloc.c @@ -207,7 +207,12 @@ static void __attribute__((constructor)) init() { initializing = 1; char *fname = getenv("CHATTYMALLOC_FILE"); if (fname == NULL) { - fname = "chattymalloc.trace"; + fname = "chattymalloc-%d.trace"; + } + + if (asprintf(&fname, fname, getpid()) == -1) { + fprintf(stderr, "can't format output file name"); + abort(); } out_fd = open(fname, O_RDWR | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
