PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
syslogger.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * syslogger.c
4  *
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.
13  *
14  * Author: Andreas Pflug <pgadmin@pse-consulting.de>
15  *
16  * Copyright (c) 2004-2017, PostgreSQL Global Development Group
17  *
18  *
19  * IDENTIFICATION
20  * src/backend/postmaster/syslogger.c
21  *
22  *-------------------------------------------------------------------------
23  */
24 #include "postgres.h"
25 
26 #include <fcntl.h>
27 #include <limits.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <unistd.h>
31 #include <sys/stat.h>
32 #include <sys/time.h>
33 
34 #include "lib/stringinfo.h"
35 #include "libpq/pqsignal.h"
36 #include "miscadmin.h"
37 #include "nodes/pg_list.h"
38 #include "pgstat.h"
39 #include "pgtime.h"
41 #include "postmaster/postmaster.h"
42 #include "postmaster/syslogger.h"
43 #include "storage/dsm.h"
44 #include "storage/ipc.h"
45 #include "storage/latch.h"
46 #include "storage/pg_shmem.h"
47 #include "utils/guc.h"
48 #include "utils/ps_status.h"
49 #include "utils/timestamp.h"
50 
51 /*
52  * We read() into a temp buffer twice as big as a chunk, so that any fragment
53  * left after processing can be moved down to the front and we'll still have
54  * room to read a full chunk.
55  */
56 #define READ_BUF_SIZE (2 * PIPE_CHUNK_SIZE)
57 
58 
59 /*
60  * GUC parameters. Logging_collector cannot be changed after postmaster
61  * start, but the rest can change at SIGHUP.
62  */
63 bool Logging_collector = false;
65 int Log_RotationSize = 10 * 1024;
69 int Log_file_mode = S_IRUSR | S_IWUSR;
70 
71 /*
72  * Globally visible state (used by elog.c)
73  */
74 bool am_syslogger = false;
75 
76 extern bool redirection_done;
77 
78 /*
79  * Private state
80  */
82 static bool pipe_eof_seen = false;
83 static bool rotation_disabled = false;
84 static FILE *syslogFile = NULL;
85 static FILE *csvlogFile = NULL;
87 static char *last_file_name = NULL;
88 static char *last_csv_file_name = NULL;
89 
90 /*
91  * Buffers for saving partial messages from different backends.
92  *
93  * Keep NBUFFER_LISTS lists of these, with the entry for a given source pid
94  * being in the list numbered (pid % NBUFFER_LISTS), so as to cut down on
95  * the number of entries we have to examine for any one incoming message.
96  * There must never be more than one entry for the same source pid.
97  *
98  * An inactive buffer is not removed from its list, just held for re-use.
99  * An inactive buffer has pid == 0 and undefined contents of data.
100  */
101 typedef struct
102 {
103  int32 pid; /* PID of source process */
104  StringInfoData data; /* accumulated data, as a StringInfo */
105 } save_buffer;
106 
107 #define NBUFFER_LISTS 256
109 
110 /* These must be exported for EXEC_BACKEND case ... annoying */
111 #ifndef WIN32
112 int syslogPipe[2] = {-1, -1};
113 #else
114 HANDLE syslogPipe[2] = {0, 0};
115 #endif
116 
117 #ifdef WIN32
118 static HANDLE threadHandle = 0;
119 static CRITICAL_SECTION sysloggerSection;
120 #endif
121 
122 /*
123  * Flags set by interrupt handlers for later service in the main loop.
124  */
125 static volatile sig_atomic_t got_SIGHUP = false;
126 static volatile sig_atomic_t rotation_requested = false;
127 
128 
129 /* Local subroutines */
130 #ifdef EXEC_BACKEND
131 static pid_t syslogger_forkexec(void);
132 static void syslogger_parseArgs(int argc, char *argv[]);
133 #endif
134 NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn();
135 static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
136 static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer);
137 static void open_csvlogfile(void);
138 static FILE *logfile_open(const char *filename, const char *mode,
139  bool allow_errors);
140 
141 #ifdef WIN32
142 static unsigned int __stdcall pipeThread(void *arg);
143 #endif
144 static void logfile_rotate(bool time_based_rotation, int size_rotation_for);
145 static char *logfile_getname(pg_time_t timestamp, const char *suffix);
146 static void set_next_rotation_time(void);
147 static void sigHupHandler(SIGNAL_ARGS);
148 static void sigUsr1Handler(SIGNAL_ARGS);
149 
150 
151 /*
152  * Main entry point for syslogger process
153  * argc/argv parameters are valid only in EXEC_BACKEND case.
154  */
155 NON_EXEC_STATIC void
156 SysLoggerMain(int argc, char *argv[])
157 {
158 #ifndef WIN32
159  char logbuffer[READ_BUF_SIZE];
160  int bytes_in_logbuffer = 0;
161 #endif
162  char *currentLogDir;
163  char *currentLogFilename;
164  int currentLogRotationAge;
165  pg_time_t now;
166 
167  now = MyStartTime;
168 
169 #ifdef EXEC_BACKEND
170  syslogger_parseArgs(argc, argv);
171 #endif /* EXEC_BACKEND */
172 
173  am_syslogger = true;
174 
175  init_ps_display("logger process", "", "", "");
176 
177  /*
178  * If we restarted, our stderr is already redirected into our own input
179  * pipe. This is of course pretty useless, not to mention that it
180  * interferes with detecting pipe EOF. Point stderr to /dev/null. This
181  * assumes that all interesting messages generated in the syslogger will
182  * come through elog.c and will be sent to write_syslogger_file.
183  */
184  if (redirection_done)
185  {
186  int fd = open(DEVNULL, O_WRONLY, 0);
187 
188  /*
189  * The closes might look redundant, but they are not: we want to be
190  * darn sure the pipe gets closed even if the open failed. We can
191  * survive running with stderr pointing nowhere, but we can't afford
192  * to have extra pipe input descriptors hanging around.
193  *
194  * As we're just trying to reset these to go to DEVNULL, there's not
195  * much point in checking for failure from the close/dup2 calls here,
196  * if they fail then presumably the file descriptors are closed and
197  * any writes will go into the bitbucket anyway.
198  */
199  close(fileno(stdout));
200  close(fileno(stderr));
201  if (fd != -1)
202  {
203  (void) dup2(fd, fileno(stdout));
204  (void) dup2(fd, fileno(stderr));
205  close(fd);
206  }
207  }
208 
209  /*
210  * Syslogger's own stderr can't be the syslogPipe, so set it back to text
211  * mode if we didn't just close it. (It was set to binary in
212  * SubPostmasterMain).
213  */
214 #ifdef WIN32
215  else
216  _setmode(_fileno(stderr), _O_TEXT);
217 #endif
218 
219  /*
220  * Also close our copy of the write end of the pipe. This is needed to
221  * ensure we can detect pipe EOF correctly. (But note that in the restart
222  * case, the postmaster already did this.)
223  */
224 #ifndef WIN32
225  if (syslogPipe[1] >= 0)
226  close(syslogPipe[1]);
227  syslogPipe[1] = -1;
228 #else
229  if (syslogPipe[1])
230  CloseHandle(syslogPipe[1]);
231  syslogPipe[1] = 0;
232 #endif
233 
234  /*
235  * Properly accept or ignore signals the postmaster might send us
236  *
237  * Note: we ignore all termination signals, and instead exit only when all
238  * upstream processes are gone, to ensure we don't miss any dying gasps of
239  * broken backends...
240  */
241 
242  pqsignal(SIGHUP, sigHupHandler); /* set flag to read config file */
243  pqsignal(SIGINT, SIG_IGN);
244  pqsignal(SIGTERM, SIG_IGN);
248  pqsignal(SIGUSR1, sigUsr1Handler); /* request log rotation */
250 
251  /*
252  * Reset some signals that are accepted by postmaster but not here
253  */
259 
261 
262 #ifdef WIN32
263  /* Fire up separate data transfer thread */
264  InitializeCriticalSection(&sysloggerSection);
265  EnterCriticalSection(&sysloggerSection);
266 
267  threadHandle = (HANDLE) _beginthreadex(NULL, 0, pipeThread, NULL, 0, NULL);
268  if (threadHandle == 0)
269  elog(FATAL, "could not create syslogger data transfer thread: %m");
270 #endif /* WIN32 */
271 
272  /*
273  * Remember active logfile's name. We recompute this from the reference
274  * time because passing down just the pg_time_t is a lot cheaper than
275  * passing a whole file path in the EXEC_BACKEND case.
276  */
278 
279  /* remember active logfile parameters */
280  currentLogDir = pstrdup(Log_directory);
281  currentLogFilename = pstrdup(Log_filename);
282  currentLogRotationAge = Log_RotationAge;
283  /* set next planned rotation time */
285 
286  /* main worker loop */
287  for (;;)
288  {
289  bool time_based_rotation = false;
290  int size_rotation_for = 0;
291  long cur_timeout;
292  int cur_flags;
293 
294 #ifndef WIN32
295  int rc;
296 #endif
297 
298  /* Clear any already-pending wakeups */
300 
301  /*
302  * Process any requests or signals received recently.
303  */
304  if (got_SIGHUP)
305  {
306  got_SIGHUP = false;
308 
309  /*
310  * Check if the log directory or filename pattern changed in
311  * postgresql.conf. If so, force rotation to make sure we're
312  * writing the logfiles in the right place.
313  */
314  if (strcmp(Log_directory, currentLogDir) != 0)
315  {
316  pfree(currentLogDir);
317  currentLogDir = pstrdup(Log_directory);
318  rotation_requested = true;
319 
320  /*
321  * Also, create new directory if not present; ignore errors
322  */
323  mkdir(Log_directory, S_IRWXU);
324  }
325  if (strcmp(Log_filename, currentLogFilename) != 0)
326  {
327  pfree(currentLogFilename);
328  currentLogFilename = pstrdup(Log_filename);
329  rotation_requested = true;
330  }
331 
332  /*
333  * If rotation time parameter changed, reset next rotation time,
334  * but don't immediately force a rotation.
335  */
336  if (currentLogRotationAge != Log_RotationAge)
337  {
338  currentLogRotationAge = Log_RotationAge;
340  }
341 
342  /*
343  * If we had a rotation-disabling failure, re-enable rotation
344  * attempts after SIGHUP, and force one immediately.
345  */
346  if (rotation_disabled)
347  {
348  rotation_disabled = false;
349  rotation_requested = true;
350  }
351  }
352 
354  {
355  /* Do a logfile rotation if it's time */
356  now = (pg_time_t) time(NULL);
357  if (now >= next_rotation_time)
358  rotation_requested = time_based_rotation = true;
359  }
360 
362  {
363  /* Do a rotation if file is too big */
364  if (ftell(syslogFile) >= Log_RotationSize * 1024L)
365  {
366  rotation_requested = true;
367  size_rotation_for |= LOG_DESTINATION_STDERR;
368  }
369  if (csvlogFile != NULL &&
370  ftell(csvlogFile) >= Log_RotationSize * 1024L)
371  {
372  rotation_requested = true;
373  size_rotation_for |= LOG_DESTINATION_CSVLOG;
374  }
375  }
376 
377  if (rotation_requested)
378  {
379  /*
380  * Force rotation when both values are zero. It means the request
381  * was sent by pg_rotate_logfile.
382  */
383  if (!time_based_rotation && size_rotation_for == 0)
384  size_rotation_for = LOG_DESTINATION_STDERR | LOG_DESTINATION_CSVLOG;
385  logfile_rotate(time_based_rotation, size_rotation_for);
386  }
387 
388  /*
389  * Calculate time till next time-based rotation, so that we don't
390  * sleep longer than that. We assume the value of "now" obtained
391  * above is still close enough. Note we can't make this calculation
392  * until after calling logfile_rotate(), since it will advance
393  * next_rotation_time.
394  *
395  * Also note that we need to beware of overflow in calculation of the
396  * timeout: with large settings of Log_RotationAge, next_rotation_time
397  * could be more than INT_MAX msec in the future. In that case we'll
398  * wait no more than INT_MAX msec, and try again.
399  */
401  {
402  pg_time_t delay;
403 
404  delay = next_rotation_time - now;
405  if (delay > 0)
406  {
407  if (delay > INT_MAX / 1000)
408  delay = INT_MAX / 1000;
409  cur_timeout = delay * 1000L; /* msec */
410  }
411  else
412  cur_timeout = 0;
413  cur_flags = WL_TIMEOUT;
414  }
415  else
416  {
417  cur_timeout = -1L;
418  cur_flags = 0;
419  }
420 
421  /*
422  * Sleep until there's something to do
423  */
424 #ifndef WIN32
426  WL_LATCH_SET | WL_SOCKET_READABLE | cur_flags,
427  syslogPipe[0],
428  cur_timeout,
430 
431  if (rc & WL_SOCKET_READABLE)
432  {
433  int bytesRead;
434 
435  bytesRead = read(syslogPipe[0],
436  logbuffer + bytes_in_logbuffer,
437  sizeof(logbuffer) - bytes_in_logbuffer);
438  if (bytesRead < 0)
439  {
440  if (errno != EINTR)
441  ereport(LOG,
443  errmsg("could not read from logger pipe: %m")));
444  }
445  else if (bytesRead > 0)
446  {
447  bytes_in_logbuffer += bytesRead;
448  process_pipe_input(logbuffer, &bytes_in_logbuffer);
449  continue;
450  }
451  else
452  {
453  /*
454  * Zero bytes read when select() is saying read-ready means
455  * EOF on the pipe: that is, there are no longer any processes
456  * with the pipe write end open. Therefore, the postmaster
457  * and all backends are shut down, and we are done.
458  */
459  pipe_eof_seen = true;
460 
461  /* if there's any data left then force it out now */
462  flush_pipe_input(logbuffer, &bytes_in_logbuffer);
463  }
464  }
465 #else /* WIN32 */
466 
467  /*
468  * On Windows we leave it to a separate thread to transfer data and
469  * detect pipe EOF. The main thread just wakes up to handle SIGHUP
470  * and rotation conditions.
471  *
472  * Server code isn't generally thread-safe, so we ensure that only one
473  * of the threads is active at a time by entering the critical section
474  * whenever we're not sleeping.
475  */
476  LeaveCriticalSection(&sysloggerSection);
477 
478  (void) WaitLatch(MyLatch,
479  WL_LATCH_SET | cur_flags,
480  cur_timeout,
482 
483  EnterCriticalSection(&sysloggerSection);
484 #endif /* WIN32 */
485 
486  if (pipe_eof_seen)
487  {
488  /*
489  * seeing this message on the real stderr is annoying - so we make
490  * it DEBUG1 to suppress in normal use.
491  */
492  ereport(DEBUG1,
493  (errmsg("logger shutting down")));
494 
495  /*
496  * Normal exit from the syslogger is here. Note that we
497  * deliberately do not close syslogFile before exiting; this is to
498  * allow for the possibility of elog messages being generated
499  * inside proc_exit. Regular exit() will take care of flushing
500  * and closing stdio channels.
501  */
502  proc_exit(0);
503  }
504  }
505 }
506 
507 /*
508  * Postmaster subroutine to start a syslogger subprocess.
509  */
510 int
512 {
513  pid_t sysloggerPid;
514  char *filename;
515 
516  if (!Logging_collector)
517  return 0;
518 
519  /*
520  * If first time through, create the pipe which will receive stderr
521  * output.
522  *
523  * If the syslogger crashes and needs to be restarted, we continue to use
524  * the same pipe (indeed must do so, since extant backends will be writing
525  * into that pipe).
526  *
527  * This means the postmaster must continue to hold the read end of the
528  * pipe open, so we can pass it down to the reincarnated syslogger. This
529  * is a bit klugy but we have little choice.
530  */
531 #ifndef WIN32
532  if (syslogPipe[0] < 0)
533  {
534  if (pipe(syslogPipe) < 0)
535  ereport(FATAL,
537  (errmsg("could not create pipe for syslog: %m"))));
538  }
539 #else
540  if (!syslogPipe[0])
541  {
542  SECURITY_ATTRIBUTES sa;
543 
544  memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
545  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
546  sa.bInheritHandle = TRUE;
547 
548  if (!CreatePipe(&syslogPipe[0], &syslogPipe[1], &sa, 32768))
549  ereport(FATAL,
551  (errmsg("could not create pipe for syslog: %m"))));
552  }
553 #endif
554 
555  /*
556  * Create log directory if not present; ignore errors
557  */
558  mkdir(Log_directory, S_IRWXU);
559 
560  /*
561  * The initial logfile is created right in the postmaster, to verify that
562  * the Log_directory is writable. We save the reference time so that the
563  * syslogger child process can recompute this file name.
564  *
565  * It might look a bit strange to re-do this during a syslogger restart,
566  * but we must do so since the postmaster closed syslogFile after the
567  * previous fork (and remembering that old file wouldn't be right anyway).
568  * Note we always append here, we won't overwrite any existing file. This
569  * is consistent with the normal rules, because by definition this is not
570  * a time-based rotation.
571  */
574 
575  syslogFile = logfile_open(filename, "a", false);
576 
577  pfree(filename);
578 
579 #ifdef EXEC_BACKEND
580  switch ((sysloggerPid = syslogger_forkexec()))
581 #else
582  switch ((sysloggerPid = fork_process()))
583 #endif
584  {
585  case -1:
586  ereport(LOG,
587  (errmsg("could not fork system logger: %m")));
588  return 0;
589 
590 #ifndef EXEC_BACKEND
591  case 0:
592  /* in postmaster child ... */
594 
595  /* Close the postmaster's sockets */
596  ClosePostmasterPorts(true);
597 
598  /* Drop our connection to postmaster's shared memory, as well */
599  dsm_detach_all();
601 
602  /* do the work */
603  SysLoggerMain(0, NULL);
604  break;
605 #endif
606 
607  default:
608  /* success, in postmaster */
609 
610  /* now we redirect stderr, if not done already */
611  if (!redirection_done)
612  {
613 #ifdef WIN32
614  int fd;
615 #endif
616 
617  /*
618  * Leave a breadcrumb trail when redirecting, in case the user
619  * forgets that redirection is active and looks only at the
620  * original stderr target file.
621  */
622  ereport(LOG,
623  (errmsg("redirecting log output to logging collector process"),
624  errhint("Future log output will appear in directory \"%s\".",
625  Log_directory)));
626 
627 #ifndef WIN32
628  fflush(stdout);
629  if (dup2(syslogPipe[1], fileno(stdout)) < 0)
630  ereport(FATAL,
632  errmsg("could not redirect stdout: %m")));
633  fflush(stderr);
634  if (dup2(syslogPipe[1], fileno(stderr)) < 0)
635  ereport(FATAL,
637  errmsg("could not redirect stderr: %m")));
638  /* Now we are done with the write end of the pipe. */
639  close(syslogPipe[1]);
640  syslogPipe[1] = -1;
641 #else
642 
643  /*
644  * open the pipe in binary mode and make sure stderr is binary
645  * after it's been dup'ed into, to avoid disturbing the pipe
646  * chunking protocol.
647  */
648  fflush(stderr);
649  fd = _open_osfhandle((intptr_t) syslogPipe[1],
650  _O_APPEND | _O_BINARY);
651  if (dup2(fd, _fileno(stderr)) < 0)
652  ereport(FATAL,
654  errmsg("could not redirect stderr: %m")));
655  close(fd);
656  _setmode(_fileno(stderr), _O_BINARY);
657 
658  /*
659  * Now we are done with the write end of the pipe.
660  * CloseHandle() must not be called because the preceding
661  * close() closes the underlying handle.
662  */
663  syslogPipe[1] = 0;
664 #endif
665  redirection_done = true;
666  }
667 
668  /* postmaster will never write the file; close it */
669  fclose(syslogFile);
670  syslogFile = NULL;
671  return (int) sysloggerPid;
672  }
673 
674  /* we should never reach here */
675  return 0;
676 }
677 
678 
679 #ifdef EXEC_BACKEND
680 
681 /*
682  * syslogger_forkexec() -
683  *
684  * Format up the arglist for, then fork and exec, a syslogger process
685  */
686 static pid_t
687 syslogger_forkexec(void)
688 {
689  char *av[10];
690  int ac = 0;
691  char filenobuf[32];
692 
693  av[ac++] = "postgres";
694  av[ac++] = "--forklog";
695  av[ac++] = NULL; /* filled in by postmaster_forkexec */
696 
697  /* static variables (those not passed by write_backend_variables) */
698 #ifndef WIN32
699  if (syslogFile != NULL)
700  snprintf(filenobuf, sizeof(filenobuf), "%d",
701  fileno(syslogFile));
702  else
703  strcpy(filenobuf, "-1");
704 #else /* WIN32 */
705  if (syslogFile != NULL)
706  snprintf(filenobuf, sizeof(filenobuf), "%ld",
707  (long) _get_osfhandle(_fileno(syslogFile)));
708  else
709  strcpy(filenobuf, "0");
710 #endif /* WIN32 */
711  av[ac++] = filenobuf;
712 
713  av[ac] = NULL;
714  Assert(ac < lengthof(av));
715 
716  return postmaster_forkexec(ac, av);
717 }
718 
719 /*
720  * syslogger_parseArgs() -
721  *
722  * Extract data from the arglist for exec'ed syslogger process
723  */
724 static void
725 syslogger_parseArgs(int argc, char *argv[])
726 {
727  int fd;
728 
729  Assert(argc == 4);
730  argv += 3;
731 
732 #ifndef WIN32
733  fd = atoi(*argv++);
734  if (fd != -1)
735  {
736  syslogFile = fdopen(fd, "a");
737  setvbuf(syslogFile, NULL, PG_IOLBF, 0);
738  }
739 #else /* WIN32 */
740  fd = atoi(*argv++);
741  if (fd != 0)
742  {
743  fd = _open_osfhandle(fd, _O_APPEND | _O_TEXT);
744  if (fd > 0)
745  {
746  syslogFile = fdopen(fd, "a");
747  setvbuf(syslogFile, NULL, PG_IOLBF, 0);
748  }
749  }
750 #endif /* WIN32 */
751 }
752 #endif /* EXEC_BACKEND */
753 
754 
755 /* --------------------------------
756  * pipe protocol handling
757  * --------------------------------
758  */
759 
760 /*
761  * Process data received through the syslogger pipe.
762  *
763  * This routine interprets the log pipe protocol which sends log messages as
764  * (hopefully atomic) chunks - such chunks are detected and reassembled here.
765  *
766  * The protocol has a header that starts with two nul bytes, then has a 16 bit
767  * length, the pid of the sending process, and a flag to indicate if it is
768  * the last chunk in a message. Incomplete chunks are saved until we read some
769  * more, and non-final chunks are accumulated until we get the final chunk.
770  *
771  * All of this is to avoid 2 problems:
772  * . partial messages being written to logfiles (messes rotation), and
773  * . messages from different backends being interleaved (messages garbled).
774  *
775  * Any non-protocol messages are written out directly. These should only come
776  * from non-PostgreSQL sources, however (e.g. third party libraries writing to
777  * stderr).
778  *
779  * logbuffer is the data input buffer, and *bytes_in_logbuffer is the number
780  * of bytes present. On exit, any not-yet-eaten data is left-justified in
781  * logbuffer, and *bytes_in_logbuffer is updated.
782  */
783 static void
784 process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
785 {
786  char *cursor = logbuffer;
787  int count = *bytes_in_logbuffer;
788  int dest = LOG_DESTINATION_STDERR;
789 
790  /* While we have enough for a header, process data... */
791  while (count >= (int) (offsetof(PipeProtoHeader, data) +1))
792  {
793  PipeProtoHeader p;
794  int chunklen;
795 
796  /* Do we have a valid header? */
797  memcpy(&p, cursor, offsetof(PipeProtoHeader, data));
798  if (p.nuls[0] == '\0' && p.nuls[1] == '\0' &&
799  p.len > 0 && p.len <= PIPE_MAX_PAYLOAD &&
800  p.pid != 0 &&
801  (p.is_last == 't' || p.is_last == 'f' ||
802  p.is_last == 'T' || p.is_last == 'F'))
803  {
804  List *buffer_list;
805  ListCell *cell;
806  save_buffer *existing_slot = NULL,
807  *free_slot = NULL;
808  StringInfo str;
809 
810  chunklen = PIPE_HEADER_SIZE + p.len;
811 
812  /* Fall out of loop if we don't have the whole chunk yet */
813  if (count < chunklen)
814  break;
815 
816  dest = (p.is_last == 'T' || p.is_last == 'F') ?
818 
819  /* Locate any existing buffer for this source pid */
820  buffer_list = buffer_lists[p.pid % NBUFFER_LISTS];
821  foreach(cell, buffer_list)
822  {
823  save_buffer *buf = (save_buffer *) lfirst(cell);
824 
825  if (buf->pid == p.pid)
826  {
827  existing_slot = buf;
828  break;
829  }
830  if (buf->pid == 0 && free_slot == NULL)
831  free_slot = buf;
832  }
833 
834  if (p.is_last == 'f' || p.is_last == 'F')
835  {
836  /*
837  * Save a complete non-final chunk in a per-pid buffer
838  */
839  if (existing_slot != NULL)
840  {
841  /* Add chunk to data from preceding chunks */
842  str = &(existing_slot->data);
844  cursor + PIPE_HEADER_SIZE,
845  p.len);
846  }
847  else
848  {
849  /* First chunk of message, save in a new buffer */
850  if (free_slot == NULL)
851  {
852  /*
853  * Need a free slot, but there isn't one in the list,
854  * so create a new one and extend the list with it.
855  */
856  free_slot = palloc(sizeof(save_buffer));
857  buffer_list = lappend(buffer_list, free_slot);
858  buffer_lists[p.pid % NBUFFER_LISTS] = buffer_list;
859  }
860  free_slot->pid = p.pid;
861  str = &(free_slot->data);
862  initStringInfo(str);
864  cursor + PIPE_HEADER_SIZE,
865  p.len);
866  }
867  }
868  else
869  {
870  /*
871  * Final chunk --- add it to anything saved for that pid, and
872  * either way write the whole thing out.
873  */
874  if (existing_slot != NULL)
875  {
876  str = &(existing_slot->data);
878  cursor + PIPE_HEADER_SIZE,
879  p.len);
880  write_syslogger_file(str->data, str->len, dest);
881  /* Mark the buffer unused, and reclaim string storage */
882  existing_slot->pid = 0;
883  pfree(str->data);
884  }
885  else
886  {
887  /* The whole message was one chunk, evidently. */
889  dest);
890  }
891  }
892 
893  /* Finished processing this chunk */
894  cursor += chunklen;
895  count -= chunklen;
896  }
897  else
898  {
899  /* Process non-protocol data */
900 
901  /*
902  * Look for the start of a protocol header. If found, dump data
903  * up to there and repeat the loop. Otherwise, dump it all and
904  * fall out of the loop. (Note: we want to dump it all if at all
905  * possible, so as to avoid dividing non-protocol messages across
906  * logfiles. We expect that in many scenarios, a non-protocol
907  * message will arrive all in one read(), and we want to respect
908  * the read() boundary if possible.)
909  */
910  for (chunklen = 1; chunklen < count; chunklen++)
911  {
912  if (cursor[chunklen] == '\0')
913  break;
914  }
915  /* fall back on the stderr log as the destination */
916  write_syslogger_file(cursor, chunklen, LOG_DESTINATION_STDERR);
917  cursor += chunklen;
918  count -= chunklen;
919  }
920  }
921 
922  /* We don't have a full chunk, so left-align what remains in the buffer */
923  if (count > 0 && cursor != logbuffer)
924  memmove(logbuffer, cursor, count);
925  *bytes_in_logbuffer = count;
926 }
927 
928 /*
929  * Force out any buffered data
930  *
931  * This is currently used only at syslogger shutdown, but could perhaps be
932  * useful at other times, so it is careful to leave things in a clean state.
933  */
934 static void
935 flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
936 {
937  int i;
938 
939  /* Dump any incomplete protocol messages */
940  for (i = 0; i < NBUFFER_LISTS; i++)
941  {
942  List *list = buffer_lists[i];
943  ListCell *cell;
944 
945  foreach(cell, list)
946  {
947  save_buffer *buf = (save_buffer *) lfirst(cell);
948 
949  if (buf->pid != 0)
950  {
951  StringInfo str = &(buf->data);
952 
953  write_syslogger_file(str->data, str->len,
955  /* Mark the buffer unused, and reclaim string storage */
956  buf->pid = 0;
957  pfree(str->data);
958  }
959  }
960  }
961 
962  /*
963  * Force out any remaining pipe data as-is; we don't bother trying to
964  * remove any protocol headers that may exist in it.
965  */
966  if (*bytes_in_logbuffer > 0)
967  write_syslogger_file(logbuffer, *bytes_in_logbuffer,
969  *bytes_in_logbuffer = 0;
970 }
971 
972 
973 /* --------------------------------
974  * logfile routines
975  * --------------------------------
976  */
977 
978 /*
979  * Write text to the currently open logfile
980  *
981  * This is exported so that elog.c can call it when am_syslogger is true.
982  * This allows the syslogger process to record elog messages of its own,
983  * even though its stderr does not point at the syslog pipe.
984  */
985 void
986 write_syslogger_file(const char *buffer, int count, int destination)
987 {
988  int rc;
989  FILE *logfile;
990 
991  if (destination == LOG_DESTINATION_CSVLOG && csvlogFile == NULL)
992  open_csvlogfile();
993 
994  logfile = destination == LOG_DESTINATION_CSVLOG ? csvlogFile : syslogFile;
995  rc = fwrite(buffer, 1, count, logfile);
996 
997  /* can't use ereport here because of possible recursion */
998  if (rc != count)
999  write_stderr("could not write to log file: %s\n", strerror(errno));
1000 }
1001 
1002 #ifdef WIN32
1003 
1004 /*
1005  * Worker thread to transfer data from the pipe to the current logfile.
1006  *
1007  * We need this because on Windows, WaitforMultipleObjects does not work on
1008  * unnamed pipes: it always reports "signaled", so the blocking ReadFile won't
1009  * allow for SIGHUP; and select is for sockets only.
1010  */
1011 static unsigned int __stdcall
1012 pipeThread(void *arg)
1013 {
1014  char logbuffer[READ_BUF_SIZE];
1015  int bytes_in_logbuffer = 0;
1016 
1017  for (;;)
1018  {
1019  DWORD bytesRead;
1020  BOOL result;
1021 
1022  result = ReadFile(syslogPipe[0],
1023  logbuffer + bytes_in_logbuffer,
1024  sizeof(logbuffer) - bytes_in_logbuffer,
1025  &bytesRead, 0);
1026 
1027  /*
1028  * Enter critical section before doing anything that might touch
1029  * global state shared by the main thread. Anything that uses
1030  * palloc()/pfree() in particular are not safe outside the critical
1031  * section.
1032  */
1033  EnterCriticalSection(&sysloggerSection);
1034  if (!result)
1035  {
1036  DWORD error = GetLastError();
1037 
1038  if (error == ERROR_HANDLE_EOF ||
1039  error == ERROR_BROKEN_PIPE)
1040  break;
1041  _dosmaperr(error);
1042  ereport(LOG,
1044  errmsg("could not read from logger pipe: %m")));
1045  }
1046  else if (bytesRead > 0)
1047  {
1048  bytes_in_logbuffer += bytesRead;
1049  process_pipe_input(logbuffer, &bytes_in_logbuffer);
1050  }
1051 
1052  /*
1053  * If we've filled the current logfile, nudge the main thread to do a
1054  * log rotation.
1055  */
1056  if (Log_RotationSize > 0)
1057  {
1058  if (ftell(syslogFile) >= Log_RotationSize * 1024L ||
1059  (csvlogFile != NULL && ftell(csvlogFile) >= Log_RotationSize * 1024L))
1060  SetLatch(MyLatch);
1061  }
1062  LeaveCriticalSection(&sysloggerSection);
1063  }
1064 
1065  /* We exit the above loop only upon detecting pipe EOF */
1066  pipe_eof_seen = true;
1067 
1068  /* if there's any data left then force it out now */
1069  flush_pipe_input(logbuffer, &bytes_in_logbuffer);
1070 
1071  /* set the latch to waken the main thread, which will quit */
1072  SetLatch(MyLatch);
1073 
1074  LeaveCriticalSection(&sysloggerSection);
1075  _endthread();
1076  return 0;
1077 }
1078 #endif /* WIN32 */
1079 
1080 /*
1081  * Open the csv log file - we do this opportunistically, because
1082  * we don't know if CSV logging will be wanted.
1083  *
1084  * This is only used the first time we open the csv log in a given syslogger
1085  * process, not during rotations. As with opening the main log file, we
1086  * always append in this situation.
1087  */
1088 static void
1090 {
1091  char *filename;
1092 
1093  filename = logfile_getname(time(NULL), ".csv");
1094 
1095  csvlogFile = logfile_open(filename, "a", false);
1096 
1097  if (last_csv_file_name != NULL) /* probably shouldn't happen */
1099 
1101 }
1102 
1103 /*
1104  * Open a new logfile with proper permissions and buffering options.
1105  *
1106  * If allow_errors is true, we just log any open failure and return NULL
1107  * (with errno still correct for the fopen failure).
1108  * Otherwise, errors are treated as fatal.
1109  */
1110 static FILE *
1111 logfile_open(const char *filename, const char *mode, bool allow_errors)
1112 {
1113  FILE *fh;
1114  mode_t oumask;
1115 
1116  /*
1117  * Note we do not let Log_file_mode disable IWUSR, since we certainly want
1118  * to be able to write the files ourselves.
1119  */
1120  oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & (S_IRWXU | S_IRWXG | S_IRWXO)));
1121  fh = fopen(filename, mode);
1122  umask(oumask);
1123 
1124  if (fh)
1125  {
1126  setvbuf(fh, NULL, PG_IOLBF, 0);
1127 
1128 #ifdef WIN32
1129  /* use CRLF line endings on Windows */
1130  _setmode(_fileno(fh), _O_TEXT);
1131 #endif
1132  }
1133  else
1134  {
1135  int save_errno = errno;
1136 
1137  ereport(allow_errors ? LOG : FATAL,
1139  errmsg("could not open log file \"%s\": %m",
1140  filename)));
1141  errno = save_errno;
1142  }
1143 
1144  return fh;
1145 }
1146 
1147 /*
1148  * perform logfile rotation
1149  */
1150 static void
1151 logfile_rotate(bool time_based_rotation, int size_rotation_for)
1152 {
1153  char *filename;
1154  char *csvfilename = NULL;
1155  pg_time_t fntime;
1156  FILE *fh;
1157 
1158  rotation_requested = false;
1159 
1160  /*
1161  * When doing a time-based rotation, invent the new logfile name based on
1162  * the planned rotation time, not current time, to avoid "slippage" in the
1163  * file name when we don't do the rotation immediately.
1164  */
1165  if (time_based_rotation)
1166  fntime = next_rotation_time;
1167  else
1168  fntime = time(NULL);
1169  filename = logfile_getname(fntime, NULL);
1170  if (csvlogFile != NULL)
1171  csvfilename = logfile_getname(fntime, ".csv");
1172 
1173  /*
1174  * Decide whether to overwrite or append. We can overwrite if (a)
1175  * Log_truncate_on_rotation is set, (b) the rotation was triggered by
1176  * elapsed time and not something else, and (c) the computed file name is
1177  * different from what we were previously logging into.
1178  *
1179  * Note: last_file_name should never be NULL here, but if it is, append.
1180  */
1181  if (time_based_rotation || (size_rotation_for & LOG_DESTINATION_STDERR))
1182  {
1183  if (Log_truncate_on_rotation && time_based_rotation &&
1184  last_file_name != NULL &&
1185  strcmp(filename, last_file_name) != 0)
1186  fh = logfile_open(filename, "w", true);
1187  else
1188  fh = logfile_open(filename, "a", true);
1189 
1190  if (!fh)
1191  {
1192  /*
1193  * ENFILE/EMFILE are not too surprising on a busy system; just
1194  * keep using the old file till we manage to get a new one.
1195  * Otherwise, assume something's wrong with Log_directory and stop
1196  * trying to create files.
1197  */
1198  if (errno != ENFILE && errno != EMFILE)
1199  {
1200  ereport(LOG,
1201  (errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1202  rotation_disabled = true;
1203  }
1204 
1205  if (filename)
1206  pfree(filename);
1207  if (csvfilename)
1208  pfree(csvfilename);
1209  return;
1210  }
1211 
1212  fclose(syslogFile);
1213  syslogFile = fh;
1214 
1215  /* instead of pfree'ing filename, remember it for next time */
1216  if (last_file_name != NULL)
1219  filename = NULL;
1220  }
1221 
1222  /* Same as above, but for csv file. */
1223 
1224  if (csvlogFile != NULL &&
1225  (time_based_rotation || (size_rotation_for & LOG_DESTINATION_CSVLOG)))
1226  {
1227  if (Log_truncate_on_rotation && time_based_rotation &&
1228  last_csv_file_name != NULL &&
1229  strcmp(csvfilename, last_csv_file_name) != 0)
1230  fh = logfile_open(csvfilename, "w", true);
1231  else
1232  fh = logfile_open(csvfilename, "a", true);
1233 
1234  if (!fh)
1235  {
1236  /*
1237  * ENFILE/EMFILE are not too surprising on a busy system; just
1238  * keep using the old file till we manage to get a new one.
1239  * Otherwise, assume something's wrong with Log_directory and stop
1240  * trying to create files.
1241  */
1242  if (errno != ENFILE && errno != EMFILE)
1243  {
1244  ereport(LOG,
1245  (errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1246  rotation_disabled = true;
1247  }
1248 
1249  if (filename)
1250  pfree(filename);
1251  if (csvfilename)
1252  pfree(csvfilename);
1253  return;
1254  }
1255 
1256  fclose(csvlogFile);
1257  csvlogFile = fh;
1258 
1259  /* instead of pfree'ing filename, remember it for next time */
1260  if (last_csv_file_name != NULL)
1262  last_csv_file_name = csvfilename;
1263  csvfilename = NULL;
1264  }
1265 
1266  if (filename)
1267  pfree(filename);
1268  if (csvfilename)
1269  pfree(csvfilename);
1270 
1272 }
1273 
1274 
1275 /*
1276  * construct logfile name using timestamp information
1277  *
1278  * If suffix isn't NULL, append it to the name, replacing any ".log"
1279  * that may be in the pattern.
1280  *
1281  * Result is palloc'd.
1282  */
1283 static char *
1285 {
1286  char *filename;
1287  int len;
1288 
1289  filename = palloc(MAXPGPATH);
1290 
1291  snprintf(filename, MAXPGPATH, "%s/", Log_directory);
1292 
1293  len = strlen(filename);
1294 
1295  /* treat Log_filename as a strftime pattern */
1296  pg_strftime(filename + len, MAXPGPATH - len, Log_filename,
1297  pg_localtime(&timestamp, log_timezone));
1298 
1299  if (suffix != NULL)
1300  {
1301  len = strlen(filename);
1302  if (len > 4 && (strcmp(filename + (len - 4), ".log") == 0))
1303  len -= 4;
1304  strlcpy(filename + len, suffix, MAXPGPATH - len);
1305  }
1306 
1307  return filename;
1308 }
1309 
1310 /*
1311  * Determine the next planned rotation time, and store in next_rotation_time.
1312  */
1313 static void
1315 {
1316  pg_time_t now;
1317  struct pg_tm *tm;
1318  int rotinterval;
1319 
1320  /* nothing to do if time-based rotation is disabled */
1321  if (Log_RotationAge <= 0)
1322  return;
1323 
1324  /*
1325  * The requirements here are to choose the next time > now that is a
1326  * "multiple" of the log rotation interval. "Multiple" can be interpreted
1327  * fairly loosely. In this version we align to log_timezone rather than
1328  * GMT.
1329  */
1330  rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
1331  now = (pg_time_t) time(NULL);
1332  tm = pg_localtime(&now, log_timezone);
1333  now += tm->tm_gmtoff;
1334  now -= now % rotinterval;
1335  now += rotinterval;
1336  now -= tm->tm_gmtoff;
1338 }
1339 
1340 /* --------------------------------
1341  * signal handler routines
1342  * --------------------------------
1343  */
1344 
1345 /* SIGHUP: set flag to reload config file */
1346 static void
1348 {
1349  int save_errno = errno;
1350 
1351  got_SIGHUP = true;
1352  SetLatch(MyLatch);
1353 
1354  errno = save_errno;
1355 }
1356 
1357 /* SIGUSR1: set flag to rotate logfile */
1358 static void
1360 {
1361  int save_errno = errno;
1362 
1363  rotation_requested = true;
1364  SetLatch(MyLatch);
1365 
1366  errno = save_errno;
1367 }
NON_EXEC_STATIC void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: syslogger.c:156
#define PIPE_HEADER_SIZE
Definition: syslogger.h:60
size_t pg_strftime(char *s, size_t max, const char *format, const struct pg_tm *tm)
Definition: strftime.c:124
static void logfile_rotate(bool time_based_rotation, int size_rotation_for)
Definition: syslogger.c:1151
static pg_time_t next_rotation_time
Definition: syslogger.c:81
#define SIGUSR1
Definition: win32.h:211
void write_syslogger_file(const char *buffer, int count, int destination)
Definition: syslogger.c:986
int32 pid
Definition: syslogger.c:103
char nuls[2]
Definition: syslogger.h:46
#define DEBUG1
Definition: elog.h:25
int errhint(const char *fmt,...)
Definition: elog.c:987
#define SIGCONT
Definition: win32.h:205
int64 pg_time_t
Definition: pgtime.h:23
char * Log_directory
Definition: syslogger.c:66
#define WL_TIMEOUT
Definition: latch.h:127
void ProcessConfigFile(GucContext context)
static void error(void)
Definition: sql-dyntest.c:147
void InitPostmasterChild(void)
Definition: miscinit.c:175
pid_t fork_process(void)
Definition: fork_process.c:31
#define READ_BUF_SIZE
Definition: syslogger.c:56
#define SIGWINCH
Definition: win32.h:209
#define mkdir(a, b)
Definition: win32.h:65
char * pstrdup(const char *in)
Definition: mcxt.c:1165
static FILE * csvlogFile
Definition: syslogger.c:85
#define PIPE_MAX_PAYLOAD
Definition: syslogger.h:61
pg_time_t MyStartTime
Definition: globals.c:39
#define SIGTTIN
Definition: win32.h:207
#define write_stderr(str)
Definition: parallel.c:182
static void sigHupHandler(SIGNAL_ARGS)
Definition: syslogger.c:1347
void proc_exit(int code)
Definition: ipc.c:99
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define WL_SOCKET_READABLE
Definition: latch.h:125
static void open_csvlogfile(void)
Definition: syslogger.c:1089
static FILE * logfile
Definition: pg_regress.c:97
int SysLogger_Start(void)
Definition: syslogger.c:511
#define lengthof(array)
Definition: c.h:557
long int tm_gmtoff
Definition: pgtime.h:36
#define pg_attribute_noreturn()
Definition: c.h:648
Definition: pgtime.h:25
void ResetLatch(volatile Latch *latch)
Definition: latch.c:462
static void set_next_rotation_time(void)
Definition: syslogger.c:1314
#define LOG
Definition: elog.h:26
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:2414
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define SIGQUIT
Definition: win32.h:197
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:768
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
#define MINS_PER_HOUR
Definition: timestamp.h:101
signed int int32
Definition: c.h:253
bool Logging_collector
Definition: syslogger.c:63
static struct pg_tm tm
Definition: localtime.c:103
pg_tz * log_timezone
Definition: pgtz.c:30
int Log_RotationSize
Definition: syslogger.c:65
bool redirection_done
Definition: postmaster.c:351
int Log_file_mode
Definition: syslogger.c:69
static char * last_file_name
Definition: syslogger.c:87
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:301
void pfree(void *pointer)
Definition: mcxt.c:992
#define NBUFFER_LISTS
Definition: syslogger.c:107
#define SIG_IGN
Definition: win32.h:193
#define FATAL
Definition: elog.h:52
#define MAXPGPATH
static void sigUsr1Handler(SIGNAL_ARGS)
Definition: syslogger.c:1359
bool am_syslogger
Definition: syslogger.c:74
static char * logfile_getname(pg_time_t timestamp, const char *suffix)
Definition: syslogger.c:1284
static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition: syslogger.c:784
static bool rotation_disabled
Definition: syslogger.c:83
static char * buf
Definition: pg_test_fsync.c:65
#define HOURS_PER_DAY
Definition: timestamp.h:90
#define memmove(d, s, c)
Definition: c.h:1057
#define SECS_PER_MINUTE
Definition: timestamp.h:100
int errcode_for_file_access(void)
Definition: elog.c:598
Definition: type.h:125
sigset_t UnBlockSig
Definition: pqsignal.c:22
#define DEVNULL
Definition: port.h:116
#define ereport(elevel, rest)
Definition: elog.h:122
static char * last_csv_file_name
Definition: syslogger.c:88
int errcode_for_socket_access(void)
Definition: elog.c:669
Definition: guc.h:72
static List * buffer_lists[NBUFFER_LISTS]
Definition: syslogger.c:108
List * lappend(List *list, void *datum)
Definition: list.c:128
StringInfoData data
Definition: syslogger.c:104
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
struct @18::@19 av[32]
#define EINTR
Definition: win32.h:295
#define PG_IOLBF
Definition: port.h:340
#define SIGPIPE
Definition: win32.h:201
#define S_IRWXO
Definition: win32.h:484
#define SIGHUP
Definition: win32.h:196
#define LOG_DESTINATION_CSVLOG
Definition: elog.h:398
#define LOG_DESTINATION_STDERR
Definition: elog.h:395
#define SIG_DFL
Definition: win32.h:191
int Log_RotationAge
Definition: syslogger.c:64
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:168
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static volatile sig_atomic_t got_SIGHUP
Definition: syslogger.c:125
void SetLatch(volatile Latch *latch)
Definition: latch.c:380
#define SIGNAL_ARGS
Definition: c.h:1078
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
int WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, long timeout, uint32 wait_event_info)
Definition: latch.c:321
void _dosmaperr(unsigned long)
Definition: win32error.c:171
NON_EXEC_STATIC pg_time_t first_syslogger_file_time
Definition: syslogger.c:86
void dsm_detach_all(void)
Definition: dsm.c:655
double timestamp
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1254
static FILE * syslogFile
Definition: syslogger.c:84
char * Log_filename
Definition: syslogger.c:67
#define S_IRWXG
Definition: win32.h:480
#define SIGTTOU
Definition: win32.h:208
static bool pipe_eof_seen
Definition: syslogger.c:82
static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition: syslogger.c:935
static char * filename
Definition: pg_dumpall.c:84
tuple list
Definition: sort-test.py:11
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
static FILE * logfile_open(const char *filename, const char *mode, bool allow_errors)
Definition: syslogger.c:1111
bool Log_truncate_on_rotation
Definition: syslogger.c:68
int i
const char * strerror(int errnum)
Definition: strerror.c:19
void * arg
struct Latch * MyLatch
Definition: globals.c:51
#define TRUE
Definition: c.h:214
#define elog
Definition: elog.h:219
#define close(a)
Definition: win32.h:17
#define SIGCHLD
Definition: win32.h:206
static volatile sig_atomic_t rotation_requested
Definition: syslogger.c:126
typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess
Definition: pg_list.h:45
#define WL_LATCH_SET
Definition: latch.h:124
#define SIGALRM
Definition: win32.h:202
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:240
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1652
#define read(a, b, c)
Definition: win32.h:18
#define SIGUSR2
Definition: win32.h:212
#define offsetof(type, field)
Definition: c.h:550
void init_ps_display(const char *username, const char *dbname, const char *host_info, const char *initial_str)
Definition: ps_status.c:244
#define NON_EXEC_STATIC
Definition: c.h:1120
int syslogPipe[2]
Definition: syslogger.c:112