1/*-------------------------------------------------------------------------
5 * The system logger (syslogger) appeared in Postgres 8.0. It catches all
6 * stderr output from the postmaster, backends, and other subprocesses
7 * by redirecting to a pipe, and writes it to a set of logfiles.
8 * It's possible to have size and age limits for the logfile configured
9 * in postgresql.conf. If these limits are reached or passed, the
10 * current logfile is closed and a new one is created (rotated).
11 * The logfiles are stored in a subdirectory (configurable in
12 * postgresql.conf), using a user-selectable naming scheme.
14 * Author: Andreas Pflug <pgadmin@pse-consulting.de>
16 * Copyright (c) 2004-2025, PostgreSQL Global Development Group
20 * src/backend/postmaster/syslogger.c
22 *-------------------------------------------------------------------------
56 * We read() into a temp buffer twice as big as a chunk, so that any fragment
57 * left after processing can be moved down to the front and we'll still have
58 * room to read a full chunk.
60 #define READ_BUF_SIZE (2 * PIPE_CHUNK_SIZE)
62/* Log rotation signal file path, relative to $PGDATA */
63 #define LOGROTATE_SIGNAL_FILE "logrotate"
67 * GUC parameters. Logging_collector cannot be changed after postmaster
68 * start, but the rest can change at SIGHUP.
93 * Buffers for saving partial messages from different backends.
95 * Keep NBUFFER_LISTS lists of these, with the entry for a given source pid
96 * being in the list numbered (pid % NBUFFER_LISTS), so as to cut down on
97 * the number of entries we have to examine for any one incoming message.
98 * There must never be more than one entry for the same source pid.
100 * An inactive buffer is not removed from its list, just held for re-use.
101 * An inactive buffer has pid == 0 and undefined contents of data.
109 #define NBUFFER_LISTS 256
112/* These must be exported for EXEC_BACKEND case ... annoying */
120static HANDLE threadHandle = 0;
121static CRITICAL_SECTION sysloggerSection;
125 * Flags set by interrupt handlers for later service in the main loop.
130/* Local subroutines */
132static int syslogger_fdget(FILE *file);
133static FILE *syslogger_fdopen(
int fd);
141static unsigned int __stdcall pipeThread(
void *
arg);
143static void logfile_rotate(
bool time_based_rotation,
int size_rotation_for);
146 int target_dest,
char **last_file_name,
161 * Main entry point for syslogger process
162 * argc/argv parameters are valid only in EXEC_BACKEND case.
169 int bytes_in_logbuffer = 0;
172 char *currentLogFilename;
173 int currentLogRotationAge;
178 * Re-open the error output files that were opened by SysLogger_Start().
180 * We expect this will always succeed, which is too optimistic, but if it
181 * fails there's not a lot we can do to report the problem anyway. As
182 * coded, we'll just crash on a null pointer dereference after failure...
188 Assert(startup_data_len ==
sizeof(*slsdata));
194 Assert(startup_data_len == 0);
198 * Now that we're done reading the startup data, release postmaster's
199 * working memory context.
213 * If we restarted, our stderr is already redirected into our own input
214 * pipe. This is of course pretty useless, not to mention that it
215 * interferes with detecting pipe EOF. Point stderr to /dev/null. This
216 * assumes that all interesting messages generated in the syslogger will
217 * come through elog.c and will be sent to write_syslogger_file.
224 * The closes might look redundant, but they are not: we want to be
225 * darn sure the pipe gets closed even if the open failed. We can
226 * survive running with stderr pointing nowhere, but we can't afford
227 * to have extra pipe input descriptors hanging around.
229 * As we're just trying to reset these to go to DEVNULL, there's not
230 * much point in checking for failure from the close/dup2 calls here,
231 * if they fail then presumably the file descriptors are closed and
232 * any writes will go into the bitbucket anyway.
245 * Syslogger's own stderr can't be the syslogPipe, so set it back to text
246 * mode if we didn't just close it. (It was set to binary in
247 * SubPostmasterMain).
255 * Also close our copy of the write end of the pipe. This is needed to
256 * ensure we can detect pipe EOF correctly. (But note that in the restart
257 * case, the postmaster already did this.)
270 * Properly accept or ignore signals the postmaster might send us
272 * Note: we ignore all termination signals, and instead exit only when all
273 * upstream processes are gone, to ensure we don't miss any dying gasps of
288 * Reset some signals that are accepted by postmaster but not here
295 /* Fire up separate data transfer thread */
296 InitializeCriticalSection(&sysloggerSection);
297 EnterCriticalSection(&sysloggerSection);
299 threadHandle = (HANDLE) _beginthreadex(NULL, 0, pipeThread, NULL, 0, NULL);
300 if (threadHandle == 0)
301 elog(
FATAL,
"could not create syslogger data transfer thread: %m");
305 * Remember active logfiles' name(s). We recompute 'em from the reference
306 * time because passing down just the pg_time_t is a lot cheaper than
307 * passing a whole file path in the EXEC_BACKEND case.
315 /* remember active logfile parameters */
319 /* set next planned rotation time */
324 * Reset whereToSendOutput, as the postmaster will do (but hasn't yet, at
325 * the point where we forked). This prevents duplicate output of messages
326 * from syslogger itself.
331 * Set up a reusable WaitEventSet object we'll use to wait for our latch,
332 * and (except on Windows) our socket.
334 * Unlike all other postmaster child processes, we'll ignore postmaster
335 * death because we want to collect final log output from all backends and
336 * then exit last. We'll do that by running until we see EOF on the
337 * syslog pipe, which implies that all other backends have exited
338 * (including the postmaster).
346 /* main worker loop */
349 bool time_based_rotation =
false;
350 int size_rotation_for = 0;
358 /* Clear any already-pending wakeups */
362 * Process any requests or signals received recently.
370 * Check if the log directory or filename pattern changed in
371 * postgresql.conf. If so, force rotation to make sure we're
372 * writing the logfiles in the right place.
376 pfree(currentLogDir);
381 * Also, create new directory if not present; ignore errors
387 pfree(currentLogFilename);
393 * Force a rotation if CSVLOG output was just turned on or off and
394 * we need to open or close csvlogFile accordingly.
401 * Force a rotation if JSONLOG output was just turned on or off
402 * and we need to open or close jsonlogFile accordingly.
409 * If rotation time parameter changed, reset next rotation time,
410 * but don't immediately force a rotation.
419 * If we had a rotation-disabling failure, re-enable rotation
420 * attempts after SIGHUP, and force one immediately.
429 * Force rewriting last log filename when reloading configuration.
430 * Even if rotation_requested is false, log_destination may have
431 * been changed and we don't want to wait the next file rotation.
438 /* Do a logfile rotation if it's time */
446 /* Do a rotation if file is too big */
469 * Force rotation when both values are zero. It means the request
470 * was sent by pg_rotate_logfile() or "pg_ctl logrotate".
472 if (!time_based_rotation && size_rotation_for == 0)
480 * Calculate time till next time-based rotation, so that we don't
481 * sleep longer than that. We assume the value of "now" obtained
482 * above is still close enough. Note we can't make this calculation
483 * until after calling logfile_rotate(), since it will advance
484 * next_rotation_time.
486 * Also note that we need to beware of overflow in calculation of the
487 * timeout: with large settings of Log_RotationAge, next_rotation_time
488 * could be more than INT_MAX msec in the future. In that case we'll
489 * wait no more than INT_MAX msec, and try again.
498 if (delay > INT_MAX / 1000)
499 delay = INT_MAX / 1000;
500 cur_timeout = delay * 1000L;
/* msec */
509 * Sleep until there's something to do
513 WAIT_EVENT_SYSLOGGER_MAIN);
520 logbuffer + bytes_in_logbuffer,
521 sizeof(logbuffer) - bytes_in_logbuffer);
527 errmsg(
"could not read from logger pipe: %m")));
529 else if (bytesRead > 0)
531 bytes_in_logbuffer += bytesRead;
538 * Zero bytes read when select() is saying read-ready means
539 * EOF on the pipe: that is, there are no longer any processes
540 * with the pipe write end open. Therefore, the postmaster
541 * and all backends are shut down, and we are done.
545 /* if there's any data left then force it out now */
552 * On Windows we leave it to a separate thread to transfer data and
553 * detect pipe EOF. The main thread just wakes up to handle SIGHUP
554 * and rotation conditions.
556 * Server code isn't generally thread-safe, so we ensure that only one
557 * of the threads is active at a time by entering the critical section
558 * whenever we're not sleeping.
560 LeaveCriticalSection(&sysloggerSection);
563 WAIT_EVENT_SYSLOGGER_MAIN);
565 EnterCriticalSection(&sysloggerSection);
571 * seeing this message on the real stderr is annoying - so we make
572 * it DEBUG1 to suppress in normal use.
578 * Normal exit from the syslogger is here. Note that we
579 * deliberately do not close syslogFile before exiting; this is to
580 * allow for the possibility of elog messages being generated
581 * inside proc_exit. Regular exit() will take care of flushing
582 * and closing stdio channels.
590 * Postmaster subroutine to start a syslogger subprocess.
599#endif /* EXEC_BACKEND */
604 * If first time through, create the pipe which will receive stderr
607 * If the syslogger crashes and needs to be restarted, we continue to use
608 * the same pipe (indeed must do so, since extant backends will be writing
611 * This means the postmaster must continue to hold the read end of the
612 * pipe open, so we can pass it down to the reincarnated syslogger. This
613 * is a bit klugy but we have little choice.
615 * Also note that we don't bother counting the pipe FDs by calling
616 * Reserve/ReleaseExternalFD. There's no real need to account for them
617 * accurately in the postmaster or syslogger process, and both ends of the
618 * pipe will wind up closed in all other postmaster children.
626 errmsg(
"could not create pipe for syslog: %m")));
631 SECURITY_ATTRIBUTES
sa;
633 memset(&
sa, 0,
sizeof(SECURITY_ATTRIBUTES));
634 sa.nLength =
sizeof(SECURITY_ATTRIBUTES);
635 sa.bInheritHandle = TRUE;
640 errmsg(
"could not create pipe for syslog: %m")));
645 * Create log directory if not present; ignore errors
650 * The initial logfile is created right in the postmaster, to verify that
651 * the Log_directory is writable. We save the reference time so that the
652 * syslogger child process can recompute this file name.
654 * It might look a bit strange to re-do this during a syslogger restart,
655 * but we must do so since the postmaster closed syslogFile after the
656 * previous fork (and remembering that old file wouldn't be right anyway).
657 * Note we always append here, we won't overwrite any existing file. This
658 * is consistent with the normal rules, because by definition this is not
659 * a time-based rotation.
670 * Likewise for the initial CSV log file, if that's enabled. (Note that
671 * we open syslogFile even when only CSV output is nominally enabled,
672 * since some code paths will write to syslogFile anyway.)
684 * Likewise for the initial JSON log file, if that's enabled. (Note that
685 * we open syslogFile even when only JSON output is nominally enabled,
686 * since some code paths will write to syslogFile anyway.)
702 &startup_data,
sizeof(startup_data), NULL);
706#endif /* EXEC_BACKEND */
708 if (sysloggerPid == -1)
711 (
errmsg(
"could not fork system logger: %m")));
715 /* success, in postmaster */
717 /* now we redirect stderr, if not done already */
725 * Leave a breadcrumb trail when redirecting, in case the user forgets
726 * that redirection is active and looks only at the original stderr
730 (
errmsg(
"redirecting log output to logging collector process"),
731 errhint(
"Future log output will appear in directory \"%s\".",
739 errmsg(
"could not redirect stdout: %m")));
744 errmsg(
"could not redirect stderr: %m")));
745 /* Now we are done with the write end of the pipe. */
751 * open the pipe in binary mode and make sure stderr is binary after
752 * it's been dup'ed into, to avoid disturbing the pipe chunking
757 _O_APPEND | _O_BINARY);
761 errmsg(
"could not redirect stderr: %m")));
766 * Now we are done with the write end of the pipe. CloseHandle() must
767 * not be called because the preceding close() closes the underlying
775 /* postmaster will never write the file(s); close 'em */
788 return (
int) sysloggerPid;
795 * syslogger_fdget() -
797 * Utility wrapper to grab the file descriptor of an opened error output
798 * file. Used when building the command to fork the logging collector.
801syslogger_fdget(FILE *file)
810 return (
int) _get_osfhandle(_fileno(file));
817 * syslogger_fdopen() -
819 * Utility wrapper to re-open an error output file, using the given file
820 * descriptor. Used when parsing arguments in a forked logging collector.
823syslogger_fdopen(
int fd)
830 file = fdopen(
fd,
"a");
836 fd = _open_osfhandle(
fd, _O_APPEND | _O_TEXT);
839 file = fdopen(
fd,
"a");
847#endif /* EXEC_BACKEND */
850/* --------------------------------
851 * pipe protocol handling
852 * --------------------------------
856 * Process data received through the syslogger pipe.
858 * This routine interprets the log pipe protocol which sends log messages as
859 * (hopefully atomic) chunks - such chunks are detected and reassembled here.
861 * The protocol has a header that starts with two nul bytes, then has a 16 bit
862 * length, the pid of the sending process, and a flag to indicate if it is
863 * the last chunk in a message. Incomplete chunks are saved until we read some
864 * more, and non-final chunks are accumulated until we get the final chunk.
866 * All of this is to avoid 2 problems:
867 * . partial messages being written to logfiles (messes rotation), and
868 * . messages from different backends being interleaved (messages garbled).
870 * Any non-protocol messages are written out directly. These should only come
871 * from non-PostgreSQL sources, however (e.g. third party libraries writing to
874 * logbuffer is the data input buffer, and *bytes_in_logbuffer is the number
875 * of bytes present. On exit, any not-yet-eaten data is left-justified in
876 * logbuffer, and *bytes_in_logbuffer is updated.
882 int count = *bytes_in_logbuffer;
885 /* While we have enough for a header, process data... */
892 /* Do we have a valid header? */
897 if (p.
nuls[0] ==
'0円' && p.
nuls[1] ==
'0円' &&
910 /* Fall out of loop if we don't have the whole chunk yet */
911 if (count < chunklen)
922 /* this should never happen as of the header validation */
926 /* Locate any existing buffer for this source pid */
928 foreach(cell, buffer_list)
937 if (
buf->pid == 0 && free_slot == NULL)
944 * Save a complete non-final chunk in a per-pid buffer
946 if (existing_slot != NULL)
948 /* Add chunk to data from preceding chunks */
956 /* First chunk of message, save in a new buffer */
957 if (free_slot == NULL)
960 * Need a free slot, but there isn't one in the list,
961 * so create a new one and extend the list with it.
964 buffer_list =
lappend(buffer_list, free_slot);
967 free_slot->pid = p.
pid;
968 str = &(free_slot->data);
978 * Final chunk --- add it to anything saved for that pid, and
979 * either way write the whole thing out.
981 if (existing_slot != NULL)
988 /* Mark the buffer unused, and reclaim string storage */
989 existing_slot->
pid = 0;
994 /* The whole message was one chunk, evidently. */
1000 /* Finished processing this chunk */
1006 /* Process non-protocol data */
1009 * Look for the start of a protocol header. If found, dump data
1010 * up to there and repeat the loop. Otherwise, dump it all and
1011 * fall out of the loop. (Note: we want to dump it all if at all
1012 * possible, so as to avoid dividing non-protocol messages across
1013 * logfiles. We expect that in many scenarios, a non-protocol
1014 * message will arrive all in one read(), and we want to respect
1015 * the read() boundary if possible.)
1017 for (chunklen = 1; chunklen < count; chunklen++)
1019 if (
cursor[chunklen] ==
'0円')
1022 /* fall back on the stderr log as the destination */
1029 /* We don't have a full chunk, so left-align what remains in the buffer */
1030 if (count > 0 &&
cursor != logbuffer)
1031 memmove(logbuffer,
cursor, count);
1032 *bytes_in_logbuffer = count;
1036 * Force out any buffered data
1038 * This is currently used only at syslogger shutdown, but could perhaps be
1039 * useful at other times, so it is careful to leave things in a clean state.
1046 /* Dump any incomplete protocol messages */
1062 /* Mark the buffer unused, and reclaim string storage */
1070 * Force out any remaining pipe data as-is; we don't bother trying to
1071 * remove any protocol headers that may exist in it.
1073 if (*bytes_in_logbuffer > 0)
1076 *bytes_in_logbuffer = 0;
1080/* --------------------------------
1082 * --------------------------------
1086 * Write text to the currently open logfile
1088 * This is exported so that elog.c can call it when MyBackendType is B_LOGGER.
1089 * This allows the syslogger process to record elog messages of its own,
1090 * even though its stderr does not point at the syslog pipe.
1099 * If we're told to write to a structured log file, but it's not open,
1100 * dump the data to syslogFile (which is always open) instead. This can
1101 * happen if structured output is enabled after postmaster start and we've
1102 * been unable to open logFile. There are also race conditions during a
1103 * parameter change whereby backends might send us structured output
1104 * before we open the logFile or after we close it. Writing formatted
1105 * output to the regular log file isn't great, but it beats dropping log
1106 * output on the floor.
1108 * Think not to improve this by trying to open logFile on-the-fly. Any
1109 * failure in that would lead to recursion.
1118 rc = fwrite(buffer, 1, count,
logfile);
1121 * Try to report any failure. We mustn't use ereport because it would
1122 * just recurse right back here, but write_stderr is OK: it will write
1123 * either to the postmaster's original stderr, or to /dev/null, but never
1124 * to our input pipe which would result in a different sort of looping.
1133 * Worker thread to transfer data from the pipe to the current logfile.
1135 * We need this because on Windows, WaitForMultipleObjects does not work on
1136 * unnamed pipes: it always reports "signaled", so the blocking ReadFile won't
1137 * allow for SIGHUP; and select is for sockets only.
1139static unsigned int __stdcall
1140pipeThread(
void *
arg)
1143 int bytes_in_logbuffer = 0;
1151 logbuffer + bytes_in_logbuffer,
1152 sizeof(logbuffer) - bytes_in_logbuffer,
1156 * Enter critical section before doing anything that might touch
1157 * global state shared by the main thread. Anything that uses
1158 * palloc()/pfree() in particular are not safe outside the critical
1161 EnterCriticalSection(&sysloggerSection);
1164 DWORD
error = GetLastError();
1166 if (
error == ERROR_HANDLE_EOF ||
1167 error == ERROR_BROKEN_PIPE)
1172 errmsg(
"could not read from logger pipe: %m")));
1174 else if (bytesRead > 0)
1176 bytes_in_logbuffer += bytesRead;
1181 * If we've filled the current logfile, nudge the main thread to do a
1193 LeaveCriticalSection(&sysloggerSection);
1196 /* We exit the above loop only upon detecting pipe EOF */
1199 /* if there's any data left then force it out now */
1202 /* set the latch to waken the main thread, which will quit */
1205 LeaveCriticalSection(&sysloggerSection);
1212 * Open a new logfile with proper permissions and buffering options.
1214 * If allow_errors is true, we just log any open failure and return NULL
1215 * (with errno still correct for the fopen failure).
1216 * Otherwise, errors are treated as fatal.
1225 * Note we do not let Log_file_mode disable IWUSR, since we certainly want
1226 * to be able to write the files ourselves.
1237 /* use CRLF line endings on Windows */
1238 _setmode(_fileno(fh), _O_TEXT);
1243 int save_errno = errno;
1247 errmsg(
"could not open log file \"%s\": %m",
1256 * Do logfile rotation for a single destination, as specified by target_dest.
1257 * The information stored in *last_file_name and *logFile is updated on a
1258 * successful file rotation.
1260 * Returns false if the rotation has been stopped, or true to move on to
1261 * the processing of other formats.
1266 char **last_file_name, FILE **logFile)
1268 char *logFileExt = NULL;
1273 * If the target destination was just turned off, close the previous file
1274 * and unregister its data. This cannot happen for stderr as syslogFile
1275 * is assumed to be always opened even if stderr is disabled in
1281 if (*logFile != NULL)
1284 if (*last_file_name != NULL)
1285 pfree(*last_file_name);
1286 *last_file_name = NULL;
1291 * Leave if it is not time for a rotation or if the target destination has
1292 * no need to do a rotation based on the size of its file.
1294 if (!time_based_rotation && (size_rotation_for & target_dest) == 0)
1297 /* file extension depends on the destination type */
1301 logFileExt =
".csv";
1303 logFileExt =
".json";
1310 /* build the new file name */
1314 * Decide whether to overwrite or append. We can overwrite if (a)
1315 * Log_truncate_on_rotation is set, (b) the rotation was triggered by
1316 * elapsed time and not something else, and (c) the computed file name is
1317 * different from what we were previously logging into.
1320 *last_file_name != NULL &&
1321 strcmp(
filename, *last_file_name) != 0)
1329 * ENFILE/EMFILE are not too surprising on a busy system; just keep
1330 * using the old file till we manage to get a new one. Otherwise,
1331 * assume something's wrong with Log_directory and stop trying to
1334 if (errno != ENFILE && errno != EMFILE)
1337 (
errmsg(
"disabling automatic rotation (use SIGHUP to re-enable)")));
1346 /* fill in the new information */
1347 if (*logFile != NULL)
1351 /* instead of pfree'ing filename, remember it for next time */
1352 if (*last_file_name != NULL)
1353 pfree(*last_file_name);
1360 * perform logfile rotation
1370 * When doing a time-based rotation, invent the new logfile name based on
1371 * the planned rotation time, not current time, to avoid "slippage" in the
1372 * file name when we don't do the rotation immediately.
1374 if (time_based_rotation)
1377 fntime = time(NULL);
1379 /* file rotation for stderr */
1385 /* file rotation for csvlog */
1391 /* file rotation for jsonlog */
1404 * construct logfile name using timestamp information
1406 * If suffix isn't NULL, append it to the name, replacing any ".log"
1407 * that may be in the pattern.
1409 * Result is palloc'd.
1423 /* treat Log_filename as a strftime pattern */
1439 * Determine the next planned rotation time, and store in next_rotation_time.
1448 /* nothing to do if time-based rotation is disabled */
1453 * The requirements here are to choose the next time > now that is a
1454 * "multiple" of the log rotation interval. "Multiple" can be interpreted
1455 * fairly loosely. In this version we align to log_timezone rather than
1462 now -=
now % rotinterval;
1469 * Store the name of the file(s) where the log collector, when enabled, writes
1470 * log messages. Useful for finding the name(s) of the current log file(s)
1471 * when there is time-based logfile rotation. Filenames are stored in a
1472 * temporary file and which is renamed into the final destination for
1473 * atomicity. The file is opened with the same permissions as what gets
1474 * created in the data directory and has proper buffering options.
1489 errmsg(
"could not remove file \"%s\": %m",
1494 /* use the same permissions as the data directory for the new file */
1504 /* use CRLF line endings on Windows */
1505 _setmode(_fileno(fh), _O_TEXT);
1512 errmsg(
"could not open file \"%s\": %m",
1523 errmsg(
"could not write file \"%s\": %m",
1536 errmsg(
"could not write file \"%s\": %m",
1549 errmsg(
"could not write file \"%s\": %m",
1560 errmsg(
"could not rename file \"%s\" to \"%s\": %m",
1564/* --------------------------------
1565 * signal handler routines
1566 * --------------------------------
1570 * Check to see if a log rotation request has arrived. Should be
1571 * called by postmaster after receiving SIGUSR1.
1576 struct stat stat_buf;
1585 * Remove the file signaling a log rotation request.
1593/* SIGUSR1: set flag to rotate logfile */
Datum now(PG_FUNCTION_ARGS)
#define write_stderr(str)
#define fprintf(file, fmt, msg)
int errcode_for_socket_access(void)
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errhint(const char *fmt,...)
int errmsg(const char *fmt,...)
#define LOG_DESTINATION_JSONLOG
#define LOG_DESTINATION_STDERR
#define ereport(elevel,...)
#define LOG_DESTINATION_CSVLOG
int MakePGDirectory(const char *directoryName)
void ProcessConfigFile(GucContext context)
Assert(PointerIsAligned(start, uint64))
volatile sig_atomic_t ConfigReloadPending
void SignalHandlerForConfigReload(SIGNAL_ARGS)
void SetLatch(Latch *latch)
void ResetLatch(Latch *latch)
pid_t postmaster_child_launch(BackendType child_type, int child_slot, void *startup_data, size_t startup_data_len, ClientSocket *client_sock)
List * lappend(List *list, void *datum)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext PostmasterContext
void MemoryContextDelete(MemoryContext context)
BackendType MyBackendType
PGDLLIMPORT const uint8 pg_number_of_ones[256]
static PgChecksumMode mode
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
PGDLLIMPORT pg_tz * log_timezone
size_t strlcpy(char *dst, const char *src, size_t siz)
CommandDest whereToSendOutput
static int fd(const char *x, int i)
void init_ps_display(const char *fixed_part)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void initStringInfo(StringInfo str)
bool Log_truncate_on_rotation
static bool rotation_disabled
static void logfile_rotate(bool time_based_rotation, int size_rotation_for)
static bool pipe_eof_seen
void SysLoggerMain(const void *startup_data, size_t startup_data_len)
static bool logfile_rotate_dest(bool time_based_rotation, int size_rotation_for, pg_time_t fntime, int target_dest, char **last_file_name, FILE **logFile)
bool CheckLogrotateSignal(void)
static char * logfile_getname(pg_time_t timestamp, const char *suffix)
#define LOGROTATE_SIGNAL_FILE
static FILE * logfile_open(const char *filename, const char *mode, bool allow_errors)
static void update_metainfo_datafile(void)
static char * last_csv_file_name
NON_EXEC_STATIC pg_time_t first_syslogger_file_time
static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
void RemoveLogrotateSignalFiles(void)
void write_syslogger_file(const char *buffer, int count, int destination)
static pg_time_t next_rotation_time
static volatile sig_atomic_t rotation_requested
static List * buffer_lists[NBUFFER_LISTS]
static void sigUsr1Handler(SIGNAL_ARGS)
static void set_next_rotation_time(void)
static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
int SysLogger_Start(int child_slot)
static FILE * jsonlogFile
static char * last_json_file_name
static char * last_sys_file_name
#define PIPE_PROTO_DEST_JSONLOG
#define PIPE_PROTO_IS_LAST
#define PIPE_PROTO_DEST_CSVLOG
#define LOG_METAINFO_DATAFILE_TMP
#define PIPE_PROTO_DEST_STDERR
#define LOG_METAINFO_DATAFILE
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
WaitEventSet * CreateWaitEventSet(ResourceOwner resowner, int nevents)
#define WL_SOCKET_READABLE
void _dosmaperr(unsigned long)