From 338cd4835dd163c5f54f63db59e41ea1ebbc900f Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 19 Jun 2013 14:44:40 +0200 Subject: [PATCH] Fix logStackTrace() when logging to stdout. When the semantics changed from logfile = NULL to logfile = "" to log into standard output, no proper change was made to logStackTrace() to make it able to work with the new setup. This commit fixes the issue. --- src/debug.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/debug.c b/src/debug.c index eb08c38d..32d36120 100644 --- a/src/debug.c +++ b/src/debug.c @@ -619,11 +619,12 @@ void logRegisters(ucontext_t *uc) { void logStackTrace(ucontext_t *uc) { void *trace[100]; int trace_size = 0, fd; + int log_to_stdout = server.logfile[0] == '\0'; /* Open the log file in append mode. */ - fd = server.logfile ? - open(server.logfile, O_APPEND|O_CREAT|O_WRONLY, 0644) : - STDOUT_FILENO; + fd = log_to_stdout ? + STDOUT_FILENO : + open(server.logfile, O_APPEND|O_CREAT|O_WRONLY, 0644); if (fd == -1) return; /* Generate the stack trace */ @@ -637,7 +638,7 @@ void logStackTrace(ucontext_t *uc) { backtrace_symbols_fd(trace, trace_size, fd); /* Cleanup */ - if (server.logfile) close(fd); + if (!log_to_stdout) close(fd); } /* Log information about the "current" client, that is, the client that is