diff options
| -rw-r--r-- | sysklogd/syslogd.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 6e7652c00..ef9cf2162 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
| @@ -79,7 +79,6 @@ static char LocalHostName[64]; | |||
| 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; | 81 | static struct sockaddr_in remoteaddr; |
| 82 | static int remoteaddrlen; | ||
| 83 | 82 | ||
| 84 | /* where do we log? */ | 83 | /* where do we log? */ |
| 85 | static char *RemoteHost; | 84 | static char *RemoteHost; |
| @@ -381,13 +380,29 @@ static void message(char *fmt, ...) | |||
| 381 | } | 380 | } |
| 382 | } | 381 | } |
| 383 | 382 | ||
| 383 | #ifdef CONFIG_FEATURE_REMOTE_LOG | ||
| 384 | static void init_RemoteLog(void) | ||
| 385 | { | ||
| 386 | memset(&remoteaddr, 0, sizeof(remoteaddr)); | ||
| 387 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); | ||
| 388 | |||
| 389 | if (remotefd < 0) { | ||
| 390 | bb_error_msg("cannot create socket"); | ||
| 391 | } | ||
| 392 | |||
| 393 | remoteaddr.sin_family = AF_INET; | ||
| 394 | remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; | ||
| 395 | remoteaddr.sin_port = htons(RemotePort); | ||
| 396 | } | ||
| 397 | #endif | ||
| 398 | |||
| 384 | static void logMessage(int pri, char *msg) | 399 | static void logMessage(int pri, char *msg) |
| 385 | { | 400 | { |
| 386 | time_t now; | 401 | time_t now; |
| 387 | char *timestamp; | 402 | char *timestamp; |
| 388 | static char res[20] = ""; | 403 | static char res[20] = ""; |
| 389 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 404 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
| 390 | static char line[512]; | 405 | static char line[MAXLINE + 1]; |
| 391 | #endif | 406 | #endif |
| 392 | CODE *c_pri, *c_fac; | 407 | CODE *c_pri, *c_fac; |
| 393 | 408 | ||
| @@ -418,15 +433,20 @@ static void logMessage(int pri, char *msg) | |||
| 418 | 433 | ||
| 419 | #ifdef CONFIG_FEATURE_REMOTE_LOG | 434 | #ifdef CONFIG_FEATURE_REMOTE_LOG |
| 420 | /* send message to remote logger */ | 435 | /* send message to remote logger */ |
| 421 | if (-1 != remotefd) { | 436 | if (-1 == remotefd) { |
| 437 | init_RemoteLog(); | ||
| 438 | } | ||
| 422 | 439 | ||
| 423 | memset(&line, 0, sizeof(line)); | 440 | if (-1 != remotefd) { |
| 424 | snprintf(line, sizeof(line), "<%d> <%s>", pri, msg); | 441 | now = 1; |
| 442 | snprintf(line, sizeof(line), "<%d> %s", pri, msg); | ||
| 425 | 443 | ||
| 426 | retry: | 444 | retry: |
| 427 | if(( -1 == sendto(remotefd, line, strlen(line), 0, | 445 | if(( -1 == sendto(remotefd, line, strlen(line), 0, |
| 428 | (struct sockaddr *) &remoteaddr, | 446 | (struct sockaddr *) &remoteaddr, |
| 429 | remoteaddrlen)) && (errno == EINTR)) { | 447 | sizeof(remoteaddr))) && (errno == EINTR)) { |
| 448 | sleep(now); | ||
| 449 | now *= 2; | ||
| 430 | goto retry; | 450 | goto retry; |
| 431 | } | 451 | } |
| 432 | } | 452 | } |
| @@ -503,29 +523,6 @@ static int serveConnection(char *tmpbuf, int n_read) | |||
| 503 | return n_read; | 523 | return n_read; |
| 504 | } | 524 | } |
| 505 | 525 | ||
| 506 | |||
| 507 | #ifdef CONFIG_FEATURE_REMOTE_LOG | ||
| 508 | static void init_RemoteLog(void) | ||
| 509 | { | ||
| 510 | struct hostent *hostinfo; | ||
| 511 | remoteaddrlen = sizeof(remoteaddr); | ||
| 512 | |||
| 513 | memset(&remoteaddr, 0, remoteaddrlen); | ||
| 514 | |||
| 515 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); | ||
| 516 | |||
| 517 | if (remotefd < 0) { | ||
| 518 | bb_error_msg_and_die("cannot create socket"); | ||
| 519 | } | ||
| 520 | |||
| 521 | hostinfo = xgethostbyname(RemoteHost); | ||
| 522 | |||
| 523 | remoteaddr.sin_family = AF_INET; | ||
| 524 | remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; | ||
| 525 | remoteaddr.sin_port = htons(RemotePort); | ||
| 526 | } | ||
| 527 | #endif | ||
| 528 | |||
| 529 | static void doSyslogd(void) __attribute__ ((noreturn)); | 526 | static void doSyslogd(void) __attribute__ ((noreturn)); |
| 530 | static void doSyslogd(void) | 527 | static void doSyslogd(void) |
| 531 | { | 528 | { |
