diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index cccec743b0d28922964acd5b597ed74548588856..bb36633ee52e645838353dc020c874881bec90eb 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -24,6 +24,7 @@ #include "postgres.h" #include <fcntl.h> +#include <limits.h> #include <signal.h> #include <time.h> #include <unistd.h> @@ -416,11 +417,23 @@ SysLoggerMain(int argc, char *argv[]) * above is still close enough. Note we can't make this calculation * until after calling logfile_rotate(), since it will advance * next_rotation_time. + * + * Also note that we need to beware of overflow in calculation of the + * timeout: with large settings of Log_RotationAge, next_rotation_time + * could be more than INT_MAX msec in the future. In that case we'll + * wait no more than INT_MAX msec, and try again. */ if (Log_RotationAge > 0 && !rotation_disabled) { - if (now < next_rotation_time) - cur_timeout = (next_rotation_time - now) * 1000L; /* msec */ + pg_time_t delay; + + delay = next_rotation_time - now; + if (delay > 0) + { + if (delay > INT_MAX / 1000) + delay = INT_MAX / 1000; + cur_timeout = delay * 1000L; /* msec */ + } else cur_timeout = 0; cur_flags = WL_TIMEOUT; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 745e7be68e493b4a7ff623733e14ebfdfa6ce213..54461c830fe7306057e5fa8ecea88e1d4e53c901 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2147,7 +2147,7 @@ static struct config_int ConfigureNamesInt[] = GUC_UNIT_MIN }, &Log_RotationAge, - HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, + HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / SECS_PER_MINUTE, NULL, NULL, NULL },