codekingpro/portable-devtools
115k
1/*-------------------------------------------------------------------------2 *3 * syslogger.h4 * Exports from postmaster/syslogger.c.5 *6 * Copyright (c) 2004-2023, PostgreSQL Global Development Group7 *8 * src/include/postmaster/syslogger.h9 *10 *-------------------------------------------------------------------------11 */12#ifndef _SYSLOGGER_H13#define _SYSLOGGER_H14 15#include <limits.h> /* for PIPE_BUF */16 17 18/*19 * Primitive protocol structure for writing to syslogger pipe(s). The idea20 * here is to divide long messages into chunks that are not more than21 * PIPE_BUF bytes long, which according to POSIX spec must be written into22 * the pipe atomically. The pipe reader then uses the protocol headers to23 * reassemble the parts of a message into a single string. The reader can24 * also cope with non-protocol data coming down the pipe, though we cannot25 * guarantee long strings won't get split apart.26 *27 * We use non-nul bytes in is_last to make the protocol a tiny bit28 * more robust against finding a false double nul byte prologue. But29 * we still might find it in the len and/or pid bytes unless we're careful.30 */31 32#ifdef PIPE_BUF33/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */34#if PIPE_BUF > 6553635#define PIPE_CHUNK_SIZE 6553636#else37#define PIPE_CHUNK_SIZE ((int) PIPE_BUF)38#endif39#else /* not defined */40/* POSIX says the value of PIPE_BUF must be at least 512, so use that */41#define PIPE_CHUNK_SIZE 51242#endif43 44typedef struct45{46 char nuls[2]; /* always \0\0 */47 uint16 len; /* size of this chunk (counts data only) */48 int32 pid; /* writer's pid */49 bits8 flags; /* bitmask of PIPE_PROTO_* */50 char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */51} PipeProtoHeader;52 53typedef union54{55 PipeProtoHeader proto;56 char filler[PIPE_CHUNK_SIZE];57} PipeProtoChunk;58 59#define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data)60#define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE))61 62/* flag bits for PipeProtoHeader->flags */63#define PIPE_PROTO_IS_LAST 0x01 /* last chunk of message? */64/* log destinations */65#define PIPE_PROTO_DEST_STDERR 0x1066#define PIPE_PROTO_DEST_CSVLOG 0x2067#define PIPE_PROTO_DEST_JSONLOG 0x4068 69/* GUC options */70extern PGDLLIMPORT bool Logging_collector;71extern PGDLLIMPORT int Log_RotationAge;72extern PGDLLIMPORT int Log_RotationSize;73extern PGDLLIMPORT char *Log_directory;74extern PGDLLIMPORT char *Log_filename;75extern PGDLLIMPORT bool Log_truncate_on_rotation;76extern PGDLLIMPORT int Log_file_mode;77 78#ifndef WIN3279extern PGDLLIMPORT int syslogPipe[2];80#else81extern PGDLLIMPORT HANDLE syslogPipe[2];82#endif83 84 85extern int SysLogger_Start(void);86 87extern void write_syslogger_file(const char *buffer, int count, int destination);88 89#ifdef EXEC_BACKEND90extern void SysLoggerMain(int argc, char *argv[]) pg_attribute_noreturn();91#endif92 93extern bool CheckLogrotateSignal(void);94extern void RemoveLogrotateSignalFiles(void);95 96/*97 * Name of files saving meta-data information about the log98 * files currently in use by the syslogger99 */100#define LOG_METAINFO_DATAFILE "current_logfiles"101#define LOG_METAINFO_DATAFILE_TMP LOG_METAINFO_DATAFILE ".tmp"102 103#endif /* _SYSLOGGER_H */104 