diff -Nru logrotate-3.8.7/debian/changelog logrotate-3.8.7/debian/changelog --- logrotate-3.8.7/debian/changelog 2017-03-22 07:43:44.000000000 -0400 +++ logrotate-3.8.7/debian/changelog 2017-08-09 15:56:52.000000000 -0400 @@ -1,3 +1,11 @@ +logrotate (3.8.7-1ubuntu1.2) trusty; urgency=medium + + * logrotate does not ever recover from a corrupted statefile (LP: #1709670) + - d/p/do-not-treat-failure-of-readState-as-fatal.patch + (Backported from commit b9d82003002c98370e4131a7e43c76afcd23306a) + + -- Eric Desrochers Wed, 09 Aug 2017 15:55:36 -0400 + logrotate (3.8.7-1ubuntu1.1) trusty; urgency=medium * createOutputFile: rename already existing file (LP: #1630516) diff -Nru logrotate-3.8.7/debian/patches/do-not-treat-failure-of-readState-as-fatal.patch logrotate-3.8.7/debian/patches/do-not-treat-failure-of-readState-as-fatal.patch --- logrotate-3.8.7/debian/patches/do-not-treat-failure-of-readState-as-fatal.patch 1969-12-31 19:00:00.000000000 -0500 +++ logrotate-3.8.7/debian/patches/do-not-treat-failure-of-readState-as-fatal.patch 2017-08-09 15:53:31.000000000 -0400 @@ -0,0 +1,108 @@ +Description: do not treat failure of readState() as fatal + + This also prevents an empty state file from being written when running + with the --debug option. + + Closes #45 + +Author: Kamil Dudka +Origin: upstream, https://github.com/logrotate/logrotate/commit/b9d82003002c98370e4131a7e43c76afcd23306a +Bug: https://github.com/logrotate/logrotate/issues/45 +Bug-Ubuntu: https://bugs.launchpad.net/bugs/1709670 +Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871592 +Index: logrotate-3.8.7/logrotate.c +=================================================================== +--- logrotate-3.8.7.orig/logrotate.c ++++ logrotate-3.8.7/logrotate.c +@@ -1999,27 +1999,43 @@ static int readState(char *stateFilename + struct logState *st; + time_t lr_time; + struct stat f_stat; ++ int rc = 0; + + error = stat(stateFilename, &f_stat); + +- if ((error && errno == ENOENT) || (!error && f_stat.st_size == 0)) { +- /* create the file before continuing to ensure we have write +- access to the file */ +- f = fopen(stateFilename, "w"); +- if (!f) { +- message(MESS_ERROR, "error creating state file %s: %s\n", +- stateFilename, strerror(errno)); +- return 1; +- } +- fprintf(f, "logrotate state -- version 2\n"); +- fclose(f); +- return 0; +- } else if (error) { +- message(MESS_ERROR, "error stat()ing state file %s: %s\n", +- stateFilename, strerror(errno)); +- return 1; ++ if (error) { ++ /* treat non-statable file as an empty file */ ++ f_stat.st_size = 0; ++ if (errno != ENOENT) { ++ message(MESS_ERROR, "error stat()ing state file %s: %s\n", ++ stateFilename, strerror(errno)); ++ ++ /* do not return until the hash table is allocated */ ++ rc = 1; ++ } ++ } ++ ++ if (!debug && (f_stat.st_size == 0)) { ++ /* create the file before continuing to ensure we have write ++ access to the file */ ++ f = fopen(stateFilename, "w"); ++ if (f) { ++ fprintf(f, "logrotate state -- version 2\n"); ++ fclose(f); ++ } else { ++ message(MESS_ERROR, "error creating state file %s: %s\n", ++ stateFilename, strerror(errno)); ++ ++ /* do not return until the hash table is allocated */ ++ rc = 1; ++ } + } + ++ ++ if (rc || (f_stat.st_size == 0)) ++ /* error already occurred, or we have no state file to read from */ ++ return rc; ++ + f = fopen(stateFilename, "r"); + if (!f) { + message(MESS_ERROR, "error opening state file %s: %s\n", +@@ -2242,7 +2258,7 @@ int main(int argc, const char **argv) + return 1; + + if (readState(stateFile)) +- exit(1); ++ rc = 1; + + message(MESS_DEBUG, "\nHandling %d logs\n", numLogs); + +Index: logrotate-3.8.7/test/test +=================================================================== +--- logrotate-3.8.7.orig/test/test ++++ logrotate-3.8.7/test/test +@@ -1138,8 +1138,7 @@ EOF + cleanup 46 + + # ------------------------------- Test 46 ------------------------------------ +-# the state file is truncated and obviously corrupt, so no rotation should +-# happen ++# the state file is truncated and obviously corrupt + preptest test.log 46 1 + + cat > state << EOF +@@ -1160,7 +1159,7 @@ fi + rm -f error.log + + checkoutput < Last-Update: 2017-03-22 -diff --git a/logrotate.c b/logrotate.c -index 10f4b52..79f4755 100644 ---- a/logrotate.c -+++ b/logrotate.c -@@ -366,11 +366,18 @@ static int runScript(struct logInfo *log, char *logfn, char *script) +Index: logrotate-3.8.7/logrotate.c +=================================================================== +--- logrotate-3.8.7.orig/logrotate.c ++++ logrotate-3.8.7/logrotate.c +@@ -299,11 +299,18 @@ static int runScript(struct logInfo *log int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, int force_mode) { @@ -39,7 +39,7 @@ /* the destination file already exists, while it should not */ struct tm now = *localtime(&nowSecs); size_t fileName_size = strlen(fileName); -@@ -384,11 +391,9 @@ int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, i +@@ -317,11 +324,9 @@ int createOutputFile(char *fileName, int fileName, backupName, strerror(errno)); return -1; } @@ -52,6 +52,3 @@ if (fd < 0) { message(MESS_ERROR, "error creating output file %s: %s\n", fileName, strerror(errno)); --- -2.7.4 -