summaryrefslogtreecommitdiffstats
path: root/src/util/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/debug.c')
-rw-r--r--src/util/debug.c30
1 files changed, 28 insertions, 2 deletions
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();