Oops. Fix capililization
[oweals/busybox.git] / sysklogd / syslogd.c
index 9f5fc93b1f21745bc3130f6b8c57c4d0b1cc4c03..db6401c5202e581e235128438f04f176e7ba95bd 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,7 @@ static int local_logging = FALSE;
 #endif
 
 /* circular buffer variables/structures */
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
 
 #include <sys/ipc.h>
 #include <sys/sem.h>
@@ -155,8 +155,6 @@ void ipcsyslog_init(void){
                    perror_msg_and_die("semget");
                }else
                        perror_msg_and_die("semget");
-           } else {
-                   sem_up(s_semid);
            }
        }else{
                printf("Buffer already allocated just grab the semaphore?");
@@ -271,7 +269,7 @@ static void message (char *fmt, ...)
        fl.l_start  = 0;
        fl.l_len    = 1;
 
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
        if ((circular_logging == TRUE) && (buf != NULL)){
                        char b[1024];
                        va_start (arguments, fmt);
@@ -341,14 +339,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);          
@@ -372,9 +370,9 @@ static const int IOV_COUNT = 2;
 
 static void quit_signal(int sig)
 {
-       logMessage(0, "System log daemon exiting.");
+       logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting.");
        unlink(lfile);
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
        ipcsyslog_cleanup();
 #endif
 
@@ -389,21 +387,24 @@ static void domark(int sig)
        }
 }
 
-static const int BUFSIZE = 1023;
+/* This must be a #define, since when DODEBUG and BUFFERS_GO_IN_BSS are
+ * enabled, we otherwise get a "storage size isn't constant error. */
+#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 +429,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);
 
@@ -450,11 +453,7 @@ static void init_RemoteLog (void){
     error_msg_and_die("syslogd: cannot create socket");
   }
 
-  hostinfo = (struct hostent *) gethostbyname(RemoteHost);
-
-  if (!hostinfo) {
-    error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost);
-  }
+  hostinfo = xgethostbyname(RemoteHost);
 
   remoteaddr.sin_family = AF_INET;
   remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
@@ -494,17 +493,14 @@ static void doSyslogd (void)
        alarm (MarkInterval);
 
        /* Create the syslog file so realpath() can work. */
-       close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
-       if (realpath (_PATH_LOG, lfile) == NULL)
-               perror_msg_and_die ("Could not resolve path to " _PATH_LOG);
-
-       unlink (lfile);
+       if (realpath (_PATH_LOG, lfile) != NULL)
+               unlink (lfile);
 
        memset (&sunx, 0, sizeof (sunx));
        sunx.sun_family = AF_UNIX;
        strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
        if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
-               perror_msg_and_die ("Couldn't obtain descriptor for socket " _PATH_LOG);
+               perror_msg_and_die ("Couldn't get file descriptor for socket " _PATH_LOG);
 
        addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
        if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
@@ -516,19 +512,19 @@ static void doSyslogd (void)
        FD_ZERO (&fds);
        FD_SET (sock_fd, &fds);
 
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
        if (circular_logging == TRUE ){
           ipcsyslog_init();
        }
 #endif
 
-        #ifdef BB_FEATURE_REMOTE_LOG
+        #ifdef CONFIG_FEATURE_REMOTE_LOG
         if (doRemoteLog == TRUE){
           init_RemoteLog();
         }
         #endif
 
-       logMessage (0, "syslogd started: " BB_BANNER);
+       logMessage (LOG_SYSLOG | LOG_INFO, "syslogd started: " BB_BANNER);
 
        for (;;) {
 
@@ -589,7 +585,7 @@ extern int syslogd_main(int argc, char **argv)
                        case 'O':
                                logFilePath = strdup(optarg);
                                break;
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
                        case 'R':
                                RemoteHost = strdup(optarg);
                                if ( (p = strchr(RemoteHost, ':'))){
@@ -602,7 +598,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;
@@ -612,7 +608,7 @@ 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)
                local_logging = TRUE;