[BusyBox-cvs] CVS update of busybox/sysklogd (syslogd.c)

Erik Andersen andersen at codepoet.org
Wed Sep 8 10:56:07 UTC 2004


    Date: Wednesday, September 8, 2004 @ 04:56:07
  Author: andersen
    Path: /var/cvs/busybox/sysklogd

Modified: syslogd.c (1.115 -> 1.116)

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.


Index: busybox/sysklogd/syslogd.c
diff -u busybox/sysklogd/syslogd.c:1.115 busybox/sysklogd/syslogd.c:1.116
--- busybox/sysklogd/syslogd.c:1.115	Thu Sep  2 16:22:17 2004
+++ busybox/sysklogd/syslogd.c	Wed Sep  8 04:56:06 2004
@@ -79,7 +79,6 @@
 /* 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 @@
 	}
 }
 
+#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 @@
 
 #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 @@
 	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)
 {



More information about the busybox-cvs mailing list