Skip to content

Commit 89067bc

Browse files
committed
Fix syslogger to not fail when log_rotation_age exceeds 2^31 milliseconds.
We need to avoid calling WaitLatch with timeouts exceeding INT_MAX. Fortunately a simple clamp will do the trick, since no harm is done if the wait times out before it's really time to rotate the log file. Per bug #7670 (probably bug #7545 is the same thing, too). In passing, fix bogus definition of log_rotation_age's maximum value in guc.c --- it was numerically right, but only because MINS_PER_HOUR and SECS_PER_MINUTE have the same value. Back-patch to 9.2. Before that, syslogger wasn't using WaitLatch.
1 parent f0461cd commit 89067bc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/backend/postmaster/syslogger.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "postgres.h"
2525

2626
#include <fcntl.h>
27+
#include <limits.h>
2728
#include <signal.h>
2829
#include <time.h>
2930
#include <unistd.h>
@@ -415,11 +416,23 @@ SysLoggerMain(int argc, char *argv[])
415416
* above is still close enough. Note we can't make this calculation
416417
* until after calling logfile_rotate(), since it will advance
417418
* next_rotation_time.
419+
*
420+
* Also note that we need to beware of overflow in calculation of the
421+
* timeout: with large settings of Log_RotationAge, next_rotation_time
422+
* could be more than INT_MAX msec in the future. In that case we'll
423+
* wait no more than INT_MAX msec, and try again.
418424
*/
419425
if (Log_RotationAge > 0 && !rotation_disabled)
420426
{
421-
if (now < next_rotation_time)
422-
cur_timeout = (next_rotation_time - now) * 1000L; /* msec */
427+
pg_time_t delay;
428+
429+
delay = next_rotation_time - now;
430+
if (delay > 0)
431+
{
432+
if (delay > INT_MAX / 1000)
433+
delay = INT_MAX / 1000;
434+
cur_timeout = delay * 1000L; /* msec */
435+
}
423436
else
424437
cur_timeout = 0;
425438
cur_flags = WL_TIMEOUT;

src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ static struct config_int ConfigureNamesInt[] =
21342134
GUC_UNIT_MIN
21352135
},
21362136
&Log_RotationAge,
2137-
HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR,
2137+
HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE,
21382138
NULL, NULL, NULL
21392139
},
21402140

0 commit comments

Comments
 (0)