]> git.pld-linux.org Git - packages/logrotate.git/commitdiff
- try to update for 3.7
authorJakub Bogusz <qboosh@pld-linux.org>
Sun, 29 Feb 2004 16:22:13 +0000 (16:22 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    logrotate-dateext.dif -> 1.2
    logrotate-maxage.dif -> 1.2

logrotate-dateext.dif
logrotate-maxage.dif

index aaa681c61543b45b3930fcff91335ccc14841824..c40c7b13680676d725875fc344201b7f713caab9 100644 (file)
  This has only effect when used in combination with \fBcompress\fR.
 --- logrotate.c
 +++ logrotate.c
-@@ -10,6 +10,7 @@
- #include <sys/stat.h>
+@@ -11,6 +11,7 @@
+ #include <sys/wait.h>
  #include <time.h>
  #include <unistd.h>
 +#include <glob.h>
  
  #ifdef WITH_SELINUX
  #include <selinux/selinux.h>
-@@ -21,6 +22,10 @@
+@@ -22,6 +23,10 @@
  #include "log.h"
  #include "logrotate.h"
  
@@ -50,9 +50,9 @@
  typedef struct {
      char * fn;
      struct tm lastRotated;    /* only tm.mon, tm_mday, tm_year are good! */
-@@ -64,6 +69,14 @@
      return newstr;
- }
+@@ -42,6 +47,14 @@
char * mailCommand = DEFAULT_MAIL_COMMAND;
+ time_t nowSecs = 0;
  
 +static int globerr(const char * pathname, int theerr) {
 +    message(MESS_ERROR, "error accessing %s: %s\n", pathname, 
 +    return 1;
 +}
 +
- static logState * findState(const char * fn, logState ** statesPtr, 
-                           int * numStatesPtr) {
+ static logState * findState(const char * fn, struct stateSet * sip) {
      int i;
-@@ -72,9 +85,11 @@
+     logState * states = sip->states;
+@@ -49,9 +62,11 @@
      struct tm now = *localtime(&nowSecs);
      time_t lr_time;
  
@@ -77,7 +77,7 @@
      if (i == numStates) {
        i = numStates++;
        states = realloc(states, sizeof(*states) * numStates);
-@@ -465,6 +480,9 @@
+@@ -458,6 +473,9 @@
      char * baseName;
      char * dirName;
      char * firstRotated;
@@ -87,7 +87,7 @@
      size_t alloc_size;
      int rotateCount = log->rotateCount ? log->rotateCount : 1;
      int logStart = (log->logStart == -1) ? 1 : log->logStart;
-@@ -501,7 +519,7 @@
+@@ -488,7 +506,7 @@
  
      alloc_size = strlen(dirName) + strlen(baseName) + 
                   strlen(log->files[logNum]) + strlen(fileext) +
      
      oldName = alloca(alloc_size);
      newName = alloca(alloc_size);
-@@ -523,18 +541,95 @@
-     /* First compress the previous log when necessary */
-     if (log->flags & LOG_FLAG_COMPRESS &&
+@@ -512,27 +530,45 @@
          log->flags & LOG_FLAG_DELAYCOMPRESS) {
--      sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
--      hasErrors = compress_log(log, oldName, "previous", errorFile);
+         struct stat sbprev;
+       
+-        sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
+-        if (stat(oldName, &sbprev)) {
+-            message(MESS_DEBUG, "previous log %s does not exist\n",
+-                  oldName);
+-        } else {
+-          hasErrors = compressLogFile(oldName, log);
 +      if(log->flags & LOG_FLAG_DATEEXT) {
 +          /* glob for uncompressed files with our pattern */
 +          glob_pattern = malloc(strlen(dirName) + strlen(baseName)
 +          if (!rc && globResult.gl_pathc > 0) {
 +              for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) {
 +                  sprintf(oldName,"%s",(globResult.gl_pathv)[i]);
-+                  hasErrors = compress_log(log, oldName, "previous", errorFile);
++                  if (stat(oldName, &sbprev)) {
++                      message(MESS_DEBUG, "previous log %s does not exist\n",
++                            oldName);
++                  } else {
++                      hasErrors = compressLogFile(oldName, log);
++                  }
 +              }
 +          } else {
 +              message (MESS_DEBUG, "glob finding logs to compress failed\n");
 +          free(glob_pattern);
 +      } else {
 +          sprintf(oldName, "%s/%s.%d%s", dirName, baseName, logStart, fileext);
-+          hasErrors = compress_log(log, oldName, "previous", errorFile);
-+      }
++          if (stat(oldName, &sbprev)) {
++              message(MESS_DEBUG, "previous log %s does not exist\n",
++                    oldName);
++          } else {
++              hasErrors = compressLogFile(oldName, log);
++          }
+       }
      }
+     
+-    sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
+-            logStart + rotateCount, fileext, compext);
+-    strcpy(newName, oldName);
+-    
+-    strcpy(disposeName, oldName);
+-    
+     firstRotated = alloca(strlen(dirName) + strlen(baseName) +
+                           strlen(fileext) + strlen(compext) + 30);
+-    sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
+-            logStart, fileext, 
+-          (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
 -    
-+    firstRotated = alloca(strlen(dirName) + strlen(baseName) +
-+                        strlen(fileext) + strlen(compext) + 30);
++
+ #ifdef WITH_SELINUX
+     if ((selinux_enabled=(is_selinux_enabled()>0))) {
+       security_context_t oldContext=NULL;
+@@ -558,6 +594,98 @@
+       }
+     }
+ #endif
 +
 +    if(log->flags & LOG_FLAG_DATEEXT) {
 +      /* glob for compressed files with our pattern
 +              if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
 +                  if (i < ((int)globResult.gl_pathc - rotateCount - 1)) {
 +                      if ( mail_out != -1 ) {
-+                          if (!hasErrors && log->logAddress)
-+                              hasErrors = mail_old_log(log, logNum, NULL,
-+                                      (globResult.gl_pathv)[mail_out],
-+                                       errorFile, compext);
-+                              if (!hasErrors)
-+                                  hasErrors = remove_old_log(log,
-+                                           (globResult.gl_pathv)[mail_out],
-+                                            errorFile);
++                          if (!hasErrors && log->logAddress) {
++                              char * mailFilename;
++
++                              if(log->flags & LOG_FLAG_MAILFIRST)
++                                  mailFilename = NULL;
++                              else
++                                  mailFilename = (globResult.gl_pathv)[mail_out];
++                              if(mailFilename) {
++                                  /* if the log is compressed (and we're not mailing a
++                                     file whose compression has been delayed), we need
++                                     to uncompress it */
++                                  if ((log->flags & LOG_FLAG_COMPRESS) &&
++                                      !((log->flags & LOG_FLAG_DELAYCOMPRESS) &&
++                                        (log->flags & LOG_FLAG_MAILFIRST))) {
++                                      if (mailLog(mailFilename, mailCommand, 
++                                              log->uncompress_prog, log->logAddress, 
++                                              log->files[logNum])) 
++                                          hasErrors = 1;
++                                  } else {
++                                      if (mailLog(mailFilename, mailCommand, NULL, 
++                                          log->logAddress, mailFilename))
++                                          hasErrors = 1;
++                                  }
++                              }
++                              if (!hasErrors) {
++                                  message(MESS_DEBUG, "removing old log %s\n", 
++                                      (globResult.gl_pathv)[mail_out]);
++                                  if(!debug && unlink((globResult.gl_pathv)[mail_out])) {
++                                      message(MESS_ERROR, "Failed to remove old log %s: %s\n",
++                                          (globResult.gl_pathv)[mail_out], strerror(errno));
++                                      hasErrors = 1;
++                                  }
++                              }
++                          }
 +                      }
 +                      mail_out = i;
 +                  }
 +      free(glob_pattern);
 +    } else {
 +
-     sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
-             logStart + rotateCount, fileext, compext);
-     strcpy(newName, oldName);
-     
-     strcpy(disposeName, oldName);
-     
--    firstRotated = alloca(strlen(dirName) + strlen(baseName) +
--                          strlen(fileext) + strlen(compext) + 30);
-     sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
-             logStart, fileext, compext);
-     
-@@ -584,11 +679,27 @@
++    sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
++            logStart + rotateCount, fileext, compext);
++    strcpy(newName, oldName);
++    
++    strcpy(disposeName, oldName);
++    
++    sprintf(firstRotated, "%s/%s.%d%s%s", dirName, baseName,
++            logStart, fileext, 
++          (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
++    
+     for (i = rotateCount + logStart - 1; (i >= 0) && !hasErrors; i--) {
+         tmp = newName;
+         newName = oldName;
+@@ -579,11 +707,27 @@
            }
        }
      }
      
      /* if the last rotation doesn't exist, that's okay */
      if (!debug && access(disposeName, F_OK)) {
-@@ -597,9 +708,6 @@
+@@ -592,9 +736,6 @@
          disposeName = NULL;
      } 
      
      if (!hasErrors) {
          if (log->pre && !(log->flags & LOG_FLAG_SHAREDSCRIPTS)) {
              message(MESS_DEBUG, "running prerotate script\n");
-@@ -716,6 +824,8 @@
+@@ -740,6 +881,8 @@
          }
        }
  #endif
index 3bb15cfe906387ddf471bfc0bdfc85f0652899e9..2831e78f8486e90783e79ddc2c3903ba7c1128a3 100644 (file)
@@ -39,7 +39,7 @@
  message. See also \fBnomissingok\fR.
 --- logrotate.c
 +++ logrotate.c
-@@ -589,7 +589,10 @@
+@@ -615,7 +615,10 @@
             * the date in their name */
             for (i = 0; i < globResult.gl_pathc; i++) {
                if( !stat((globResult.gl_pathv)[i],&fst_buf) ) {
@@ -49,9 +49,9 @@
 +                          && (((nowSecs - fst_buf.st_mtime)/60/60/24)
 +                              > log->rotateAge))) {
                        if ( mail_out != -1 ) {
-                           if (!hasErrors && log->logAddress)
-                               hasErrors = mail_old_log(log, logNum, NULL,
-@@ -623,6 +626,25 @@
+                           if (!hasErrors && log->logAddress) {
+                               char * mailFilename;
+@@ -675,6 +678,49 @@
        globfree(&globResult);
        free(glob_pattern);
      } else {
 +              if(!stat(oldName,&fst_buf)
 +                  && (((nowSecs - fst_buf.st_mtime)/60/60/24)
 +                      > log->rotateAge)) {
-+                  if (!hasErrors && log->logAddress)
-+                      hasErrors = mail_old_log(log, logNum, NULL,
-+                                      (globResult.gl_pathv)[i],
-+                                      errorFile, compext);
-+                  if (!hasErrors)
-+                      hasErrors = remove_old_log(log,
-+                                      (globResult.gl_pathv)[i],
-+                                      errorFile);
++                  if (!hasErrors && log->logAddress) {
++                      char * mailFilename;
++
++                      if(log->flags & LOG_FLAG_MAILFIRST)
++                          mailFilename = NULL;
++                      else
++                          mailFilename = (globResult.gl_pathv)[i];
++                      /* if the log is compressed (and we're not mailing a
++                         file whose compression has been delayed), we need
++                         to uncompress it */
++                      if ((log->flags & LOG_FLAG_COMPRESS) &&
++                          !((log->flags & LOG_FLAG_DELAYCOMPRESS) &&
++                            (log->flags & LOG_FLAG_MAILFIRST))) {
++                          if (mailLog(mailFilename, mailCommand, 
++                                  log->uncompress_prog, log->logAddress, 
++                                  log->files[logNum])) 
++                              hasErrors = 1;
++                          } else {
++                              if (mailLog(mailFilename, mailCommand, NULL, 
++                                  log->logAddress, mailFilename))
++                              hasErrors = 1;
++                          }
++                  }
++                  if (!hasErrors) {
++                      message(MESS_DEBUG, "removing old log %s\n", 
++                          (globResult.gl_pathv)[i]);
++                      if(!debug && unlink((globResult.gl_pathv)[i])) {
++                          message(MESS_ERROR, "Failed to remove old log %s: %s\n",
++                              (globResult.gl_pathv)[i], strerror(errno));
++                          hasErrors = 1;
++                      }
++                  }
 +              }
 +          }
 +      }
  
      sprintf(oldName, "%s/%s.%d%s%s", dirName, baseName,
              logStart + rotateCount, fileext, compext);
-@@ -1110,8 +1132,10 @@
+@@ -1168,8 +1214,10 @@
  }
  
  int main(int argc, const char ** argv) {
This page took 0.104415 seconds and 4 git commands to generate.