diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-08-26 23:15:29 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-08-26 23:15:29 +0000 |
commit | 75813eea230ccf60ac8623ffb161c890c6f063c5 (patch) | |
tree | 76a4f528f98381a03778e5e7b00515a8063b295e | |
parent | 138791050d36d221d718568094892245d7c6f6ec (diff) | |
download | busybox-w32-75813eea230ccf60ac8623ffb161c890c6f063c5.tar.gz busybox-w32-75813eea230ccf60ac8623ffb161c890c6f063c5.tar.bz2 busybox-w32-75813eea230ccf60ac8623ffb161c890c6f063c5.zip |
Togg writes:
Syslogd wont start if remote-logging is enabled and the connection to the
remote-log server is not possible on syslogd startup.
I found a patch somewhere which works like a charm. It uses sendto() which
seems more reliable for this issue.
Please see attached patch. Many people will be more happy with this included
I think.
Regards,
Togg
-rw-r--r-- | sysklogd/syslogd.c | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 2023873a8..741c80673 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -78,6 +78,8 @@ static char LocalHostName[64]; | |||
78 | #include <netinet/in.h> | 78 | #include <netinet/in.h> |
79 | /* udp socket for logging to remote host */ | 79 | /* udp socket for logging to remote host */ |
80 | static int remotefd = -1; | 80 | static int remotefd = -1; |
81 | static struct sockaddr_in remoteaddr; | ||
82 | static int remoteaddrlen; | ||
81 | 83 | ||
82 | /* where do we log? */ | 84 | /* where do we log? */ |
83 | static char *RemoteHost; | 85 | static char *RemoteHost; |
@@ -384,6 +386,7 @@ static void logMessage(int pri, char *msg) | |||
384 | time_t now; | 386 | time_t now; |
385 | char *timestamp; | 387 | char *timestamp; |
386 | static char res[20] = ""; | 388 | static char res[20] = ""; |
389 | static char line[512]; | ||
387 | CODE *c_pri, *c_fac; | 390 | CODE *c_pri, *c_fac; |
388 | 391 | ||
389 | if (pri != 0) { | 392 | if (pri != 0) { |
@@ -414,21 +417,15 @@ static void logMessage(int pri, char *msg) | |||
414 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 417 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
415 | /* send message to remote logger */ | 418 | /* send message to remote logger */ |
416 | if (-1 != remotefd) { | 419 | if (-1 != remotefd) { |
417 | static const int IOV_COUNT = 2; | 420 | |
418 | struct iovec iov[IOV_COUNT]; | 421 | memset(&line, 0, sizeof(line)); |
419 | struct iovec *v = iov; | 422 | snprintf(line, sizeof(line), "<%d> <%s>", pri, msg); |
420 | 423 | ||
421 | memset(&res, 0, sizeof(res)); | 424 | retry: |
422 | snprintf(res, sizeof(res), "<%d>", pri); | 425 | if(( -1 == sendto(remotefd, line, strlen(line), 0, |
423 | v->iov_base = res; | 426 | (struct sockaddr *) &remoteaddr, |
424 | v->iov_len = strlen(res); | 427 | remoteaddrlen)) && (errno == EINTR)) { |
425 | v++; | 428 | goto retry; |
426 | |||
427 | v->iov_base = msg; | ||
428 | v->iov_len = strlen(msg); | ||
429 | writev_retry: | ||
430 | if ((-1 == writev(remotefd, iov, IOV_COUNT)) && (errno == EINTR)) { | ||
431 | goto writev_retry; | ||
432 | } | 429 | } |
433 | } | 430 | } |
434 | if (local_logging == TRUE) | 431 | if (local_logging == TRUE) |
@@ -508,12 +505,10 @@ static int serveConnection(char *tmpbuf, int n_read) | |||
508 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 505 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
509 | static void init_RemoteLog(void) | 506 | static void init_RemoteLog(void) |
510 | { | 507 | { |
511 | |||
512 | struct sockaddr_in remoteaddr; | ||
513 | struct hostent *hostinfo; | 508 | struct hostent *hostinfo; |
514 | int len = sizeof(remoteaddr); | 509 | remoteaddrlen = sizeof(remoteaddr); |
515 | 510 | ||
516 | memset(&remoteaddr, 0, len); | 511 | memset(&remoteaddr, 0, remoteaddrlen); |
517 | 512 | ||
518 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); | 513 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); |
519 | 514 | ||
@@ -526,15 +521,6 @@ static void init_RemoteLog(void) | |||
526 | remoteaddr.sin_family = AF_INET; | 521 | remoteaddr.sin_family = AF_INET; |
527 | remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; | 522 | remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; |
528 | remoteaddr.sin_port = htons(RemotePort); | 523 | remoteaddr.sin_port = htons(RemotePort); |
529 | |||
530 | /* Since we are using UDP sockets, connect just sets the default host and port | ||
531 | * for future operations | ||
532 | */ | ||
533 | if (0 != (connect(remotefd, (struct sockaddr *) &remoteaddr, len))) { | ||
534 | bb_error_msg_and_die("cannot connect to remote host %s:%d", RemoteHost, | ||
535 | RemotePort); | ||
536 | } | ||
537 | |||
538 | } | 524 | } |
539 | #endif | 525 | #endif |
540 | 526 | ||