From 94744ef96f4f6ab16e5637ee8f9775f8fe6aaf15 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 9 Mar 2016 18:28:46 -0800 Subject: [PATCH] Account for the possibility of stderr not being open when we start. --- adsbus/log.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adsbus/log.c b/adsbus/log.c index aa1554e..b3bfbf5 100644 --- a/adsbus/log.c +++ b/adsbus/log.c @@ -35,8 +35,10 @@ static void log_open() { } int fd = open(log_path, O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY | O_CLOEXEC, S_IRUSR | S_IWUSR); assert(fd >= 0); - assert(dup3(fd, STDERR_FILENO, O_CLOEXEC) == STDERR_FILENO); - assert(!close(fd)); + if (fd != STDERR_FILENO) { + assert(dup3(fd, STDERR_FILENO, O_CLOEXEC) == STDERR_FILENO); + assert(!close(fd)); + } } static void log_rotate() {