syslogger.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*-------------------------------------------------------------------------
  2. *
  3. * syslogger.h
  4. * Exports from postmaster/syslogger.c.
  5. *
  6. * Copyright (c) 2004-2022, PostgreSQL Global Development Group
  7. *
  8. * src/include/postmaster/syslogger.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef _SYSLOGGER_H
  13. #define _SYSLOGGER_H
  14. #include <limits.h> /* for PIPE_BUF */
  15. /*
  16. * Primitive protocol structure for writing to syslogger pipe(s). The idea
  17. * here is to divide long messages into chunks that are not more than
  18. * PIPE_BUF bytes long, which according to POSIX spec must be written into
  19. * the pipe atomically. The pipe reader then uses the protocol headers to
  20. * reassemble the parts of a message into a single string. The reader can
  21. * also cope with non-protocol data coming down the pipe, though we cannot
  22. * guarantee long strings won't get split apart.
  23. *
  24. * We use non-nul bytes in is_last to make the protocol a tiny bit
  25. * more robust against finding a false double nul byte prologue. But
  26. * we still might find it in the len and/or pid bytes unless we're careful.
  27. */
  28. #ifdef PIPE_BUF
  29. /* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */
  30. #if PIPE_BUF > 65536
  31. #define PIPE_CHUNK_SIZE 65536
  32. #else
  33. #define PIPE_CHUNK_SIZE ((int) PIPE_BUF)
  34. #endif
  35. #else /* not defined */
  36. /* POSIX says the value of PIPE_BUF must be at least 512, so use that */
  37. #define PIPE_CHUNK_SIZE 512
  38. #endif
  39. typedef struct
  40. {
  41. char nuls[2]; /* always \0\0 */
  42. uint16 len; /* size of this chunk (counts data only) */
  43. int32 pid; /* writer's pid */
  44. bits8 flags; /* bitmask of PIPE_PROTO_* */
  45. char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */
  46. } PipeProtoHeader;
  47. typedef union
  48. {
  49. PipeProtoHeader proto;
  50. char filler[PIPE_CHUNK_SIZE];
  51. } PipeProtoChunk;
  52. #define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data)
  53. #define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE))
  54. /* flag bits for PipeProtoHeader->flags */
  55. #define PIPE_PROTO_IS_LAST 0x01 /* last chunk of message? */
  56. /* log destinations */
  57. #define PIPE_PROTO_DEST_STDERR 0x10
  58. #define PIPE_PROTO_DEST_CSVLOG 0x20
  59. #define PIPE_PROTO_DEST_JSONLOG 0x40
  60. /* GUC options */
  61. extern PGDLLIMPORT bool Logging_collector;
  62. extern PGDLLIMPORT int Log_RotationAge;
  63. extern PGDLLIMPORT int Log_RotationSize;
  64. extern PGDLLIMPORT char *Log_directory;
  65. extern PGDLLIMPORT char *Log_filename;
  66. extern PGDLLIMPORT bool Log_truncate_on_rotation;
  67. extern PGDLLIMPORT int Log_file_mode;
  68. #ifndef WIN32
  69. extern PGDLLIMPORT int syslogPipe[2];
  70. #else
  71. extern PGDLLIMPORT HANDLE syslogPipe[2];
  72. #endif
  73. extern int SysLogger_Start(void);
  74. extern void write_syslogger_file(const char *buffer, int count, int dest);
  75. #ifdef EXEC_BACKEND
  76. extern void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn();
  77. #endif
  78. extern bool CheckLogrotateSignal(void);
  79. extern void RemoveLogrotateSignalFiles(void);
  80. /*
  81. * Name of files saving meta-data information about the log
  82. * files currently in use by the syslogger
  83. */
  84. #define LOG_METAINFO_DATAFILE "current_logfiles"
  85. #define LOG_METAINFO_DATAFILE_TMP LOG_METAINFO_DATAFILE ".tmp"
  86. #endif /* _SYSLOGGER_H */