From 999d9250e7efc15f38448c2929bbe6d19dbb8013 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 4 Nov 2010 08:56:50 -0400 Subject: Handle errors during log reopening better --- src/util/debug.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/debug.c b/src/util/debug.c index 30026dc1..1b78ebae 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -159,11 +159,37 @@ int open_debug_file(void) int rotate_debug_files(void) { int ret; + errno_t error; if (!debug_to_file) return EOK; - ret = fclose(debug_file); - if (ret) return ret; + do { + error = 0; + ret = fclose(debug_file); + if (ret != 0) { + error = errno; + } + + /* Check for EINTR, which means we should retry + * because the system call was interrupted by a + * signal + */ + } while (error == EINTR); + + if (error != 0) { + /* Even if we were unable to close the debug log, we need to make + * sure that we open up a new one. Log rotation will remove the + * current file, so all debug messages will be disappearing. + * + * We should write an error to the syslog warning of the resource + * leak and then proceed with opening the new file. + */ + sss_log(SSS_LOG_ALERT, "Could not close debug file [%s]. [%d][%s]\n", + debug_log_file, error, strerror(error)); + sss_log(SSS_LOG_ALERT, "Attempting to open new file anyway. " + "Be aware that this is a resource leak\n"); + } + debug_file = NULL; return open_debug_file(); -- cgit