From 68cb8aaf0aa7956f7e6e28e380ea6b0333a4a3be Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 14 Oct 2011 11:37:24 -0700 Subject: [PATCH] vlog: Skip reopening a log file if it would have no effect. Avoids redundant "closing log file"/"opened log file" messages in log files. Reported-by: Reid Price Bug #7750. --- lib/vlog.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/vlog.c b/lib/vlog.c index 301473cd..11b2f7cc 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -322,7 +323,25 @@ vlog_set_log_file(const char *file_name) int vlog_reopen_log_file(void) { - return log_file_name ? vlog_set_log_file(log_file_name) : 0; + struct stat old, new; + + /* Skip re-opening if there's nothing to reopen. */ + if (!log_file_name) { + return 0; + } + + /* Skip re-opening if it would be a no-op because the old and new files are + * the same. (This avoids writing "closing log file" followed immediately + * by "opened log file".) */ + if (log_file + && !fstat(fileno(log_file), &old) + && !stat(log_file_name, &new) + && old.st_dev == new.st_dev + && old.st_ino == new.st_ino) { + return 0; + } + + return vlog_set_log_file(log_file_name); } /* Set debugging levels: -- 2.30.2