Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 537b266

Browse files
committed
Fix syslogger's rotation disable/re-enable logic.
If it fails to open a new log file, the syslogger assumes there's something wrong with its parameters (such as log_directory), and stops attempting automatic time-based or size-based log file rotations. Sending it SIGHUP is supposed to start that up again. However, the original coding for that was really bogus, involving clobbering a couple of GUC variables and hoping that SIGHUP processing would restore them. Get rid of that technique in favor of maintaining a separate flag showing we've turned rotation off. Per report from Mark Kirkwood. Also, the syslogger will automatically attempt to create the log_directory directory if it doesn't exist, but that was only happening at startup. For consistency and ease of use, it should do the same whenever the value of log_directory is changed by SIGHUP. Back-patch to all supported branches.
1 parent 3424bff commit 537b266

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/backend/postmaster/syslogger.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extern bool redirection_done;
8888
*/
8989
static pg_time_t next_rotation_time;
9090
static bool pipe_eof_seen = false;
91+
static bool rotation_disabled = false;
9192
static FILE *syslogFile = NULL;
9293
static FILE *csvlogFile = NULL;
9394
static char *last_file_name = NULL;
@@ -318,6 +319,11 @@ SysLoggerMain(int argc, char *argv[])
318319
pfree(currentLogDir);
319320
currentLogDir = pstrdup(Log_directory);
320321
rotation_requested = true;
322+
323+
/*
324+
* Also, create new directory if not present; ignore errors
325+
*/
326+
mkdir(Log_directory, S_IRWXU);
321327
}
322328
if (strcmp(Log_filename, currentLogFilename) != 0)
323329
{
@@ -335,9 +341,19 @@ SysLoggerMain(int argc, char *argv[])
335341
currentLogRotationAge = Log_RotationAge;
336342
set_next_rotation_time();
337343
}
344+
345+
/*
346+
* If we had a rotation-disabling failure, re-enable rotation
347+
* attempts after SIGHUP, and force one immediately.
348+
*/
349+
if (rotation_disabled)
350+
{
351+
rotation_disabled = false;
352+
rotation_requested = true;
353+
}
338354
}
339355

340-
if (!rotation_requested && Log_RotationAge > 0)
356+
if (!rotation_requested && Log_RotationAge > 0 && !rotation_disabled)
341357
{
342358
/* Do a logfile rotation if it's time */
343359
pg_time_t now = (pg_time_t) time(NULL);
@@ -346,7 +362,7 @@ SysLoggerMain(int argc, char *argv[])
346362
rotation_requested = time_based_rotation = true;
347363
}
348364

349-
if (!rotation_requested && Log_RotationSize > 0)
365+
if (!rotation_requested && Log_RotationSize > 0 && !rotation_disabled)
350366
{
351367
/* Do a rotation if file is too big */
352368
if (ftell(syslogFile) >= Log_RotationSize * 1024L)
@@ -1122,8 +1138,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11221138
{
11231139
ereport(LOG,
11241140
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1125-
Log_RotationAge = 0;
1126-
Log_RotationSize = 0;
1141+
rotation_disabled = true;
11271142
}
11281143

11291144
if (filename)
@@ -1167,8 +1182,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11671182
{
11681183
ereport(LOG,
11691184
(errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1170-
Log_RotationAge = 0;
1171-
Log_RotationSize = 0;
1185+
rotation_disabled = true;
11721186
}
11731187

11741188
if (filename)

0 commit comments

Comments
 (0)