PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include "common/file_perm.h"
#include "lib/stringinfo.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "nodes/pg_list.h"
#include "pgstat.h"
#include "pgtime.h"
#include "postmaster/fork_process.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "storage/dsm.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/pg_shmem.h"
#include "tcop/tcopprot.h"
#include "utils/guc.h"
#include "utils/ps_status.h"
#include "utils/timestamp.h"
Go to the source code of this file.
Data Structures | |
struct | save_buffer |
Macros | |
#define | READ_BUF_SIZE (2 * PIPE_CHUNK_SIZE) |
#define | LOGROTATE_SIGNAL_FILE "logrotate" |
#define | NBUFFER_LISTS 256 |
Functions | |
NON_EXEC_STATIC void | SysLoggerMain (int argc, char *argv[]) pg_attribute_noreturn() |
static void | process_pipe_input (char *logbuffer, int *bytes_in_logbuffer) |
static void | flush_pipe_input (char *logbuffer, int *bytes_in_logbuffer) |
static FILE * | logfile_open (const char *filename, const char *mode, bool allow_errors) |
static void | logfile_rotate (bool time_based_rotation, int size_rotation_for) |
static char * | logfile_getname (pg_time_t timestamp, const char *suffix) |
static void | set_next_rotation_time (void) |
static void | sigHupHandler (SIGNAL_ARGS) |
static void | sigUsr1Handler (SIGNAL_ARGS) |
static void | update_metainfo_datafile (void) |
int | SysLogger_Start (void) |
void | write_syslogger_file (const char *buffer, int count, int destination) |
bool | CheckLogrotateSignal (void) |
void | RemoveLogrotateSignalFiles (void) |
Variables | |
bool | Logging_collector = false |
int | Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR |
int | Log_RotationSize = 10 * 1024 |
char * | Log_directory = NULL |
char * | Log_filename = NULL |
bool | Log_truncate_on_rotation = false |
int | Log_file_mode = S_IRUSR | S_IWUSR |
bool | am_syslogger = false |
bool | redirection_done |
static pg_time_t | next_rotation_time |
static bool | pipe_eof_seen = false |
static bool | rotation_disabled = false |
static FILE * | syslogFile = NULL |
static FILE * | csvlogFile = NULL |
NON_EXEC_STATIC pg_time_t | first_syslogger_file_time = 0 |
static char * | last_file_name = NULL |
static char * | last_csv_file_name = NULL |
static List * | buffer_lists [NBUFFER_LISTS] |
int | syslogPipe [2] = {-1, -1} |
static volatile sig_atomic_t | got_SIGHUP = false |
static volatile sig_atomic_t | rotation_requested = false |
#define LOGROTATE_SIGNAL_FILE "logrotate" |
Definition at line 62 of file syslogger.c.
Referenced by CheckLogrotateSignal(), and RemoveLogrotateSignalFiles().
#define NBUFFER_LISTS 256 |
Definition at line 113 of file syslogger.c.
Referenced by flush_pipe_input(), and process_pipe_input().
#define READ_BUF_SIZE (2 * PIPE_CHUNK_SIZE) |
Definition at line 59 of file syslogger.c.
Referenced by SysLoggerMain(), and write_syslogger_file().
bool CheckLogrotateSignal | ( | void | ) |
Definition at line 1538 of file syslogger.c.
References LOGROTATE_SIGNAL_FILE, and stat.
Referenced by sigusr1_handler().
|
static |
Definition at line 1029 of file syslogger.c.
References buf, StringInfoData::data, save_buffer::data, i, StringInfoData::len, lfirst, sort-test::list, LOG_DESTINATION_STDERR, NBUFFER_LISTS, pfree(), save_buffer::pid, generate_unaccent_rules::str, and write_syslogger_file().
Referenced by SysLoggerMain(), and write_syslogger_file().
|
static |
Definition at line 1390 of file syslogger.c.
References filename, Log_directory, Log_filename, log_timezone, MAXPGPATH, palloc(), pg_localtime(), pg_strftime(), snprintf, and strlcpy().
Referenced by logfile_rotate(), SysLogger_Start(), and SysLoggerMain().
|
static |
Definition at line 1198 of file syslogger.c.
References ereport, errcode_for_file_access(), errmsg(), FATAL, LOG, Log_file_mode, PG_IOLBF, S_IRWXG, S_IRWXO, S_IRWXU, and S_IWUSR.
Referenced by logfile_rotate(), and SysLogger_Start().
|
static |
Definition at line 1238 of file syslogger.c.
References csvlogFile, ereport, errmsg(), filename, last_csv_file_name, last_file_name, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_STDERR, Log_truncate_on_rotation, logfile_getname(), logfile_open(), next_rotation_time, pfree(), rotation_disabled, rotation_requested, set_next_rotation_time(), syslogFile, and update_metainfo_datafile().
Referenced by SysLoggerMain().
|
static |
Definition at line 878 of file syslogger.c.
References appendBinaryStringInfo(), buf, StringInfoData::data, save_buffer::data, generate_unaccent_rules::dest, initStringInfo(), PipeProtoHeader::is_last, lappend(), StringInfoData::len, PipeProtoHeader::len, lfirst, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_STDERR, memmove, NBUFFER_LISTS, PipeProtoHeader::nuls, offsetof, palloc(), pfree(), PipeProtoHeader::pid, save_buffer::pid, PIPE_HEADER_SIZE, PIPE_MAX_PAYLOAD, generate_unaccent_rules::str, and write_syslogger_file().
Referenced by SysLoggerMain(), and write_syslogger_file().
void RemoveLogrotateSignalFiles | ( | void | ) |
Definition at line 1552 of file syslogger.c.
References LOGROTATE_SIGNAL_FILE.
Referenced by PostmasterMain(), and sigusr1_handler().
|
static |
Definition at line 1420 of file syslogger.c.
References Log_RotationAge, log_timezone, next_rotation_time, now(), pg_localtime(), SECS_PER_MINUTE, tm, and pg_tm::tm_gmtoff.
Referenced by logfile_rotate(), and SysLoggerMain().
|
static |
Definition at line 1559 of file syslogger.c.
References got_SIGHUP, MyLatch, and SetLatch().
Referenced by SysLoggerMain().
|
static |
Definition at line 1571 of file syslogger.c.
References MyLatch, rotation_requested, and SetLatch().
Referenced by SysLoggerMain().
int SysLogger_Start | ( | void | ) |
Definition at line 546 of file syslogger.c.
References Assert, av, close, ClosePostmasterPorts(), csvlogFile, dsm_detach_all(), ereport, errcode_for_file_access(), errcode_for_socket_access(), errhint(), errmsg(), FATAL, fd(), filename, first_syslogger_file_time, fork_process(), InitPostmasterChild(), lengthof, LOG, Log_destination, LOG_DESTINATION_CSVLOG, Log_directory, logfile_getname(), logfile_open(), Logging_collector, MakePGDirectory(), pfree(), PG_IOLBF, PGSharedMemoryDetach(), redirection_done, snprintf, generate_unaccent_rules::stdout, syslogFile, SysLoggerMain(), and syslogPipe.
Referenced by PostmasterMain(), reaper(), and ServerLoop().
NON_EXEC_STATIC void SysLoggerMain | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 162 of file syslogger.c.
References AddWaitEventToSet(), am_syslogger, close, CreateWaitEventSet(), csvlogFile, CurrentMemoryContext, DEBUG1, DestNone, DEVNULL, EINTR, elog, ereport, errcode_for_socket_access(), errmsg(), WaitEvent::events, FATAL, fd(), first_syslogger_file_time, flush_pipe_input(), got_SIGHUP, init_ps_display(), last_csv_file_name, last_file_name, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_STDERR, Log_directory, Log_filename, Log_RotationAge, Log_RotationSize, logfile_getname(), logfile_rotate(), MakePGDirectory(), MyLatch, MyStartTime, next_rotation_time, now(), pfree(), PG_SETMASK, PGC_SIGHUP, PGINVALID_SOCKET, pipe_eof_seen, pqsignal(), proc_exit(), process_pipe_input(), ProcessConfigFile(), pstrdup(), read, READ_BUF_SIZE, redirection_done, ResetLatch(), rotation_disabled, rotation_requested, set_next_rotation_time(), SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, sigHupHandler(), SIGPIPE, SIGQUIT, SIGUSR1, sigUsr1Handler(), SIGUSR2, generate_unaccent_rules::stdout, syslogFile, syslogPipe, UnBlockSig, update_metainfo_datafile(), WAIT_EVENT_SYSLOGGER_MAIN, WaitEventSetWait(), whereToSendOutput, WL_LATCH_SET, and WL_SOCKET_READABLE.
Referenced by BackendRun(), and SysLogger_Start().
|
static |
Definition at line 1455 of file syslogger.c.
References ereport, errcode_for_file_access(), errmsg(), fprintf, last_csv_file_name, last_file_name, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_STDERR, LOG_METAINFO_DATAFILE, LOG_METAINFO_DATAFILE_TMP, PG_IOLBF, and pg_mode_mask.
Referenced by logfile_rotate(), and SysLoggerMain().
void write_syslogger_file | ( | const char * | buffer, |
int | count, | ||
int | destination | ||
) |
Definition at line 1080 of file syslogger.c.
References _dosmaperr(), arg, csvlogFile, ereport, errcode_for_file_access(), errmsg(), error(), flush_pipe_input(), LOG, LOG_DESTINATION_CSVLOG, Log_RotationSize, logfile, MyLatch, pipe_eof_seen, process_pipe_input(), READ_BUF_SIZE, SetLatch(), strerror, syslogFile, syslogPipe, and write_stderr.
Referenced by flush_pipe_input(), process_pipe_input(), send_message_to_server_log(), and write_csvlog().
Definition at line 80 of file syslogger.c.
Referenced by send_message_to_server_log(), SysLoggerMain(), and write_csvlog().
|
static |
Definition at line 114 of file syslogger.c.
|
static |
Definition at line 91 of file syslogger.c.
Referenced by logfile_rotate(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().
NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0 |
Definition at line 92 of file syslogger.c.
Referenced by PostmasterMarkPIDForWorkerNotify(), SysLogger_Start(), and SysLoggerMain().
|
static |
Definition at line 131 of file syslogger.c.
Referenced by sigHupHandler(), and SysLoggerMain().
|
static |
Definition at line 94 of file syslogger.c.
Referenced by logfile_rotate(), SysLoggerMain(), and update_metainfo_datafile().
|
static |
Definition at line 93 of file syslogger.c.
Referenced by logfile_rotate(), SysLoggerMain(), and update_metainfo_datafile().
char* Log_directory = NULL |
Definition at line 72 of file syslogger.c.
Referenced by convert_and_check_filename(), logfile_getname(), pg_logdir_ls_internal(), pg_ls_logdir(), SysLogger_Start(), and SysLoggerMain().
Definition at line 75 of file syslogger.c.
Referenced by logfile_open(), and show_log_file_mode().
char* Log_filename = NULL |
Definition at line 73 of file syslogger.c.
Referenced by logfile_getname(), pg_logdir_ls_internal(), and SysLoggerMain().
int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR |
Definition at line 70 of file syslogger.c.
Referenced by set_next_rotation_time(), and SysLoggerMain().
int Log_RotationSize = 10 * 1024 |
Definition at line 71 of file syslogger.c.
Referenced by SysLoggerMain(), and write_syslogger_file().
Definition at line 74 of file syslogger.c.
Referenced by logfile_rotate().
Definition at line 69 of file syslogger.c.
Referenced by pg_rotate_logfile(), pg_rotate_logfile_v2(), ServerLoop(), and SysLogger_Start().
|
static |
Definition at line 87 of file syslogger.c.
Referenced by logfile_rotate(), set_next_rotation_time(), and SysLoggerMain().
Definition at line 88 of file syslogger.c.
Referenced by SysLoggerMain(), and write_syslogger_file().
bool redirection_done |
Definition at line 355 of file postmaster.c.
Referenced by SysLogger_Start(), and SysLoggerMain().
Definition at line 89 of file syslogger.c.
Referenced by logfile_rotate(), and SysLoggerMain().
|
static |
Definition at line 132 of file syslogger.c.
Referenced by logfile_rotate(), sigUsr1Handler(), and SysLoggerMain().
|
static |
Definition at line 90 of file syslogger.c.
Referenced by logfile_rotate(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().
int syslogPipe[2] = {-1, -1} |
Definition at line 118 of file syslogger.c.
Referenced by ClosePostmasterPorts(), PostmasterMarkPIDForWorkerNotify(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().