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.
This commit is contained in:
parent
6b87144323
commit
aa0c797c90
@ -87,6 +87,7 @@ extern bool redirection_done;
|
|||||||
*/
|
*/
|
||||||
static pg_time_t next_rotation_time;
|
static pg_time_t next_rotation_time;
|
||||||
static bool pipe_eof_seen = false;
|
static bool pipe_eof_seen = false;
|
||||||
|
static bool rotation_disabled = false;
|
||||||
static FILE *syslogFile = NULL;
|
static FILE *syslogFile = NULL;
|
||||||
static FILE *csvlogFile = NULL;
|
static FILE *csvlogFile = NULL;
|
||||||
static char *last_file_name = NULL;
|
static char *last_file_name = NULL;
|
||||||
@ -315,6 +316,11 @@ SysLoggerMain(int argc, char *argv[])
|
|||||||
pfree(currentLogDir);
|
pfree(currentLogDir);
|
||||||
currentLogDir = pstrdup(Log_directory);
|
currentLogDir = pstrdup(Log_directory);
|
||||||
rotation_requested = true;
|
rotation_requested = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Also, create new directory if not present; ignore errors
|
||||||
|
*/
|
||||||
|
mkdir(Log_directory, S_IRWXU);
|
||||||
}
|
}
|
||||||
if (strcmp(Log_filename, currentLogFilename) != 0)
|
if (strcmp(Log_filename, currentLogFilename) != 0)
|
||||||
{
|
{
|
||||||
@ -332,9 +338,19 @@ SysLoggerMain(int argc, char *argv[])
|
|||||||
currentLogRotationAge = Log_RotationAge;
|
currentLogRotationAge = Log_RotationAge;
|
||||||
set_next_rotation_time();
|
set_next_rotation_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we had a rotation-disabling failure, re-enable rotation
|
||||||
|
* attempts after SIGHUP, and force one immediately.
|
||||||
|
*/
|
||||||
|
if (rotation_disabled)
|
||||||
|
{
|
||||||
|
rotation_disabled = false;
|
||||||
|
rotation_requested = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rotation_requested && Log_RotationAge > 0)
|
if (!rotation_requested && Log_RotationAge > 0 && !rotation_disabled)
|
||||||
{
|
{
|
||||||
/* Do a logfile rotation if it's time */
|
/* Do a logfile rotation if it's time */
|
||||||
pg_time_t now = (pg_time_t) time(NULL);
|
pg_time_t now = (pg_time_t) time(NULL);
|
||||||
@ -343,7 +359,7 @@ SysLoggerMain(int argc, char *argv[])
|
|||||||
rotation_requested = time_based_rotation = true;
|
rotation_requested = time_based_rotation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rotation_requested && Log_RotationSize > 0)
|
if (!rotation_requested && Log_RotationSize > 0 && !rotation_disabled)
|
||||||
{
|
{
|
||||||
/* Do a rotation if file is too big */
|
/* Do a rotation if file is too big */
|
||||||
if (ftell(syslogFile) >= Log_RotationSize * 1024L)
|
if (ftell(syslogFile) >= Log_RotationSize * 1024L)
|
||||||
@ -1106,8 +1122,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
|
|||||||
{
|
{
|
||||||
ereport(LOG,
|
ereport(LOG,
|
||||||
(errmsg("disabling automatic rotation (use SIGHUP to reenable)")));
|
(errmsg("disabling automatic rotation (use SIGHUP to reenable)")));
|
||||||
Log_RotationAge = 0;
|
rotation_disabled = true;
|
||||||
Log_RotationSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
@ -1164,8 +1179,7 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
|
|||||||
{
|
{
|
||||||
ereport(LOG,
|
ereport(LOG,
|
||||||
(errmsg("disabling automatic rotation (use SIGHUP to reenable)")));
|
(errmsg("disabling automatic rotation (use SIGHUP to reenable)")));
|
||||||
Log_RotationAge = 0;
|
rotation_disabled = true;
|
||||||
Log_RotationSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user