From: Heiko Schlittermann (HS12-RIPE) Date: Fri, 4 Nov 2016 13:26:35 +0000 (+0100) Subject: Add syslog_pid option. X-Git-Tag: exim-4_88_RC4~7 X-Git-Url: https://git.exim.org/users/heiko/exim.git/commitdiff_plain/2333e06f406b5d66068cef3e20ab223fc6650307?ds=sidebyside;hp=0df394b5d5e6865094f601baf2a71f41d1d3ad95 Add syslog_pid option. This option suppresses the PID duplication to syslog. As syslog/systemd add the PID of the logging process automatically. --- diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 478b5e1a4..f9a80558e 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -13593,6 +13593,7 @@ listed in more than one group. .row &%slow_lookup_log%& "control logging of slow DNS lookups" .row &%syslog_duplication%& "controls duplicate log lines on syslog" .row &%syslog_facility%& "set syslog &""facility""& field" +.row &%syslog_pid%& "pid in syslog lines" .row &%syslog_processname%& "set syslog &""ident""& field" .row &%syslog_timestamp%& "timestamp syslog lines" .row &%write_rejectlog%& "control use of message log" @@ -16856,6 +16857,15 @@ If this option is unset, &"mail"& is used. See chapter &<>& for details of Exim's logging. +.option syslog_pid main boolean true +.cindex "syslog" "pid" +If &%syslog_pid%& is set false, the PID on Exim's log lines are +omitted when these lines are sent to syslog. (Syslog normally prefixes +the log lines with the PID of the logging process automatically.) You need +to enable the &`+pid`& log selector item, if you want Exim to write it's PID +into the logs.) See chapter &<>& for details of Exim's logging. + + .option syslog_processname main string &`exim`& .cindex "syslog" "process name; setting" diff --git a/src/src/globals.c b/src/src/globals.c index dcdd6f880..b862015a2 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1384,6 +1384,7 @@ BOOL suppress_local_fixups_default = FALSE; BOOL synchronous_delivery = FALSE; BOOL syslog_duplication = TRUE; int syslog_facility = LOG_MAIL; +BOOL syslog_pid = TRUE; uschar *syslog_processname = US"exim"; BOOL syslog_timestamp = TRUE; uschar *system_filter = NULL; diff --git a/src/src/globals.h b/src/src/globals.h index 3e91c427d..b3747a84a 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -890,6 +890,7 @@ extern BOOL suppress_local_fixups_default; /* former is reset to this; overri extern BOOL synchronous_delivery; /* TRUE if -odi is set */ extern BOOL syslog_duplication; /* FALSE => no duplicate logging */ extern int syslog_facility; /* As defined by Syslog.h */ +extern BOOL syslog_pid; /* TRUE if PID on syslogs */ extern uschar *syslog_processname; /* 'ident' param to openlog() */ extern BOOL syslog_timestamp; /* TRUE if time on syslogs */ extern uschar *system_filter; /* Name of system filter file */ diff --git a/src/src/log.c b/src/src/log.c index 6eb57ca75..081e47bf9 100644 --- a/src/src/log.c +++ b/src/src/log.c @@ -47,6 +47,8 @@ static BOOL path_inspected = FALSE; static int logging_mode = LOG_MODE_FILE; static uschar *file_path = US""; +static size_t pid_position[2]; + /* These should be kept in-step with the private delivery error number definitions in macros.h */ @@ -132,7 +134,7 @@ can get here if there is a failure to open the panic log.) Arguments: priority syslog priority - s the string to be written + s the string to be written, the string may be modified! Returns: nothing */ @@ -146,6 +148,8 @@ int linecount = 0; if (running_in_test_harness) return; if (!syslog_timestamp) s += log_timezone? 26 : 20; +if (!syslog_pid && LOGGING(pid)) + memmove(s + pid_position[0], s + pid_position[1], pid_position[1] - pid_position[0]); len = Ustrlen(s); @@ -905,7 +909,9 @@ while(*ptr) ptr++; if (LOGGING(pid)) { sprintf(CS ptr, "[%d] ", (int)getpid()); + if (!syslog_pid) pid_position[0] = ptr - log_buffer; // remember begin … while (*ptr) ptr++; + if (!syslog_pid) pid_position[1] = ptr - log_buffer; // … and end+1 of the PID } if (really_exim && message_id[0] != 0) diff --git a/src/src/readconf.c b/src/src/readconf.c index 9cbad8474..27a834b3f 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -445,6 +445,7 @@ static optionlist optionlist_config[] = { { "strip_trailing_dot", opt_bool, &strip_trailing_dot }, { "syslog_duplication", opt_bool, &syslog_duplication }, { "syslog_facility", opt_stringptr, &syslog_facility_str }, + { "syslog_pid", opt_bool, &syslog_pid }, { "syslog_processname", opt_stringptr, &syslog_processname }, { "syslog_timestamp", opt_bool, &syslog_timestamp }, { "system_filter", opt_stringptr, &system_filter }, diff --git a/test/confs/0001 b/test/confs/0001 index 1eb0e884c..b0f8f61e3 100644 --- a/test/confs/0001 +++ b/test/confs/0001 @@ -193,6 +193,7 @@ no_strip_excess_angle_brackets no_strip_trailing_dot no_syslog_duplication syslog_facility = uucp +no_syslog_pid syslog_processname = mta-exim no_syslog_timestamp system_filter = /home/exim/test/filter diff --git a/test/scripts/0000-Basic/0001 b/test/scripts/0000-Basic/0001 index 4b5f282ca..78682571d 100644 --- a/test/scripts/0000-Basic/0001 +++ b/test/scripts/0000-Basic/0001 @@ -26,5 +26,6 @@ exim -bP accept_8bitmime \ tcp_nodelay \ trusted_users \ unknown_login \ - warn_message_file + warn_message_file \ + syslog_pid **** diff --git a/test/stdout/0001 b/test/stdout/0001 index d9ce2f07b..9238c91fe 100644 --- a/test/stdout/0001 +++ b/test/stdout/0001 @@ -20,3 +20,4 @@ no_tcp_nodelay trusted_users = 1234:5678 unknown_login = unknownlogin warn_message_file = /home/exim/test/warnmsg_file +no_syslog_pid