From 0db93d9072de081c28d08dbbd9075e9fa2264c63 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 11 Sep 2012 13:07:20 +0200 Subject: [PATCH] sighandler: use non-existing backtrace filenames ($TMPDIR/i3-backtrace.%pid.%idx.txt) --- src/sighandler.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sighandler.c b/src/sighandler.c index c951ea9d..988927f0 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -52,7 +52,15 @@ static int backtrace(void) { pid_t pid_parent = getpid(); char *filename = NULL; - sasprintf(&filename, "%s/i3-backtrace.%d.txt", tmpdir, pid_parent); + int suffix = 0; + struct stat bt; + /* Find a unique filename for the backtrace (since the PID of i3 stays the + * same), so that we don’t overwrite earlier backtraces. */ + do { + FREE(filename); + sasprintf(&filename, "%s/i3-backtrace.%d.%d.txt", tmpdir, pid_parent, suffix); + suffix++; + } while (stat(filename, &bt) == 0); pid_t pid_gdb = fork(); if (pid_gdb < 0) { @@ -101,7 +109,6 @@ static int backtrace(void) { exit(1); } int status = 0; - struct stat bt; waitpid(pid_gdb, &status, 0);