diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-30 19:21:24 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-30 19:21:24 +0000 |
commit | 02be0f5350fb3b316e864f0484b8998ccce66fdd (patch) | |
tree | 8269ce9d003f5268821a521d21aff3cf081b8ae8 | |
parent | 14c1940255a190143ef003a2a73bcba29e4c3d56 (diff) | |
download | busybox-w32-02be0f5350fb3b316e864f0484b8998ccce66fdd.tar.gz busybox-w32-02be0f5350fb3b316e864f0484b8998ccce66fdd.tar.bz2 busybox-w32-02be0f5350fb3b316e864f0484b8998ccce66fdd.zip |
syslogd: do not retry udp sends (can stall syslogd for extended periods
of time), resolve remote logging host before daemonization
-rw-r--r-- | sysklogd/syslogd.c | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index a28dde6b3..888082924 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -52,12 +52,6 @@ static char LocalHostName[64]; | |||
52 | static int remotefd = -1; | 52 | static int remotefd = -1; |
53 | static struct sockaddr_in remoteaddr; | 53 | static struct sockaddr_in remoteaddr; |
54 | 54 | ||
55 | /* where do we log? */ | ||
56 | static char *RemoteHost; | ||
57 | |||
58 | /* what port to log to? */ | ||
59 | static int RemotePort = 514; | ||
60 | |||
61 | #endif | 55 | #endif |
62 | 56 | ||
63 | /* options */ | 57 | /* options */ |
@@ -375,19 +369,6 @@ static void message(char *fmt, ...) | |||
375 | } | 369 | } |
376 | } | 370 | } |
377 | 371 | ||
378 | #ifdef CONFIG_FEATURE_REMOTE_LOG | ||
379 | static void init_RemoteLog(void) | ||
380 | { | ||
381 | memset(&remoteaddr, 0, sizeof(remoteaddr)); | ||
382 | remotefd = xsocket(AF_INET, SOCK_DGRAM, 0); | ||
383 | remoteaddr.sin_family = AF_INET; | ||
384 | remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; | ||
385 | remoteaddr.sin_port = htons(RemotePort); | ||
386 | } | ||
387 | #else | ||
388 | void init_RemoteLog(void); | ||
389 | #endif | ||
390 | |||
391 | static void logMessage(int pri, char *msg) | 372 | static void logMessage(int pri, char *msg) |
392 | { | 373 | { |
393 | time_t now; | 374 | time_t now; |
@@ -427,24 +408,14 @@ static void logMessage(int pri, char *msg) | |||
427 | char line[MAXLINE + 1]; | 408 | char line[MAXLINE + 1]; |
428 | /* trying connect the socket */ | 409 | /* trying connect the socket */ |
429 | if (-1 == remotefd) { | 410 | if (-1 == remotefd) { |
430 | init_RemoteLog(); | 411 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); |
431 | } | 412 | } |
432 | |||
433 | /* if we have a valid socket, send the message */ | 413 | /* if we have a valid socket, send the message */ |
434 | if (-1 != remotefd) { | 414 | if (-1 != remotefd) { |
435 | now = 1; | ||
436 | snprintf(line, sizeof(line), "<%d>%s", pri, msg); | 415 | snprintf(line, sizeof(line), "<%d>%s", pri, msg); |
437 | 416 | /* send message to remote logger, ignore possible error */ | |
438 | retry: | 417 | sendto(remotefd, line, strlen(line), 0, |
439 | /* send message to remote logger */ | 418 | (struct sockaddr *) &remoteaddr, sizeof(remoteaddr)); |
440 | if ((-1 == sendto(remotefd, line, strlen(line), 0, | ||
441 | (struct sockaddr *) &remoteaddr, | ||
442 | sizeof(remoteaddr))) && (errno == EINTR)) { | ||
443 | /* sleep now seconds and retry (with now * 2) */ | ||
444 | sleep(now); | ||
445 | now *= 2; | ||
446 | goto retry; | ||
447 | } | ||
448 | } | 419 | } |
449 | } | 420 | } |
450 | 421 | ||
@@ -468,7 +439,7 @@ static void quit_signal(int sig) | |||
468 | if (ENABLE_FEATURE_IPC_SYSLOG) | 439 | if (ENABLE_FEATURE_IPC_SYSLOG) |
469 | ipcsyslog_cleanup(); | 440 | ipcsyslog_cleanup(); |
470 | 441 | ||
471 | exit(TRUE); | 442 | exit(1); |
472 | } | 443 | } |
473 | 444 | ||
474 | static void domark(int sig) | 445 | static void domark(int sig) |
@@ -564,10 +535,6 @@ static void doSyslogd(void) | |||
564 | ipcsyslog_init(); | 535 | ipcsyslog_init(); |
565 | } | 536 | } |
566 | 537 | ||
567 | if (ENABLE_FEATURE_REMOTE_LOG && (option_mask & OPT_remotelog)) { | ||
568 | init_RemoteLog(); | ||
569 | } | ||
570 | |||
571 | logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER ); | 538 | logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " "BusyBox v" BB_VER ); |
572 | 539 | ||
573 | for (;;) { | 540 | for (;;) { |
@@ -628,12 +595,18 @@ int syslogd_main(int argc, char **argv) | |||
628 | #endif | 595 | #endif |
629 | #if ENABLE_FEATURE_REMOTE_LOG | 596 | #if ENABLE_FEATURE_REMOTE_LOG |
630 | if (option_mask & OPT_remotelog) { // -R | 597 | if (option_mask & OPT_remotelog) { // -R |
631 | RemoteHost = xstrdup(opt_R); | 598 | int port = 514; |
632 | p = strchr(RemoteHost, ':'); | 599 | char *host = xstrdup(opt_R); |
600 | p = strchr(host, ':'); | ||
633 | if (p) { | 601 | if (p) { |
634 | RemotePort = atoi(p + 1); | 602 | port = atoi(p + 1); |
635 | *p = '\0'; | 603 | *p = '\0'; |
636 | } | 604 | } |
605 | remoteaddr.sin_family = AF_INET; | ||
606 | /* FIXME: looks ip4-specific. need to do better */ | ||
607 | remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(host)->h_addr_list); | ||
608 | remoteaddr.sin_port = htons(port); | ||
609 | free(host); | ||
637 | } | 610 | } |
638 | //if (option_mask & OPT_locallog) // -L | 611 | //if (option_mask & OPT_locallog) // -L |
639 | #endif | 612 | #endif |