aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Korsgaard <peter@korsgaard.com>2018-08-09 11:25:22 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-08-26 17:31:21 +0200
commit9d539f9fbd0dc4ea70ed8ba66e3c78150fa8a8b2 (patch)
treef6686f8555301ee56d6fdd4d0c42ec5307178970
parent6791140123ebe7535f525f1a893a8536219122c4 (diff)
downloadbusybox-w32-9d539f9fbd0dc4ea70ed8ba66e3c78150fa8a8b2.tar.gz
busybox-w32-9d539f9fbd0dc4ea70ed8ba66e3c78150fa8a8b2.tar.bz2
busybox-w32-9d539f9fbd0dc4ea70ed8ba66e3c78150fa8a8b2.zip
sysklogd: add timestamp option to ignore message timestamps
Some syslog producers provide inconsistent timestamps, so provide an option to ignore the message timestamps and always locally timestamp. In order to implement this, invert the valid-timestamp check, but only use the timestamp if this option is not enabled. This is in line with what what other syslogd implementations do: From sysklogd syslogd.c: * Sun Nov 7 12:28:47 CET 2004: Martin Schulze <joey@infodrom.org> * Discard any timestamp information found in received syslog * messages. This will affect local messages sent from a * different timezone. rsyslog's imuxsock module similary has an (enabled by default) IgnoreTimestamp option: https://www.rsyslog.com/doc/v8-stable/configuration/modules/imuxsock.html function old new delta packed_usage 32877 32912 +35 timestamp_and_log 363 376 +13 syslogd_main 1638 1641 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 51/0) Total: 51 bytes Signed-off-by: Peter Korsgaard <peter@korsgaard.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--sysklogd/syslogd.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 4265f4f90..5630d97fc 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -140,6 +140,7 @@
140//usage: ) 140//usage: )
141//usage: "\n -l N Log only messages more urgent than prio N (1-8)" 141//usage: "\n -l N Log only messages more urgent than prio N (1-8)"
142//usage: "\n -S Smaller output" 142//usage: "\n -S Smaller output"
143//usage: "\n -t Strip client-generated timestamps"
143//usage: IF_FEATURE_SYSLOGD_DUP( 144//usage: IF_FEATURE_SYSLOGD_DUP(
144//usage: "\n -D Drop duplicates" 145//usage: "\n -D Drop duplicates"
145//usage: ) 146//usage: )
@@ -316,6 +317,7 @@ enum {
316 OPTBIT_outfile, // -O 317 OPTBIT_outfile, // -O
317 OPTBIT_loglevel, // -l 318 OPTBIT_loglevel, // -l
318 OPTBIT_small, // -S 319 OPTBIT_small, // -S
320 OPTBIT_timestamp, // -t
319 IF_FEATURE_ROTATE_LOGFILE(OPTBIT_filesize ,) // -s 321 IF_FEATURE_ROTATE_LOGFILE(OPTBIT_filesize ,) // -s
320 IF_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatecnt ,) // -b 322 IF_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatecnt ,) // -b
321 IF_FEATURE_REMOTE_LOG( OPTBIT_remotelog ,) // -R 323 IF_FEATURE_REMOTE_LOG( OPTBIT_remotelog ,) // -R
@@ -330,6 +332,7 @@ enum {
330 OPT_outfile = 1 << OPTBIT_outfile , 332 OPT_outfile = 1 << OPTBIT_outfile ,
331 OPT_loglevel = 1 << OPTBIT_loglevel, 333 OPT_loglevel = 1 << OPTBIT_loglevel,
332 OPT_small = 1 << OPTBIT_small , 334 OPT_small = 1 << OPTBIT_small ,
335 OPT_timestamp = 1 << OPTBIT_timestamp,
333 OPT_filesize = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_filesize )) + 0, 336 OPT_filesize = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_filesize )) + 0,
334 OPT_rotatecnt = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatecnt )) + 0, 337 OPT_rotatecnt = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatecnt )) + 0,
335 OPT_remotelog = IF_FEATURE_REMOTE_LOG( (1 << OPTBIT_remotelog )) + 0, 338 OPT_remotelog = IF_FEATURE_REMOTE_LOG( (1 << OPTBIT_remotelog )) + 0,
@@ -339,7 +342,7 @@ enum {
339 OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, 342 OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0,
340 OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, 343 OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0,
341}; 344};
342#define OPTION_STR "m:nO:l:S" \ 345#define OPTION_STR "m:nO:l:St" \
343 IF_FEATURE_ROTATE_LOGFILE("s:" ) \ 346 IF_FEATURE_ROTATE_LOGFILE("s:" ) \
344 IF_FEATURE_ROTATE_LOGFILE("b:" ) \ 347 IF_FEATURE_ROTATE_LOGFILE("b:" ) \
345 IF_FEATURE_REMOTE_LOG( "R:*") \ 348 IF_FEATURE_REMOTE_LOG( "R:*") \
@@ -813,21 +816,27 @@ static void parse_fac_prio_20(int pri, char *res20)
813 * that there is no timestamp, short-circuiting the test. */ 816 * that there is no timestamp, short-circuiting the test. */
814static void timestamp_and_log(int pri, char *msg, int len) 817static void timestamp_and_log(int pri, char *msg, int len)
815{ 818{
816 char *timestamp; 819 char *timestamp = NULL;
817 time_t now; 820 time_t now;
818 821
819 /* Jan 18 00:11:22 msg... */ 822 /* Jan 18 00:11:22 msg... */
820 /* 01234567890123456 */ 823 /* 01234567890123456 */
821 if (len < 16 || msg[3] != ' ' || msg[6] != ' ' 824 if (len >= 16 && msg[3] == ' ' && msg[6] == ' '
822 || msg[9] != ':' || msg[12] != ':' || msg[15] != ' ' 825 && msg[9] == ':' && msg[12] == ':' && msg[15] == ' '
823 ) { 826 ) {
827 if (!(option_mask32 & OPT_timestamp)) {
828 /* use message timestamp */
829 timestamp = msg;
830 now = 0;
831 }
832 msg += 16;
833 }
834
835 if (!timestamp) {
824 time(&now); 836 time(&now);
825 timestamp = ctime(&now) + 4; /* skip day of week */ 837 timestamp = ctime(&now) + 4; /* skip day of week */
826 } else {
827 now = 0;
828 timestamp = msg;
829 msg += 16;
830 } 838 }
839
831 timestamp[15] = '\0'; 840 timestamp[15] = '\0';
832 841
833 if (option_mask32 & OPT_kmsg) { 842 if (option_mask32 & OPT_kmsg) {