diff options
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/klogd.c | 15 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 25 |
2 files changed, 26 insertions, 14 deletions
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 728cc8d38..25ddf3172 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -53,7 +53,7 @@ | |||
53 | //usage:#define klogd_trivial_usage | 53 | //usage:#define klogd_trivial_usage |
54 | //usage: "[-c N] [-n]" | 54 | //usage: "[-c N] [-n]" |
55 | //usage:#define klogd_full_usage "\n\n" | 55 | //usage:#define klogd_full_usage "\n\n" |
56 | //usage: "Kernel logger\n" | 56 | //usage: "Log kernel messages to syslog\n" |
57 | //usage: "\n -c N Print to console messages more urgent than prio N (1-8)" | 57 | //usage: "\n -c N Print to console messages more urgent than prio N (1-8)" |
58 | //usage: "\n -n Run in foreground" | 58 | //usage: "\n -n Run in foreground" |
59 | 59 | ||
@@ -85,6 +85,7 @@ static void klogd_setloglevel(int lvl) | |||
85 | 85 | ||
86 | static int klogd_read(char *bufp, int len) | 86 | static int klogd_read(char *bufp, int len) |
87 | { | 87 | { |
88 | /* "2 -- Read from the log." */ | ||
88 | return klogctl(2, bufp, len); | 89 | return klogctl(2, bufp, len); |
89 | } | 90 | } |
90 | # define READ_ERROR "klogctl(2) error" | 91 | # define READ_ERROR "klogctl(2) error" |
@@ -238,7 +239,6 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
238 | int priority; | 239 | int priority; |
239 | char *start; | 240 | char *start; |
240 | 241 | ||
241 | /* "2 -- Read from the log." */ | ||
242 | start = log_buffer + used; | 242 | start = log_buffer + used; |
243 | n = klogd_read(start, KLOGD_LOGBUF_SIZE-1 - used); | 243 | n = klogd_read(start, KLOGD_LOGBUF_SIZE-1 - used); |
244 | if (n < 0) { | 244 | if (n < 0) { |
@@ -275,10 +275,13 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
275 | priority = LOG_INFO; | 275 | priority = LOG_INFO; |
276 | if (*start == '<') { | 276 | if (*start == '<') { |
277 | start++; | 277 | start++; |
278 | if (*start) | 278 | if (*start) { |
279 | priority = strtoul(start, &start, 10); | 279 | char *end; |
280 | if (*start == '>') | 280 | priority = strtoul(start, &end, 10); |
281 | start++; | 281 | if (*end == '>') |
282 | end++; | ||
283 | start = end; | ||
284 | } | ||
282 | } | 285 | } |
283 | /* Log (only non-empty lines) */ | 286 | /* Log (only non-empty lines) */ |
284 | if (*start) | 287 | if (*start) |
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. */ |
814 | static void timestamp_and_log(int pri, char *msg, int len) | 817 | static 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) { |