/[inetutils]/inetutils/syslogd/syslogd.c
ViewVC logotype

Diff of /inetutils/syslogd/syslogd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.66 by gray, Mon Sep 2 15:59:50 2002 UTC revision 1.67 by gray, Mon Sep 30 13:55:11 2002 UTC
# Line 668  main (int argc, char *argv[]) Line 668  main (int argc, char *argv[])
668                  continue;                  continue;
669              else if (fdarray[i].fd == fklog)              else if (fdarray[i].fd == fklog)
670                {                {
671                  /* Set to 1 if the kline possibly contains a log message.  */                  result = read (fdarray[i].fd, &kline[kline_len],
672                  int log_kline = 0;                                 sizeof (kline) - kline_len - 1);
673    
674                  /*dbg_printf ("klog message\n");*/                  if (result > 0)
   
                 if (kline_len == sizeof (kline) - 1)  
675                    {                    {
676                      /* We are trying to find the end of an earlier                      kline_len += result;
                        logged partial line.  */  
   
                     result = read (fdarray[i].fd, kline, sizeof (kline) - 1);  
                     if (result > 0)  
                       {  
                         char *eol;  
   
                         kline[result] = '\0';  
                         eol = strchr (kline, '\n');  
                         if (eol)  
                           {  
                             eol++;  
                             kline_len = result - (eol - kline);  
                             memmove (kline, eol, kline_len);  
                             log_kline = 1;  
                           }  
                       }  
                     else if (result < 0 && errno != EINTR)  
                       {  
                         logerror ("klog");  
                         fdarray[i].fd = fklog = -1;  
                       }  
677                    }                    }
678                  else                  else if (result < 0 && errno != EINTR)
679                    {                    {
680                      result = read (fdarray[i].fd, &kline[kline_len],                      logerror ("klog");
681                                     sizeof (kline) - kline_len - 1);                      fdarray[i].fd = fklog = -1;
   
                     if (result > 0)  
                       {  
                         kline_len += result;  
                         log_kline = 1;  
                       }  
                     else if (result < 0 && errno != EINTR)  
                       {  
                         logerror ("klog");  
                         fdarray[i].fd = fklog = -1;  
                       }  
682                    }                    }
683    
684                  if (log_kline)                  while (1)
685                    {                    {
686                      char *bol, *eol;                      char *bol, *eol;
687                        
688                      kline[kline_len] = '\0';                      kline[kline_len] = '\0';
689    
690                      for (bol = kline, eol = strchr (kline, '\n'); eol;                      for (bol = kline, eol = strchr (kline, '\n'); eol;
691                           bol = eol, eol = strchr (bol, '\n'))                           bol = eol, eol = strchr (bol, '\n'))
692                        {                        {
# Line 728  main (int argc, char *argv[]) Line 694  main (int argc, char *argv[])
694                          kline_len -= (eol - bol);                          kline_len -= (eol - bol);
695                          printsys (bol);                          printsys (bol);
696                        }                        }
697                      if (*bol)  
698                        /* Log the beginning of a partial line.  */                      /* This loop makes sure the daemon won't lock up
699                        printsys (bol);                       * on null bytes in the klog stream.  They still hurt
700                         * efficiency, acting like a message separator that
701                         * forces a shift-and-reiterate when the buffer was
702                         * never full.
703                         */
704                        while (kline_len && !*bol)
705                          {
706                            bol++;
707                            kline_len--;
708                          }
709    
710                        if (!kline_len)
711                          break;
712    
713                        if (bol != kline)
714                          {
715                            /* shift the partial line to start of buffer, so
716                             * we can re-iterate.
717                             */
718                            memmove (kline, bol, kline_len);
719                          }
720                        else
721                          {
722                            if (kline_len < MAXLINE)
723                              break;
724    
725                            /* The pathological case of a single message that
726                             * overfills our buffer.  The best we can do is
727                             * log it in pieces.
728                             */
729                            printsys (kline);
730    
731                            /* Clone priority signal if present
732                             * We merely shift the kline_len pointer after
733                             * it so the next chunk is written after it.
734                             *
735                             * strchr(kline,'>') is not used as it would allow
736                             * a pathological line ending in '>' to cause an
737                             * endless loop.
738                             */
739                            if (kline[0] == '<'
740                                && isdigit (kline[1]) && kline[2] == '>')
741                              kline_len = 3;
742                            else
743                              kline_len = 0;
744                          }
745                    }                    }
746                }                }
747              else if (fdarray[i].fd == finet)              else if (fdarray[i].fd == finet)

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.67

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26