* archival/gzip.c (ifname, ofname): Delete.
[oweals/busybox.git] / sysklogd / syslogd.c
index 89f5348ec94ffbd197fac8ee275873ffe33d4463..6db017cd479860bf58595dc12e86a22d553bd8fd 100644 (file)
@@ -2,8 +2,8 @@
 /*
  * Mini syslogd implementation for busybox
  *
- * Copyright (C) 1999,2000,2001 by Lineo, inc.
- * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
  *
  * Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
  *
@@ -55,7 +55,7 @@
 #define __LOG_FILE "/var/log/messages"
 
 /* Path to the unix socket */
-static char lfile[BUFSIZ] = "";
+static char lfile[BUFSIZ];
 
 static char *logFilePath = __LOG_FILE;
 
@@ -65,7 +65,7 @@ static int MarkInterval = 20 * 60;
 /* localhost's name */
 static char LocalHostName[32];
 
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
 #include <netinet/in.h>
 /* udp socket for logging to remote host */
 static int remotefd = -1;
@@ -79,7 +79,13 @@ static int local_logging = FALSE;
 #endif
 
 /* circular buffer variables/structures */
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+
+#if __GNU_LIBRARY__ < 5
+#error Sorry.  Looks like you are using libc5.
+#error libc5 shm support isnt good enough.
+#error Please disable CONFIG_FEATURE_IPC_SYSLOG
+#endif
 
 #include <sys/ipc.h>
 #include <sys/sem.h>
@@ -269,8 +275,8 @@ static void message (char *fmt, ...)
        fl.l_start  = 0;
        fl.l_len    = 1;
 
-#ifdef BB_FEATURE_IPC_SYSLOG
-       if ((circular_logging == TRUE) && (buf != NULL)){
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+       if ((circular_logging) && (buf != NULL)){
                        char b[1024];
                        va_start (arguments, fmt);
                        vsprintf (b, fmt, arguments);
@@ -339,14 +345,14 @@ static void logMessage (int pri, char *msg)
 
        /* todo: supress duplicates */
 
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
        /* send message to remote logger */
        if ( -1 != remotefd){
 static const int IOV_COUNT = 2;
                struct iovec iov[IOV_COUNT];
                struct iovec *v = iov;
 
-               bzero(&res, sizeof(res));
+               memset(&res, 0, sizeof(res));
                snprintf(res, sizeof(res), "<%d>", pri);
                v->iov_base = res ;
                v->iov_len = strlen(res);          
@@ -360,7 +366,7 @@ static const int IOV_COUNT = 2;
                                        "%s:%d",RemoteHost,RemotePort);
                }
        }
-       if (local_logging == TRUE)
+       if (local_logging)
 #endif
                /* now spew out the message to wherever it is supposed to go */
                message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
@@ -372,7 +378,7 @@ static void quit_signal(int sig)
 {
        logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting.");
        unlink(lfile);
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
        ipcsyslog_cleanup();
 #endif
 
@@ -392,18 +398,19 @@ static void domark(int sig)
 #define BUFSIZE 1023
 static int serveConnection (int conn)
 {
-       RESERVE_BB_BUFFER(tmpbuf, BUFSIZE + 1);
+       RESERVE_CONFIG_BUFFER(tmpbuf, BUFSIZE + 1);
        int    n_read;
+       char *p = tmpbuf;
 
        n_read = read (conn, tmpbuf, BUFSIZE );
 
-       if (n_read > 0) {
+       while (p < tmpbuf + n_read) {
 
                int           pri = (LOG_USER | LOG_NOTICE);
                char          line[ BUFSIZE + 1 ];
                unsigned char c;
 
-               char *p = tmpbuf, *q = line;
+               char *q = line;
 
                tmpbuf[ n_read - 1 ] = '\0';
 
@@ -428,21 +435,23 @@ static int serveConnection (int conn)
                        p++;
                }
                *q = '\0';
+               p++;
                /* Now log it */
                logMessage (pri, line);
        }
+       RELEASE_CONFIG_BUFFER (tmpbuf);
        return n_read;
 }
 
 
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
 static void init_RemoteLog (void){
 
   struct sockaddr_in remoteaddr;
   struct hostent *hostinfo;
   int len = sizeof(remoteaddr);
 
-  bzero(&remoteaddr, len);
+  memset(&remoteaddr, 0, len);
 
   remotefd = socket(AF_INET, SOCK_DGRAM, 0);
 
@@ -509,14 +518,14 @@ static void doSyslogd (void)
        FD_ZERO (&fds);
        FD_SET (sock_fd, &fds);
 
-#ifdef BB_FEATURE_IPC_SYSLOG
-       if (circular_logging == TRUE ){
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+       if (circular_logging ){
           ipcsyslog_init();
        }
 #endif
 
-        #ifdef BB_FEATURE_REMOTE_LOG
-        if (doRemoteLog == TRUE){
+        #ifdef CONFIG_FEATURE_REMOTE_LOG
+        if (doRemoteLog){
           init_RemoteLog();
         }
         #endif
@@ -580,11 +589,11 @@ extern int syslogd_main(int argc, char **argv)
                                doFork = FALSE;
                                break;
                        case 'O':
-                               logFilePath = strdup(optarg);
+                               logFilePath = xstrdup(optarg);
                                break;
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
                        case 'R':
-                               RemoteHost = strdup(optarg);
+                               RemoteHost = xstrdup(optarg);
                                if ( (p = strchr(RemoteHost, ':'))){
                                        RemotePort = atoi(p+1);
                                        *p = '\0';
@@ -595,7 +604,7 @@ extern int syslogd_main(int argc, char **argv)
                                local_logging = TRUE;
                                break;
 #endif
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
                        case 'C':
                                circular_logging = TRUE;
                                break;
@@ -605,9 +614,9 @@ extern int syslogd_main(int argc, char **argv)
                }
        }
 
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
        /* If they have not specified remote logging, then log locally */
-       if (doRemoteLog == FALSE)
+       if (! doRemoteLog)
                local_logging = TRUE;
 #endif
 
@@ -620,9 +629,13 @@ extern int syslogd_main(int argc, char **argv)
 
        umask(0);
 
-       if (doFork == TRUE) {
+       if (doFork) {
+#if !defined(__UCLIBC__) || defined(__UCLIBC_HAS_MMU__)
                if (daemon(0, 1) < 0)
                        perror_msg_and_die("daemon");
+#else
+                       error_msg_and_die("daemon not supported");
+#endif
        }
        doSyslogd();