aboutsummaryrefslogtreecommitdiff
path: root/sysklogd/syslogd.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-09-08 10:56:06 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-09-08 10:56:06 +0000
commit9577798e420ea4ceff5fecb50414035406e33b79 (patch)
treebe0f83e3412bfc3b41310c2011d9b17f6a7cb132 /sysklogd/syslogd.c
parentae5a581c80990a0e14253aabda3325ea6c29b312 (diff)
downloadbusybox-w32-9577798e420ea4ceff5fecb50414035406e33b79.tar.gz
busybox-w32-9577798e420ea4ceff5fecb50414035406e33b79.tar.bz2
busybox-w32-9577798e420ea4ceff5fecb50414035406e33b79.zip
Felipe Kellermann writes:
The Togg's sysklogd patch to use sendto() on remote logging is formatting strangely (using `<' and '>' surrounding the `msg' string message). This is OK, but this is not the standard way of formatting this message. So this patch does the following: o Fix the formatting to the standard way. o Uses `MAXLINE' when needed; o Don't loop sending messages without a "sleeping time", I'm now doing `now = 1', `now <<= 1'; o Don't die on `init_RemoteLog' when starting up (feature!) We're now trying to connect every time we have an invalid fd; o Removes one static uneeded variable. o Removes two automatic uneeded variables. git-svn-id: svn://busybox.net/trunk/busybox@9227 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r--sysklogd/syslogd.c55
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 */
80static int remotefd = -1; 80static int remotefd = -1;
81static struct sockaddr_in remoteaddr; 81static struct sockaddr_in remoteaddr;
82static int remoteaddrlen;
83 82
84/* where do we log? */ 83/* where do we log? */
85static char *RemoteHost; 84static char *RemoteHost;
@@ -381,13 +380,29 @@ static void message(char *fmt, ...)
381 } 380 }
382} 381}
383 382
383#ifdef CONFIG_FEATURE_REMOTE_LOG
384static 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
384static void logMessage(int pri, char *msg) 399static 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
508static 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
529static void doSyslogd(void) __attribute__ ((noreturn)); 526static void doSyslogd(void) __attribute__ ((noreturn));
530static void doSyslogd(void) 527static void doSyslogd(void)
531{ 528{