sighandler: use non-existing backtrace filenames ($TMPDIR/i3-backtrace.%pid.%idx.txt)

This commit is contained in:
Michael Stapelberg 2012-09-11 13:07:20 +02:00
parent e713283605
commit 0db93d9072
1 changed files with 9 additions and 2 deletions

View File

@ -52,7 +52,15 @@ static int backtrace(void) {
pid_t pid_parent = getpid(); pid_t pid_parent = getpid();
char *filename = NULL; 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 dont 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(); pid_t pid_gdb = fork();
if (pid_gdb < 0) { if (pid_gdb < 0) {
@ -101,7 +109,6 @@ static int backtrace(void) {
exit(1); exit(1);
} }
int status = 0; int status = 0;
struct stat bt;
waitpid(pid_gdb, &status, 0); waitpid(pid_gdb, &status, 0);