summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-11-04 08:56:50 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-11-05 08:13:12 -0400
commit999d9250e7efc15f38448c2929bbe6d19dbb8013 (patch)
tree938ef9de07c68fb9617bfc9c05e653ce5e03aa0d /src
parent38064e75ff70a5d740e02a511217cdbc5584ffd2 (diff)
downloadsssd-999d9250e7efc15f38448c2929bbe6d19dbb8013.tar.gz
sssd-999d9250e7efc15f38448c2929bbe6d19dbb8013.tar.xz
sssd-999d9250e7efc15f38448c2929bbe6d19dbb8013.zip
Handle errors during log reopening better
Diffstat (limited to 'src')
-rw-r--r--src/monitor/monitor_sbus.c3
-rw-r--r--src/util/debug.c30
2 files changed, 30 insertions, 3 deletions
diff --git a/src/monitor/monitor_sbus.c b/src/monitor/monitor_sbus.c
index 034cd46d2..c2106e862 100644
--- a/src/monitor/monitor_sbus.c
+++ b/src/monitor/monitor_sbus.c
@@ -184,7 +184,8 @@ int monitor_common_rotate_logs(DBusMessage *message,
ret = rotate_debug_files();
if (ret) {
- sss_log(SSS_LOG_ALERT, "Could not rotate debug files!\n");
+ sss_log(SSS_LOG_ALERT, "Could not rotate debug files! [%d][%s]\n",
+ ret, strerror(ret));
return ret;
}
diff --git a/src/util/debug.c b/src/util/debug.c
index 30026dc11..1b78ebaef 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();