From 334f32002698e3452c3a7c3b578743f7b8d80213 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 23 Jul 2020 15:54:16 +0200 Subject: [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. --- chattymalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'chattymalloc.c') 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); -- cgit v1.2.3