Print this page
4211 Some syslog facility names and symbols are missing
3232 syslogd shouldn't sync after each LOG_KERN line
1762 Syslogd man page: missing reference.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/syslogd/syslogd.c
          +++ new/usr/src/cmd/syslogd/syslogd.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
       22 + * Copyright (c) 2013 Gary Mills
       23 + * Copyright 2012 Milan Jurik. All rights reserved.
  22   24   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23   25   * Use is subject to license terms.
  24      - * Copyright 2012 Milan Jurik. All rights reserved.
  25   26   */
  26   27  
  27   28  /*
  28   29   *      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  29   30   *      All Rights Reserved
  30   31   */
  31   32  
  32   33  /*
  33   34   * University Copyright- Copyright (c) 1982, 1986, 1988
  34   35   * The Regents of the University of California
↓ open down ↓ 113 lines elided ↑ open up ↑
 148  149          "user",         LOG_USER,
 149  150          "mail",         LOG_MAIL,
 150  151          "daemon",       LOG_DAEMON,
 151  152          "auth",         LOG_AUTH,
 152  153          "security",     LOG_AUTH,
 153  154          "mark",         LOG_MARK,
 154  155          "syslog",       LOG_SYSLOG,
 155  156          "lpr",          LOG_LPR,
 156  157          "news",         LOG_NEWS,
 157  158          "uucp",         LOG_UUCP,
      159 +        "bsdcron",      LOG_BSDCRON,
      160 +        "authpriv",     LOG_AUTHPRIV,
      161 +        "ftp",          LOG_FTP,
      162 +        "ntp",          LOG_NTP,
 158  163          "audit",        LOG_AUDIT,
      164 +        "console",      LOG_CONSOLE,
 159  165          "cron",         LOG_CRON,
 160  166          "local0",       LOG_LOCAL0,
 161  167          "local1",       LOG_LOCAL1,
 162  168          "local2",       LOG_LOCAL2,
 163  169          "local3",       LOG_LOCAL3,
 164  170          "local4",       LOG_LOCAL4,
 165  171          "local5",       LOG_LOCAL5,
 166  172          "local6",       LOG_LOCAL6,
 167  173          "local7",       LOG_LOCAL7,
 168  174          NULL,           -1
↓ open down ↓ 431 lines elided ↑ open up ↑
 600  606  /*
 601  607   * this thread listens to the local stream log driver for log messages
 602  608   * generated by this host, formats them, and queues them to the logger
 603  609   * thread.
 604  610   */
 605  611  /*ARGSUSED*/
 606  612  static void *
 607  613  sys_poll(void *ap)
 608  614  {
 609  615          int nfds;
      616 +        int timeout;
 610  617          static int klogerrs = 0;
 611  618          pthread_t mythreadno;
 612  619  
 613  620          if (Debug) {
 614  621                  mythreadno = pthread_self();
 615  622          }
 616  623  
 617  624          DPRINT1(1, "sys_poll(%u): sys_thread started\n", mythreadno);
 618  625  
 619  626          /*
 620  627           * Try to process as many messages as we can without blocking on poll.
 621      -         * We count such "initial" messages with sys_init_msg_count and
      628 +         * We identify such messages with timeout == 0 and
 622  629           * enqueue them without the SYNC_FILE flag.  When no more data is
 623  630           * waiting on the local log device, we set timeout to INFTIM,
 624      -         * clear sys_init_msg_count, and generate a flush message to sync
 625      -         * the previously counted initial messages out to disk.
      631 +         * and generate a flush message to sync
      632 +         * the previously identified messages out to disk.
 626  633           */
 627  634  
 628      -        sys_init_msg_count = 0;
      635 +        timeout = INFTIM;
 629  636  
 630  637          for (;;) {
 631  638                  errno = 0;
 632  639                  t_errno = 0;
 633  640  
 634      -                nfds = poll(&Pfd, 1, INFTIM);
      641 +                nfds = poll(&Pfd, 1, timeout);
 635  642  
 636      -                if (nfds == 0)
 637      -                        continue;
 638      -
 639      -                if (nfds < 0) {
 640      -                        if (errno != EINTR)
      643 +                if (nfds <= 0) {
      644 +                        if (nfds < 0 && errno != EINTR)
 641  645                                  logerror("poll");
      646 +                        if (timeout == 0)
      647 +                                flushmsg(SYNC_FILE);
      648 +                        timeout = INFTIM;
 642  649                          continue;
 643  650                  }
      651 +
 644  652                  if (Pfd.revents & POLLIN) {
 645      -                        getkmsg(INFTIM);
 646      -                } else {
 647      -                        if (shutting_down) {
 648      -                                pthread_exit(0);
 649      -                        }
 650      -                        if (Pfd.revents & (POLLNVAL|POLLHUP|POLLERR)) {
 651      -                                logerror("kernel log driver poll error");
 652      -                                (void) close(Pfd.fd);
 653      -                                Pfd.fd = -1;
 654      -                        }
      653 +                        timeout = 0;
      654 +                        getkmsg(timeout);
      655 +                        continue;
 655  656                  }
 656  657  
      658 +                if (shutting_down) {
      659 +                        pthread_exit(0);
      660 +                }
      661 +
      662 +                if (Pfd.revents & (POLLNVAL|POLLHUP|POLLERR)) {
      663 +                        logerror("kernel log driver poll error");
      664 +                        (void) close(Pfd.fd);
      665 +                        Pfd.fd = -1;
      666 +                }
      667 +
 657  668                  while (Pfd.fd == -1 && klogerrs++ < 10) {
 658  669                          Pfd.fd = openklog(LogName, O_RDONLY);
 659  670                  }
 660  671                  if (klogerrs >= 10) {
 661  672                          logerror("can't reopen kernel log device - fatal");
 662  673                          exit(1);
 663  674                  }
      675 +                if (timeout == 0)
      676 +                        flushmsg(SYNC_FILE);
      677 +                timeout = INFTIM;
 664  678          }
 665  679          /*NOTREACHED*/
 666  680          return (NULL);
 667  681  }
 668  682  
 669  683  /*
 670  684   * Pull up one message from log driver.
 671  685   */
 672  686  static void
 673  687  getkmsg(int timeout)
↓ open down ↓ 14 lines elided ↑ open up ↑
 688  702  
 689  703          dat.maxlen = MAXLINE;
 690  704          dat.buf = buf;
 691  705          ctl.maxlen = sizeof (struct log_ctl);
 692  706          ctl.buf = (caddr_t)&hdr;
 693  707  
 694  708          while ((i = getmsg(Pfd.fd, &ctl, &dat, &flags)) == MOREDATA) {
 695  709                  lastline = &dat.buf[dat.len];
 696  710                  *lastline = '\0';
 697  711  
 698      -                DPRINT2(5, "sys_poll:(%u): getmsg: dat.len = %d\n",
      712 +                DPRINT2(5, "getkmsg:(%u): getmsg: dat.len = %d\n",
 699  713                      mythreadno, dat.len);
 700  714                  buflen = strlen(buf);
 701  715                  len = findnl_bkwd(buf, buflen);
 702  716  
 703  717                  (void) memcpy(tmpbuf, buf, len);
 704  718                  tmpbuf[len] = '\0';
 705  719  
 706  720                  /*
 707  721                   * Format sys will enqueue the log message.
 708  722                   * Set the sync flag if timeout != 0, which
↓ open down ↓ 4885 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX