Skip to content

Commit 313a7d2

Browse files
committed
Add a wait loop when attempting to reopen auth.log after log rotation.
1 parent 500371b commit 313a7d2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2015-01-17 Pierre Schweitzer <pierre@reactos.org>
2+
3+
* ForbidHosts.cpp: Add a wait loop when attempting to reopen auth.log after log rotation.
4+
15
2015-01-20 Pierre Schweitzer <pierre@reactos.org>
26

37
* ForbidHosts.cpp: Don't use LOG_ERR for syslog, it is set to be ignored

ForbidHosts.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#define MailCommandTpl "/usr/bin/mailx -s '%s - ForbidHosts Report' root"
5353
#define CrashMailTpl "/usr/bin/mailx -s '%s - ForbidHosts Crash' root"
5454

55+
const unsigned int MaxWaitRotate = 3600;
5556
const unsigned int MaxAttempts = 5;
5657
const time_t HostExpire = 5;
5758
const unsigned int FailurePenalty = 1;
@@ -649,7 +650,17 @@ int main(int argc, char ** argv) {
649650
// Close file and restart
650651
soft_assert(close(AuthLog) == 0);
651652

652-
AuthLog = open(AuthLogFile, O_RDONLY | O_NONBLOCK);
653+
// We will wait a bit to allow rotation
654+
for (unsigned int Attempts = 0; Attempts < MaxWaitRotate; ++Attempts) {
655+
AuthLog = open(AuthLogFile, O_RDONLY | O_NONBLOCK);
656+
if (AuthLog != -1) {
657+
break;
658+
}
659+
660+
sleep(1);
661+
}
662+
663+
// Check the wait loop was a success
653664
if (AuthLog < 0) {
654665
AuthLog = 0;
655666
syslog(LOG_CRIT, "Failed to reopen auth.log. Quitting.");

0 commit comments

Comments
 (0)