00001 /*------------------------------------------------------------------------- 00002 * 00003 * syslogger.h 00004 * Exports from postmaster/syslogger.c. 00005 * 00006 * Copyright (c) 2004-2013, PostgreSQL Global Development Group 00007 * 00008 * src/include/postmaster/syslogger.h 00009 * 00010 *------------------------------------------------------------------------- 00011 */ 00012 #ifndef _SYSLOGGER_H 00013 #define _SYSLOGGER_H 00014 00015 #include <limits.h> /* for PIPE_BUF */ 00016 00017 00018 /* 00019 * Primitive protocol structure for writing to syslogger pipe(s). The idea 00020 * here is to divide long messages into chunks that are not more than 00021 * PIPE_BUF bytes long, which according to POSIX spec must be written into 00022 * the pipe atomically. The pipe reader then uses the protocol headers to 00023 * reassemble the parts of a message into a single string. The reader can 00024 * also cope with non-protocol data coming down the pipe, though we cannot 00025 * guarantee long strings won't get split apart. 00026 * 00027 * We use non-nul bytes in is_last to make the protocol a tiny bit 00028 * more robust against finding a false double nul byte prologue. But 00029 * we still might find it in the len and/or pid bytes unless we're careful. 00030 */ 00031 00032 #ifdef PIPE_BUF 00033 /* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */ 00034 #if PIPE_BUF > 65536 00035 #define PIPE_CHUNK_SIZE 65536 00036 #else 00037 #define PIPE_CHUNK_SIZE ((int) PIPE_BUF) 00038 #endif 00039 #else /* not defined */ 00040 /* POSIX says the value of PIPE_BUF must be at least 512, so use that */ 00041 #define PIPE_CHUNK_SIZE 512 00042 #endif 00043 00044 typedef struct 00045 { 00046 char nuls[2]; /* always \0\0 */ 00047 uint16 len; /* size of this chunk (counts data only) */ 00048 int32 pid; /* writer's pid */ 00049 char is_last; /* last chunk of message? 't' or 'f' ('T' or 00050 * 'F' for CSV case) */ 00051 char data[1]; /* data payload starts here */ 00052 } PipeProtoHeader; 00053 00054 typedef union 00055 { 00056 PipeProtoHeader proto; 00057 char filler[PIPE_CHUNK_SIZE]; 00058 } PipeProtoChunk; 00059 00060 #define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data) 00061 #define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE)) 00062 00063 00064 /* GUC options */ 00065 extern bool Logging_collector; 00066 extern int Log_RotationAge; 00067 extern int Log_RotationSize; 00068 extern PGDLLIMPORT char *Log_directory; 00069 extern PGDLLIMPORT char *Log_filename; 00070 extern bool Log_truncate_on_rotation; 00071 extern int Log_file_mode; 00072 00073 extern bool am_syslogger; 00074 00075 #ifndef WIN32 00076 extern int syslogPipe[2]; 00077 #else 00078 extern HANDLE syslogPipe[2]; 00079 #endif 00080 00081 00082 extern int SysLogger_Start(void); 00083 00084 extern void write_syslogger_file(const char *buffer, int count, int dest); 00085 00086 #ifdef EXEC_BACKEND 00087 extern void SysLoggerMain(int argc, char *argv[]) __attribute__((noreturn)); 00088 #endif 00089 00090 #endif /* _SYSLOGGER_H */