mirror of
https://github.com/postgres/postgres.git
synced 2026-06-09 00:32:10 -04:00
Fix syslogger NULL-pointer-dereference in EXEC_BACKEND
Commit 0c8e082fba changed the time at which MyBackendType is assigned,
breaking a careful choreography in syslogger to decide when to write
messages to its own log files. Fix by flipping a boolean at the
(approximate) location where previously MyBackendType was set, instead
of depending on MyBackendType directly.
Author: Álvaro Herrera <alvherre@kurilemu.de>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/ahP-JT4ZRPyobnLb@paquier.xyz
This commit is contained in:
parent
7d13b03a2e
commit
fb23cc7e81
5 changed files with 25 additions and 5 deletions
|
|
@ -76,6 +76,12 @@ char *Log_filename = NULL;
|
|||
bool Log_truncate_on_rotation = false;
|
||||
int Log_file_mode = S_IRUSR | S_IWUSR;
|
||||
|
||||
/*
|
||||
* Indicates to be running in the syslogger process, and that the logging
|
||||
* file descriptor(s) have been set up.
|
||||
*/
|
||||
bool syslogger_setup_done = false;
|
||||
|
||||
/*
|
||||
* Private state
|
||||
*/
|
||||
|
|
@ -175,6 +181,17 @@ SysLoggerMain(const void *startup_data, size_t startup_data_len)
|
|||
pg_time_t now;
|
||||
WaitEventSet *wes;
|
||||
|
||||
#ifndef EXEC_BACKEND
|
||||
|
||||
/*
|
||||
* In !EXEC_BACKEND, syslogger is immediately ready to take over: the
|
||||
* output files were already opened by postmaster before forking. For the
|
||||
* other case we must wait until the file descriptors have been restored,
|
||||
* below.
|
||||
*/
|
||||
syslogger_setup_done = true;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Re-open the error output files that were opened by SysLogger_Start().
|
||||
*
|
||||
|
|
@ -190,6 +207,8 @@ SysLoggerMain(const void *startup_data, size_t startup_data_len)
|
|||
syslogFile = syslogger_fdopen(slsdata->syslogFile);
|
||||
csvlogFile = syslogger_fdopen(slsdata->csvlogFile);
|
||||
jsonlogFile = syslogger_fdopen(slsdata->jsonlogFile);
|
||||
|
||||
syslogger_setup_done = true;
|
||||
}
|
||||
#else
|
||||
Assert(startup_data_len == 0);
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ write_csvlog(ErrorData *edata)
|
|||
appendStringInfoChar(&buf, '\n');
|
||||
|
||||
/* If in the syslogger process, try to write messages direct to file */
|
||||
if (MyBackendType == B_LOGGER)
|
||||
if (syslogger_setup_done)
|
||||
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
|
||||
else
|
||||
write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
|
||||
|
|
|
|||
|
|
@ -3831,7 +3831,7 @@ send_message_to_server_log(ErrorData *edata)
|
|||
* pipe). If this is not possible, fallback to an entry written to
|
||||
* stderr.
|
||||
*/
|
||||
if (redirection_done || MyBackendType == B_LOGGER)
|
||||
if (redirection_done || syslogger_setup_done)
|
||||
write_csvlog(edata);
|
||||
else
|
||||
fallback_to_stderr = true;
|
||||
|
|
@ -3845,7 +3845,7 @@ send_message_to_server_log(ErrorData *edata)
|
|||
* pipe). If this is not possible, fallback to an entry written to
|
||||
* stderr.
|
||||
*/
|
||||
if (redirection_done || MyBackendType == B_LOGGER)
|
||||
if (redirection_done || syslogger_setup_done)
|
||||
{
|
||||
write_jsonlog(edata);
|
||||
}
|
||||
|
|
@ -3885,7 +3885,7 @@ send_message_to_server_log(ErrorData *edata)
|
|||
}
|
||||
|
||||
/* If in the syslogger process, try to write messages direct to file */
|
||||
if (MyBackendType == B_LOGGER)
|
||||
if (syslogger_setup_done)
|
||||
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
|
||||
|
||||
/* No more need of the message formatted for stderr */
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ write_jsonlog(ErrorData *edata)
|
|||
appendStringInfoChar(&buf, '\n');
|
||||
|
||||
/* If in the syslogger process, try to write messages direct to file */
|
||||
if (MyBackendType == B_LOGGER)
|
||||
if (syslogger_setup_done)
|
||||
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_JSONLOG);
|
||||
else
|
||||
write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_JSONLOG);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ extern PGDLLIMPORT int syslogPipe[2];
|
|||
extern PGDLLIMPORT HANDLE syslogPipe[2];
|
||||
#endif
|
||||
|
||||
extern bool syslogger_setup_done;
|
||||
|
||||
extern int SysLogger_Start(int child_slot);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue