install correct aliases file
[unix-history] / usr / src / usr.sbin / syslogd / syslogd.c
index 321fc38..5211cfd 100644 (file)
@@ -1,18 +1,29 @@
 /*
 /*
- * Copyright (c) 1983,1988 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1983, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1983,1988 Regents of the University of California.\n\
+"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)syslogd.c  5.21 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)syslogd.c  5.27 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  *  syslogd -- log system messages
 
 /*
  *  syslogd -- log system messages
@@ -173,37 +184,31 @@ main(argc, argv)
        struct sockaddr_un sunx, fromunix;
        struct sockaddr_in sin, frominet;
        FILE *fp;
        struct sockaddr_un sunx, fromunix;
        struct sockaddr_in sin, frominet;
        FILE *fp;
+       int ch;
        char line[MSG_BSIZE + 1];
        char line[MSG_BSIZE + 1];
-       extern int die(), domark(), reapchild();
-
-       while (--argc > 0) {
-               p = *++argv;
-               if (p[0] != '-')
-                       usage();
-               switch (p[1]) {
-               case 'f':               /* configuration file */
-                       if (p[2] != '\0')
-                               ConfFile = &p[2];
-                       break;
+       extern int optind, die(), domark(), reapchild();
+       extern char *optarg;
 
 
+       while ((ch = getopt(argc, argv, "df:m:p:")) != EOF)
+               switch((char)ch) {
                case 'd':               /* debug */
                        Debug++;
                        break;
                case 'd':               /* debug */
                        Debug++;
                        break;
-
-               case 'p':               /* path */
-                       if (p[2] != '\0')
-                               LogName = &p[2];
+               case 'f':               /* configuration file */
+                       ConfFile = optarg;
                        break;
                        break;
-
                case 'm':               /* mark interval */
                case 'm':               /* mark interval */
-                       if (p[2] != '\0')
-                               MarkInterval = atoi(&p[2]) * 60;
+                       MarkInterval = atoi(optarg) * 60;
                        break;
                        break;
-
+               case 'p':               /* path */
+                       LogName = optarg;
+                       break;
+               case '?':
                default:
                        usage();
                }
                default:
                        usage();
                }
-       }
+       if (argc -= optind)
+               usage();
 
        if (!Debug) {
                if (fork())
 
        if (!Debug) {
                if (fork())
@@ -337,7 +342,7 @@ main(argc, argv)
 
 usage()
 {
 
 usage()
 {
-       fprintf(stderr, "usage: syslogd [-d] [-mmarkinterval] [-ppath] [-fconffile]\n");
+       fprintf(stderr, "usage: syslogd [-d] [-m markinterval] [-p path] [-f conffile]\n");
        exit(1);
 }
 
        exit(1);
 }
 
@@ -387,14 +392,15 @@ printline(hname, msg)
 
        q = line;
 
 
        q = line;
 
-       while ((c = *p++ & 0177) != '\0' && c != '\n' &&
-           q < &line[sizeof(line) - 1]) {
-               if (iscntrl(c)) {
+       while ((c = *p++ & 0177) != '\0' &&
+           q < &line[sizeof(line) - 1])
+               if (c == '\n')
+                       *q++ = ' ';
+               else if (iscntrl(c)) {
                        *q++ = '^';
                        *q++ = c ^ 0100;
                } else
                        *q++ = c;
                        *q++ = '^';
                        *q++ = c ^ 0100;
                } else
                        *q++ = c;
-       }
        *q = '\0';
 
        logmsg(pri, line, hname, 0);
        *q = '\0';
 
        logmsg(pri, line, hname, 0);
@@ -491,7 +497,7 @@ logmsg(pri, msg, from, flags)
 
                if (f->f_file >= 0) {
                        untty();
 
                if (f->f_file >= 0) {
                        untty();
-                       fprintlog(f, flags, (char *)NULL);
+                       fprintlog(f, flags, msg);
                        (void) close(f->f_file);
                }
                (void) sigsetmask(omask);
                        (void) close(f->f_file);
                }
                (void) sigsetmask(omask);
@@ -517,7 +523,7 @@ logmsg(pri, msg, from, flags)
                    !strcmp(from, f->f_prevhost)) {
                        (void) strncpy(f->f_lasttime, timestamp, 15);
                        f->f_prevcount++;
                    !strcmp(from, f->f_prevhost)) {
                        (void) strncpy(f->f_lasttime, timestamp, 15);
                        f->f_prevcount++;
-                       dprintf("msg repeated %d times, %d sec of %d\n",
+                       dprintf("msg repeated %d times, %ld sec of %d\n",
                            f->f_prevcount, now - f->f_time,
                            repeatinterval[f->f_repeatcount]);
                        /*
                            f->f_prevcount, now - f->f_time,
                            repeatinterval[f->f_repeatcount]);
                        /*
@@ -922,18 +928,18 @@ init()
         */
        f = NULL;
        while (fgets(cline, sizeof cline, cf) != NULL) {
         */
        f = NULL;
        while (fgets(cline, sizeof cline, cf) != NULL) {
-               /* check for end-of-section */
-               if (cline[0] == '\n' || cline[0] == '#')
+               /*
+                * check for end-of-section, comments, strip off trailing
+                * spaces and newline character.
+                */
+               for (p = cline; isspace(*p); ++p);
+               if (*p == NULL || *p == '#')
                        continue;
                        continue;
-
+               for (p = index(cline, '\0'); isspace(*--p););
+               *++p = '\0';
                f = (struct filed *)calloc(1, sizeof(*f));
                *nextp = f;
                nextp = &f->f_next;
                f = (struct filed *)calloc(1, sizeof(*f));
                *nextp = f;
                nextp = &f->f_next;
-               /* strip off newline character */
-               p = index(cline, '\n');
-               if (p)
-                       *p = '\0';
-
                cfline(cline, f);
        }
 
                cfline(cline, f);
        }
 
@@ -1010,6 +1016,7 @@ struct code       FacNames[] = {
        "syslog",       LOG_SYSLOG,
        "lpr",          LOG_LPR,
        "news",         LOG_NEWS,
        "syslog",       LOG_SYSLOG,
        "lpr",          LOG_LPR,
        "news",         LOG_NEWS,
+       "uucp",         LOG_UUCP,
        "local0",       LOG_LOCAL0,
        "local1",       LOG_LOCAL1,
        "local2",       LOG_LOCAL2,
        "local0",       LOG_LOCAL0,
        "local1",       LOG_LOCAL1,
        "local2",       LOG_LOCAL2,
@@ -1035,7 +1042,7 @@ cfline(line, f)
 
        dprintf("cfline(%s)\n", line);
 
 
        dprintf("cfline(%s)\n", line);
 
-       errno = 0;      /* keep sys_errlist stuff out of logerror messages */
+       errno = 0;      /* keep sys_errlist stuff out of logerror messages */
 
        /* clear out file entry */
        bzero((char *) f, sizeof *f);
 
        /* clear out file entry */
        bzero((char *) f, sizeof *f);
@@ -1070,8 +1077,6 @@ cfline(line, f)
 
                /* scan facilities */
                while (*p && !index("\t.;", *p)) {
 
                /* scan facilities */
                while (*p && !index("\t.;", *p)) {
-                       int i;
-
                        for (bp = buf; *p && !index("\t,;.", *p); )
                                *bp++ = *p++;
                        *bp = '\0';
                        for (bp = buf; *p && !index("\t,;.", *p); )
                                *bp++ = *p++;
                        *bp = '\0';
@@ -1108,11 +1113,11 @@ cfline(line, f)
                (void) strcpy(f->f_un.f_forw.f_hname, ++p);
                hp = gethostbyname(p);
                if (hp == NULL) {
                (void) strcpy(f->f_un.f_forw.f_hname, ++p);
                hp = gethostbyname(p);
                if (hp == NULL) {
-                       char buf[100];
+                       extern int h_errno, h_nerr;
+                       extern char **h_errlist;
 
 
-                       (void) sprintf(buf, "unknown host %s", p);
-                       errno = 0;
-                       logerror(buf);
+                       logerror((u_int)h_errno < h_nerr ?
+                           h_errlist[h_errno] : "Unknown error");
                        break;
                }
                bzero((char *) &f->f_un.f_forw.f_addr,
                        break;
                }
                bzero((char *) &f->f_un.f_forw.f_addr,
@@ -1126,6 +1131,7 @@ cfline(line, f)
        case '/':
                (void) strcpy(f->f_un.f_fname, p);
                if ((f->f_file = open(p, O_WRONLY|O_APPEND)) < 0) {
        case '/':
                (void) strcpy(f->f_un.f_fname, p);
                if ((f->f_file = open(p, O_WRONLY|O_APPEND)) < 0) {
+                       f->f_file = F_UNUSED;
                        logerror(p);
                        break;
                }
                        logerror(p);
                        break;
                }