httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@locus.apache.org
Subject cvs commit: apache-1.3/src/support rotatelogs.c
Date Sat, 18 Nov 2000 21:57:16 GMT
wrowe       00/11/18 13:57:16

  Modified:    src      CHANGES
               src/main http_log.c
               src/support rotatelogs.c
  Log:
    Prevent churning log files when the destination volume is out of space.
  
  Submitted by:	Victor J. Orlikowski <v.j.orlikowski@gte.net>
  Reviewed by:	William Rowe
  
  Revision  Changes    Path
  1.1602    +4 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1601
  retrieving revision 1.1602
  diff -u -r1.1601 -r1.1602
  --- CHANGES	2000/11/15 02:51:49	1.1601
  +++ CHANGES	2000/11/18 21:57:14	1.1602
  @@ -1,5 +1,9 @@
   Changes with Apache 1.3.15
   
  +  *) Accomodate an out-of-space condition in the piped logs and the
  +     rotatelogs.c code, and no longer churn log processes for this
  +     condition.  [Victor J. Orlikowski]
  +
     *) Make cgi-bin work as a regular directory when using mod_vhost_alias
        with no VirtualScriptAlias directives. PR#6829 [Tony Finch]
   
  
  
  
  1.88      +2 -3      apache-1.3/src/main/http_log.c
  
  Index: http_log.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/http_log.c,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- http_log.c	2000/11/14 09:57:08	1.87
  +++ http_log.c	2000/11/18 21:57:15	1.88
  @@ -664,9 +664,8 @@
   	break;
       
       case OC_REASON_UNWRITABLE:
  -	if (pl->pid != -1) {
  -	    kill(pl->pid, SIGTERM);
  -	}
  +        /* We should not kill off the pipe here, since it may only be full.
  +         * If it really is locked, we should kill it off manually. */
   	break;
       
       case OC_REASON_RESTART:
  
  
  
  1.14      +42 -12    apache-1.3/src/support/rotatelogs.c
  
  Index: rotatelogs.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/support/rotatelogs.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- rotatelogs.c	2000/11/17 14:55:39	1.13
  +++ rotatelogs.c	2000/11/18 21:57:15	1.14
  @@ -13,17 +13,16 @@
   #include <fcntl.h>
   
   #define BUFSIZE        65536
  +#define ERRMSGSZ       82
   #ifndef MAX_PATH
   #define MAX_PATH       1024
   #endif
   
   int main (int argc, char **argv)
   {
  -    char buf[BUFSIZE], buf2[MAX_PATH];
  -    time_t tLogEnd = 0;
  -    time_t tRotation;
  -    int nLogFD = -1;
  -    int nRead;
  +    char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
  +    time_t tLogEnd = 0, tRotation;
  +    int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite;
       char *szLogRoot;
   
       if (argc != 3) {
  @@ -63,7 +62,7 @@
               if (errno != EINTR)
                   exit(4);
           if (nLogFD >= 0 && (time(NULL) >= tLogEnd || nRead < 0)) {
  -            close(nLogFD);
  +            nLogFDprev = nLogFD;
               nLogFD = -1;
           }
           if (nLogFD < 0) {
  @@ -72,15 +71,46 @@
               tLogEnd = tLogStart + tRotation;
               nLogFD = open(buf2, O_WRONLY | O_CREAT | O_APPEND, 0666);
               if (nLogFD < 0) {
  -                perror(buf2);
  -                exit(2);
  +                /* Uh-oh. Failed to open the new log file. Try to clear
  +                 * the previous log file, note the lost log entries,
  +                 * and keep on truckin'. */
  +                if (nLogFDprev == -1) {
  +                    perror(buf2);
  +                    exit(2);
  +                }
  +                else {
  +                    nLogFD = nLogFDprev;
  +                    sprintf(errbuf,
  +                            "Resetting log file due to error opening "
  +                            "new log file. %10d messages lost.\n",
  +                            nMessCount); 
  +                    nWrite = strlen(errbuf);
  +                    ftruncate(nLogFD, 0);
  +                    write(nLogFD, errbuf, nWrite);
  +                }
               }
  +            else {
  +                close(nLogFDprev);
  +            }
  +            nMessCount = 0;
           }
  -        if (write(nLogFD, buf, nRead) != nRead) {
  -            perror(buf2);
  -            exit(5);
  +        do {
  +            nWrite = write(nLogFD, buf, nRead);
  +        } while (nWrite < 0 && errno == EINTR);
  +        if (nWrite != nRead) {
  +            nMessCount++;
  +            sprintf(errbuf,
  +                    "Error writing to log file. "
  +                    "%10d messages lost.\n",
  +                    nMessCount);
  +            nWrite = strlen(errbuf);
  +            ftruncate(nLogFD, 0);
  +            write (nLogFD, errbuf, nWrite);
  +        } 
  +        else {
  +            nMessCount++; 
           }
       }
  -    /* We never get here, but surpress the compile warning */
  +    /* We never get here, but suppress the compile warning */
       return (0);
   }
  
  
  

Mime
View raw message