Commit
0c8e082fba8d 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
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
*/
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().
*
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);
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);
* 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;
* 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);
}
}
/* 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 */
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);
extern PGDLLIMPORT HANDLE syslogPipe[2];
#endif
+extern bool syslogger_setup_done;
extern int SysLogger_Start(int child_slot);