From: Eric Andersen Date: Wed, 8 Sep 2004 10:56:06 +0000 (-0000) Subject: Felipe Kellermann writes: X-Git-Tag: 1_00~44 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f91b9282a3290c6e46d0ab532d7003f58d755cc5;p=oweals%2Fbusybox.git 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. --- 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]; /* udp socket for logging to remote host */ static int remotefd = -1; static struct sockaddr_in remoteaddr; -static int remoteaddrlen; /* where do we log? */ static char *RemoteHost; @@ -381,13 +380,29 @@ static void message(char *fmt, ...) } } +#ifdef CONFIG_FEATURE_REMOTE_LOG +static void init_RemoteLog(void) +{ + memset(&remoteaddr, 0, sizeof(remoteaddr)); + remotefd = socket(AF_INET, SOCK_DGRAM, 0); + + if (remotefd < 0) { + bb_error_msg("cannot create socket"); + } + + remoteaddr.sin_family = AF_INET; + remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; + remoteaddr.sin_port = htons(RemotePort); +} +#endif + static void logMessage(int pri, char *msg) { time_t now; char *timestamp; static char res[20] = ""; #ifdef CONFIG_FEATURE_REMOTE_LOG - static char line[512]; + static char line[MAXLINE + 1]; #endif CODE *c_pri, *c_fac; @@ -418,15 +433,20 @@ static void logMessage(int pri, char *msg) #ifdef CONFIG_FEATURE_REMOTE_LOG /* send message to remote logger */ - if (-1 != remotefd) { + if (-1 == remotefd) { + init_RemoteLog(); + } - memset(&line, 0, sizeof(line)); - snprintf(line, sizeof(line), "<%d> <%s>", pri, msg); + if (-1 != remotefd) { + now = 1; + snprintf(line, sizeof(line), "<%d> %s", pri, msg); retry: if(( -1 == sendto(remotefd, line, strlen(line), 0, (struct sockaddr *) &remoteaddr, - remoteaddrlen)) && (errno == EINTR)) { + sizeof(remoteaddr))) && (errno == EINTR)) { + sleep(now); + now *= 2; goto retry; } } @@ -503,29 +523,6 @@ static int serveConnection(char *tmpbuf, int n_read) return n_read; } - -#ifdef CONFIG_FEATURE_REMOTE_LOG -static void init_RemoteLog(void) -{ - struct hostent *hostinfo; - remoteaddrlen = sizeof(remoteaddr); - - memset(&remoteaddr, 0, remoteaddrlen); - - remotefd = socket(AF_INET, SOCK_DGRAM, 0); - - if (remotefd < 0) { - bb_error_msg_and_die("cannot create socket"); - } - - hostinfo = xgethostbyname(RemoteHost); - - remoteaddr.sin_family = AF_INET; - remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; - remoteaddr.sin_port = htons(RemotePort); -} -#endif - static void doSyslogd(void) __attribute__ ((noreturn)); static void doSyslogd(void) {