summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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 034cd46d..c2106e86 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 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();