mirror of
https://github.com/postgres/postgres.git
synced 2026-10-31 05:54:36 +03: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:
@@ -76,6 +76,12 @@ char *Log_filename = NULL;
|
|||||||
bool Log_truncate_on_rotation = false;
|
bool Log_truncate_on_rotation = false;
|
||||||
int Log_file_mode = S_IRUSR | S_IWUSR;
|
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
|
* Private state
|
||||||
*/
|
*/
|
||||||
@@ -175,6 +181,17 @@ SysLoggerMain(const void *startup_data, size_t startup_data_len)
|
|||||||
pg_time_t now;
|
pg_time_t now;
|
||||||
WaitEventSet *wes;
|
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().
|
* 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);
|
syslogFile = syslogger_fdopen(slsdata->syslogFile);
|
||||||
csvlogFile = syslogger_fdopen(slsdata->csvlogFile);
|
csvlogFile = syslogger_fdopen(slsdata->csvlogFile);
|
||||||
jsonlogFile = syslogger_fdopen(slsdata->jsonlogFile);
|
jsonlogFile = syslogger_fdopen(slsdata->jsonlogFile);
|
||||||
|
|
||||||
|
syslogger_setup_done = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Assert(startup_data_len == 0);
|
Assert(startup_data_len == 0);
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ write_csvlog(ErrorData *edata)
|
|||||||
appendStringInfoChar(&buf, '\n');
|
appendStringInfoChar(&buf, '\n');
|
||||||
|
|
||||||
/* If in the syslogger process, try to write messages direct to file */
|
/* 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);
|
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
|
||||||
else
|
else
|
||||||
write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_CSVLOG);
|
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
|
* pipe). If this is not possible, fallback to an entry written to
|
||||||
* stderr.
|
* stderr.
|
||||||
*/
|
*/
|
||||||
if (redirection_done || MyBackendType == B_LOGGER)
|
if (redirection_done || syslogger_setup_done)
|
||||||
write_csvlog(edata);
|
write_csvlog(edata);
|
||||||
else
|
else
|
||||||
fallback_to_stderr = true;
|
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
|
* pipe). If this is not possible, fallback to an entry written to
|
||||||
* stderr.
|
* stderr.
|
||||||
*/
|
*/
|
||||||
if (redirection_done || MyBackendType == B_LOGGER)
|
if (redirection_done || syslogger_setup_done)
|
||||||
{
|
{
|
||||||
write_jsonlog(edata);
|
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 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);
|
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);
|
||||||
|
|
||||||
/* No more need of the message formatted for stderr */
|
/* No more need of the message formatted for stderr */
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ write_jsonlog(ErrorData *edata)
|
|||||||
appendStringInfoChar(&buf, '\n');
|
appendStringInfoChar(&buf, '\n');
|
||||||
|
|
||||||
/* If in the syslogger process, try to write messages direct to file */
|
/* 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);
|
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_JSONLOG);
|
||||||
else
|
else
|
||||||
write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_JSONLOG);
|
write_pipe_chunks(buf.data, buf.len, LOG_DESTINATION_JSONLOG);
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ extern PGDLLIMPORT int syslogPipe[2];
|
|||||||
extern PGDLLIMPORT HANDLE syslogPipe[2];
|
extern PGDLLIMPORT HANDLE syslogPipe[2];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool syslogger_setup_done;
|
||||||
|
|
||||||
extern int SysLogger_Start(int child_slot);
|
extern int SysLogger_Start(int child_slot);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user