aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Geulig <geulig@nentec.de>2010-02-28 13:01:59 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-02-28 13:01:59 +0100
commitd2f77796711f55240d4a88c92ea8c6545baeee98 (patch)
treee42a03d14c85f834556037a544dbda788d6032be
parent3e26d4fa233705f2061b6f296ac2a604e94f508a (diff)
downloadbusybox-w32-d2f77796711f55240d4a88c92ea8c6545baeee98.tar.gz
busybox-w32-d2f77796711f55240d4a88c92ea8c6545baeee98.tar.bz2
busybox-w32-d2f77796711f55240d4a88c92ea8c6545baeee98.zip
syslog: allow multiple -R options
function old new delta syslogd_main 1082 1177 +95 init_data 72 64 -8 Signed-off-by: Thomas Geulig <geulig@nentec.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--sysklogd/syslogd.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 8338d6be8..33203697d 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -57,6 +57,15 @@ struct shbuf_ds {
57 char data[1]; /* data/messages */ 57 char data[1]; /* data/messages */
58}; 58};
59 59
60#if ENABLE_FEATURE_REMOTE_LOG
61typedef struct {
62 int remoteFD;
63 unsigned last_dns_resolve;
64 len_and_sockaddr *remoteAddr;
65 const char *remoteHostname;
66} remoteHost_t;
67#endif
68
60/* Allows us to have smaller initializer. Ugly. */ 69/* Allows us to have smaller initializer. Ugly. */
61#define GLOBALS \ 70#define GLOBALS \
62 const char *logFilePath; \ 71 const char *logFilePath; \
@@ -73,11 +82,6 @@ IF_FEATURE_ROTATE_LOGFILE( \
73 unsigned curFileSize; \ 82 unsigned curFileSize; \
74 smallint isRegular; \ 83 smallint isRegular; \
75) \ 84) \
76IF_FEATURE_REMOTE_LOG( \
77 /* udp socket for remote logging */ \
78 int remoteFD; \
79 len_and_sockaddr* remoteAddr; \
80) \
81IF_FEATURE_IPC_SYSLOG( \ 85IF_FEATURE_IPC_SYSLOG( \
82 int shmid; /* ipc shared memory id */ \ 86 int shmid; /* ipc shared memory id */ \
83 int s_semid; /* ipc semaphore id */ \ 87 int s_semid; /* ipc semaphore id */ \
@@ -94,10 +98,8 @@ struct globals {
94 GLOBALS 98 GLOBALS
95 99
96#if ENABLE_FEATURE_REMOTE_LOG 100#if ENABLE_FEATURE_REMOTE_LOG
97 unsigned last_dns_resolve; 101 llist_t *remoteHosts;
98 char *remoteAddrStr;
99#endif 102#endif
100
101#if ENABLE_FEATURE_IPC_SYSLOG 103#if ENABLE_FEATURE_IPC_SYSLOG
102 struct shbuf_ds *shbuf; 104 struct shbuf_ds *shbuf;
103#endif 105#endif
@@ -127,9 +129,6 @@ static const struct init_globals init_data = {
127 .logFileSize = 200 * 1024, 129 .logFileSize = 200 * 1024,
128 .logFileRotate = 1, 130 .logFileRotate = 1,
129#endif 131#endif
130#if ENABLE_FEATURE_REMOTE_LOG
131 .remoteFD = -1,
132#endif
133#if ENABLE_FEATURE_IPC_SYSLOG 132#if ENABLE_FEATURE_IPC_SYSLOG
134 .shmid = -1, 133 .shmid = -1,
135 .s_semid = -1, 134 .s_semid = -1,
@@ -185,7 +184,7 @@ enum {
185#define OPTION_PARAM &opt_m, &G.logFilePath, &opt_l \ 184#define OPTION_PARAM &opt_m, &G.logFilePath, &opt_l \
186 IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \ 185 IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \
187 IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \ 186 IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \
188 IF_FEATURE_REMOTE_LOG( ,&G.remoteAddrStr) \ 187 IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \
189 IF_FEATURE_IPC_SYSLOG( ,&opt_C) 188 IF_FEATURE_IPC_SYSLOG( ,&opt_C)
190 189
191 190
@@ -534,20 +533,20 @@ static NOINLINE int create_socket(void)
534} 533}
535 534
536#if ENABLE_FEATURE_REMOTE_LOG 535#if ENABLE_FEATURE_REMOTE_LOG
537static int try_to_resolve_remote(void) 536static int try_to_resolve_remote(remoteHost_t *rh)
538{ 537{
539 if (!G.remoteAddr) { 538 if (!rh->remoteAddr) {
540 unsigned now = monotonic_sec(); 539 unsigned now = monotonic_sec();
541 540
542 /* Don't resolve name too often - DNS timeouts can be big */ 541 /* Don't resolve name too often - DNS timeouts can be big */
543 if ((now - G.last_dns_resolve) < DNS_WAIT_SEC) 542 if ((now - rh->last_dns_resolve) < DNS_WAIT_SEC)
544 return -1; 543 return -1;
545 G.last_dns_resolve = now; 544 rh->last_dns_resolve = now;
546 G.remoteAddr = host2sockaddr(G.remoteAddrStr, 514); 545 rh->remoteAddr = host2sockaddr(rh->remoteHostname, 514);
547 if (!G.remoteAddr) 546 if (!rh->remoteAddr)
548 return -1; 547 return -1;
549 } 548 }
550 return socket(G.remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0); 549 return socket(rh->remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0);
551} 550}
552#endif 551#endif
553 552
@@ -555,6 +554,9 @@ static void do_syslogd(void) NORETURN;
555static void do_syslogd(void) 554static void do_syslogd(void)
556{ 555{
557 int sock_fd; 556 int sock_fd;
557#if ENABLE_FEATURE_REMOTE_LOG
558 llist_t *item;
559#endif
558#if ENABLE_FEATURE_SYSLOGD_DUP 560#if ENABLE_FEATURE_SYSLOGD_DUP
559 int last_sz = -1; 561 int last_sz = -1;
560 char *last_buf; 562 char *last_buf;
@@ -620,23 +622,25 @@ static void do_syslogd(void)
620 last_sz = sz; 622 last_sz = sz;
621#endif 623#endif
622#if ENABLE_FEATURE_REMOTE_LOG 624#if ENABLE_FEATURE_REMOTE_LOG
625 /* Stock syslogd sends it '\n'-terminated
626 * over network, mimic that */
627 recvbuf[sz] = '\n';
628
623 /* We are not modifying log messages in any way before send */ 629 /* We are not modifying log messages in any way before send */
624 /* Remote site cannot trust _us_ anyway and need to do validation again */ 630 /* Remote site cannot trust _us_ anyway and need to do validation again */
625 if (G.remoteAddrStr) { 631 for (item = G.remoteHosts; item != NULL; item = item->link) {
626 if (-1 == G.remoteFD) { 632 remoteHost_t *rh = (remoteHost_t *)item->data;
627 G.remoteFD = try_to_resolve_remote(); 633
628 if (-1 == G.remoteFD) 634 if (rh->remoteFD == -1) {
629 goto no_luck; 635 rh->remoteFD = try_to_resolve_remote(rh);
636 if (rh->remoteFD == -1)
637 continue;
630 } 638 }
631 /* Stock syslogd sends it '\n'-terminated 639 /* Send message to remote logger, ignore possible error */
632 * over network, mimic that */
633 recvbuf[sz] = '\n';
634 /* send message to remote logger, ignore possible error */
635 /* TODO: on some errors, close and set G.remoteFD to -1 640 /* TODO: on some errors, close and set G.remoteFD to -1
636 * so that DNS resolution and connect is retried? */ 641 * so that DNS resolution and connect is retried? */
637 sendto(G.remoteFD, recvbuf, sz+1, MSG_DONTWAIT, 642 sendto(rh->remoteFD, recvbuf, sz+1, MSG_DONTWAIT,
638 &G.remoteAddr->u.sa, G.remoteAddr->len); 643 &(rh->remoteAddr->u.sa), rh->remoteAddr->len);
639 no_luck: ;
640 } 644 }
641#endif 645#endif
642 if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) { 646 if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {
@@ -656,17 +660,27 @@ static void do_syslogd(void)
656int syslogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 660int syslogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
657int syslogd_main(int argc UNUSED_PARAM, char **argv) 661int syslogd_main(int argc UNUSED_PARAM, char **argv)
658{ 662{
659 char OPTION_DECL;
660 int opts; 663 int opts;
664 char OPTION_DECL;
665#if ENABLE_FEATURE_REMOTE_LOG
666 llist_t *remoteAddrList = NULL;
667#endif
661 668
662 INIT_G(); 669 INIT_G();
670
671 /* No non-option params, -R can occur multiple times */
672 opt_complementary = "=0" IF_FEATURE_REMOTE_LOG(":R::");
673 opts = getopt32(argv, OPTION_STR, OPTION_PARAM);
663#if ENABLE_FEATURE_REMOTE_LOG 674#if ENABLE_FEATURE_REMOTE_LOG
664 G.last_dns_resolve = monotonic_sec() - DNS_WAIT_SEC - 1; 675 while (remoteAddrList) {
676 remoteHost_t *rh = xzalloc(sizeof(*rh));
677 rh->remoteHostname = llist_pop(&remoteAddrList);
678 rh->remoteFD = -1;
679 rh->last_dns_resolve = monotonic_sec() - DNS_WAIT_SEC - 1;
680 llist_add_to(&G.remoteHosts, rh);
681 }
665#endif 682#endif
666 683
667 /* do normal option parsing */
668 opt_complementary = "=0"; /* no non-option params */
669 opts = getopt32(argv, OPTION_STR, OPTION_PARAM);
670#ifdef SYSLOGD_MARK 684#ifdef SYSLOGD_MARK
671 if (opts & OPT_mark) // -m 685 if (opts & OPT_mark) // -m
672 G.markInterval = xatou_range(opt_m, 0, INT_MAX/60) * 60; 686 G.markInterval = xatou_range(opt_m, 0, INT_MAX/60) * 60;