diff options
author | Ralph Boehme <slow@samba.org> | 2020-11-23 16:04:03 +0100 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2020-12-09 10:44:15 +0000 |
commit | 6c881025bfa45927076e1b995bf948f0434417ae (patch) | |
tree | a198e85e42219e6bf98d28a73b23550fd8496ef3 | |
parent | 5cd1e3c5a4aade5d589ad7df613766e0cb38f342 (diff) | |
download | samba-6c881025bfa45927076e1b995bf948f0434417ae.tar.gz |
debug: detect logrotation by checking inode number
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14248
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 3651a51e93b45104323d5db1d5ea704d4f71acf1)
-rw-r--r-- | lib/util/debug.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/util/debug.c b/lib/util/debug.c index 6764578096a..692e97e3390 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -113,6 +113,8 @@ struct debug_class { */ char *logfile; int fd; + /* inode number of the logfile to detect logfile rotation */ + ino_t ino; }; static const char *default_classname_table[] = { @@ -1086,7 +1088,9 @@ static bool reopen_one_log(struct debug_class *config) { int old_fd = config->fd; const char *logfile = config->logfile; + struct stat st; int new_fd; + int ret; if (logfile == NULL) { debug_close_fd(old_fd); @@ -1107,6 +1111,16 @@ static bool reopen_one_log(struct debug_class *config) smb_set_close_on_exec(new_fd); config->fd = new_fd; + ret = fstat(new_fd, &st); + if (ret != 0) { + log_overflow = true; + DBG_ERR("Unable to fstat() new log file '%s': %s\n", + logfile, strerror(errno)); + log_overflow = false; + return false; + } + + config->ino = st.st_ino; return true; } @@ -1254,17 +1268,26 @@ static void do_one_check_log_size(off_t maxlog, struct debug_class *config) char name[strlen(config->logfile) + 5]; struct stat st; int ret; + bool reopen = false; bool ok; if (maxlog == 0) { return; } - ret = fstat(config->fd, &st); + ret = stat(config->logfile, &st); if (ret != 0) { return; } - if (st.st_size < maxlog ) { + if (st.st_size >= maxlog ) { + reopen = true; + } + + if (st.st_ino != config->ino) { + reopen = true; + } + + if (!reopen) { return; } @@ -1276,8 +1299,12 @@ static void do_one_check_log_size(off_t maxlog, struct debug_class *config) } ret = fstat(config->fd, &st); if (ret != 0) { + config->ino = (ino_t)0; return; } + + config->ino = st.st_ino; + if (st.st_size < maxlog) { return; } |