aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-03 12:13:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-03 12:13:42 +0000
commit4dada747e54b11f05db1beda3f4653ffe432255c (patch)
treea2901f06d7aad6b438befcd2b9f749fe19bb9fe5
parent4f2e8bc7656ff64402329de5364ec4502d8007d9 (diff)
downloadbusybox-w32-4dada747e54b11f05db1beda3f4653ffe432255c.tar.gz
busybox-w32-4dada747e54b11f05db1beda3f4653ffe432255c.tar.bz2
busybox-w32-4dada747e54b11f05db1beda3f4653ffe432255c.zip
syslogd: avoid excessive tine() system calls
function old new delta timestamp_and_log_internal - 24 +24 log_locally 741 744 +3 timestamp_and_log 313 314 +1 syslogd_main 904 897 -7 quit_signal 101 94 -7 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 28/-14) Total: 14 bytes
-rw-r--r--sysklogd/syslogd.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 7000e9301..f8e8488fb 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -285,7 +285,7 @@ void log_to_shmem(const char *msg);
285 285
286 286
287/* Print a message to the log file. */ 287/* Print a message to the log file. */
288static void log_locally(char *msg) 288static void log_locally(time_t now, char *msg)
289{ 289{
290 struct flock fl; 290 struct flock fl;
291 int len = strlen(msg); 291 int len = strlen(msg);
@@ -297,10 +297,10 @@ static void log_locally(char *msg)
297 } 297 }
298#endif 298#endif
299 if (G.logFD >= 0) { 299 if (G.logFD >= 0) {
300 time_t cur; 300 if (!now)
301 time(&cur); 301 now = time(NULL);
302 if (G.last_log_time != cur) { 302 if (G.last_log_time != now) {
303 G.last_log_time = cur; /* reopen log file every second */ 303 G.last_log_time = now; /* reopen log file every second */
304 close(G.logFD); 304 close(G.logFD);
305 goto reopen; 305 goto reopen;
306 } 306 }
@@ -397,23 +397,20 @@ static void parse_fac_prio_20(int pri, char *res20)
397static void timestamp_and_log(int pri, char *msg, int len) 397static void timestamp_and_log(int pri, char *msg, int len)
398{ 398{
399 char *timestamp; 399 char *timestamp;
400 400 time_t now;
401 if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_locallog))
402 return;
403 401
404 if (len < 16 || msg[3] != ' ' || msg[6] != ' ' 402 if (len < 16 || msg[3] != ' ' || msg[6] != ' '
405 || msg[9] != ':' || msg[12] != ':' || msg[15] != ' ' 403 || msg[9] != ':' || msg[12] != ':' || msg[15] != ' '
406 ) { 404 ) {
407 time_t now;
408 time(&now); 405 time(&now);
409 timestamp = ctime(&now) + 4; 406 timestamp = ctime(&now) + 4; /* skip day of week */
410 } else { 407 } else {
408 now = 0;
411 timestamp = msg; 409 timestamp = msg;
412 msg += 16; 410 msg += 16;
413 } 411 }
414 timestamp[15] = '\0'; 412 timestamp[15] = '\0';
415 413
416 /* Log message locally (to file or shared mem) */
417 if (option_mask32 & OPT_small) 414 if (option_mask32 & OPT_small)
418 sprintf(G.printbuf, "%s %s\n", timestamp, msg); 415 sprintf(G.printbuf, "%s %s\n", timestamp, msg);
419 else { 416 else {
@@ -421,7 +418,16 @@ static void timestamp_and_log(int pri, char *msg, int len)
421 parse_fac_prio_20(pri, res); 418 parse_fac_prio_20(pri, res);
422 sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg); 419 sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg);
423 } 420 }
424 log_locally(G.printbuf); 421
422 /* Log message locally (to file or shared mem) */
423 log_locally(now, G.printbuf);
424}
425
426static void timestamp_and_log_internal(const char *msg)
427{
428 if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_locallog))
429 return;
430 timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)msg, 0);
425} 431}
426 432
427static void split_escape_and_log(char *tmpbuf, int len) 433static void split_escape_and_log(char *tmpbuf, int len)
@@ -462,7 +468,7 @@ static void split_escape_and_log(char *tmpbuf, int len)
462 468
463static void quit_signal(int sig) 469static void quit_signal(int sig)
464{ 470{
465 timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); 471 timestamp_and_log_internal("syslogd exiting");
466 puts("syslogd exiting"); 472 puts("syslogd exiting");
467 if (ENABLE_FEATURE_IPC_SYSLOG) 473 if (ENABLE_FEATURE_IPC_SYSLOG)
468 ipcsyslog_cleanup(); 474 ipcsyslog_cleanup();
@@ -473,7 +479,7 @@ static void quit_signal(int sig)
473static void do_mark(int sig) 479static void do_mark(int sig)
474{ 480{
475 if (G.markInterval) { 481 if (G.markInterval) {
476 timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"-- MARK --", 0); 482 timestamp_and_log_internal("-- MARK --");
477 alarm(G.markInterval); 483 alarm(G.markInterval);
478 } 484 }
479} 485}
@@ -546,8 +552,7 @@ static void do_syslogd(void)
546 ipcsyslog_init(); 552 ipcsyslog_init();
547 } 553 }
548 554
549 timestamp_and_log(LOG_SYSLOG | LOG_INFO, 555 timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER);
550 (char*)"syslogd started: BusyBox v" BB_VER, 0);
551 556
552 for (;;) { 557 for (;;) {
553 size_t sz; 558 size_t sz;