#! /bin/sh -e ## 72-dateext-highresolution.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: uses time format yyyyMMddhhmmss instead of yyyyMMdd if [ $# -lt 1 ]; then echo "`basename $0`: script expects -patch|-unpatch as argument" >&2 exit 1 fi [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}" case "$1" in -patch) patch -p1 ${patch_opts} < $0;; -unpatch) patch -R -p1 ${patch_opts} < $0;; *) echo "`basename $0`: script expects -patch|-unpatch as argument" >&2 exit 1;; esac exit 0 @DPATCH@ diff -urNad logrotate-3.7/logrotate.c /tmp/dpep.DDnyTe/logrotate-3.7/logrotate.c --- logrotate-3.7/logrotate.c 2005-05-09 14:42:48.000000000 +0300 +++ /tmp/dpep.DDnyTe/logrotate-3.7/logrotate.c 2005-05-09 14:42:48.000000000 +0300 @@ -77,6 +77,9 @@ states[i].lastRotated.tm_mon = now.tm_mon; states[i].lastRotated.tm_mday = now.tm_mday; states[i].lastRotated.tm_year = now.tm_year; + states[i].lastRotated.tm_hour = now.tm_hour; + states[i].lastRotated.tm_min = now.tm_min; + states[i].lastRotated.tm_sec = now.tm_sec; /* fill in the rest of the st->lastRotated fields */ lr_time = mktime(&states[i].lastRotated); @@ -448,14 +451,23 @@ (state->lastRotated.tm_year == now.tm_year && (state->lastRotated.tm_mon > now.tm_mon || (state->lastRotated.tm_mon == now.tm_mon && - state->lastRotated.tm_mday > now.tm_mday)))) { + (state->lastRotated.tm_mday > now.tm_mday || + (state->lastRotated.tm_mday == now.tm_mday && + (state->lastRotated.tm_hour > now.tm_hour || + (state->lastRotated.tm_hour == now.tm_hour && + (state->lastRotated.tm_min > now.tm_min || + (state->lastRotated.tm_min == now.tm_min && + (state->lastRotated.tm_sec > now.tm_sec ))))))))))) { message(MESS_ERROR, "log %s last rotated in the future -- rotation forced\n", log->files[logNum]); state->doRotate = 1; } else if (state->lastRotated.tm_year != now.tm_year || state->lastRotated.tm_mon != now.tm_mon || - state->lastRotated.tm_mday != now.tm_mday) { + state->lastRotated.tm_mday != now.tm_mday || + state->lastRotated.tm_hour != now.tm_hour || + state->lastRotated.tm_min != now.tm_min || + state->lastRotated.tm_sec != now.tm_sec) { switch (log->criterium) { case ROT_WEEKLY: /* rotate if: @@ -572,9 +584,9 @@ if (log->flags & LOG_FLAG_DATEEXT) { /* glob for uncompressed files with our pattern */ glob_pattern = malloc(strlen(dirName) + strlen(baseName) - + strlen(fileext) + 44 ); + + strlen(fileext) + 73 ); // this should -at least- be the size of the string below + 1 /can@parkyeri sprintf(glob_pattern, - "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s", + "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s", dirName, baseName, fileext); rc = glob(glob_pattern, 0, globerr, &globResult); if (!rc && globResult.gl_pathc > 0) { @@ -609,9 +621,9 @@ /* glob for compressed files with our pattern * and compress ext */ glob_pattern = malloc(strlen(dirName)+strlen(baseName) - +strlen(fileext)+strlen(compext)+44); + +strlen(fileext)+strlen(compext)+73); sprintf(glob_pattern, - "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s%s", + "%s/%s-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%s%s", dirName, baseName, fileext, compext); rc = glob(glob_pattern, 0, globerr, &globResult); if (!rc) { @@ -649,9 +661,9 @@ disposeName = NULL; } /* firstRotated is most recently created/compressed rotated log */ - sprintf(firstRotated, "%s/%s-%04d%02d%02d%s%s", + sprintf(firstRotated, "%s/%s-%04d%02d%02d%02d%02d%02d%s%s", dirName, baseName, now.tm_year+1900, - now.tm_mon+1, now.tm_mday, fileext, compext); + now.tm_mon+1, now.tm_mday, now.tm_hour + 1, now.tm_min + 1, now.tm_sec + 1, fileext, compext); globfree(&globResult); free(glob_pattern); } else { @@ -720,9 +732,13 @@ char * destFile = alloca(strlen(dirName) + strlen(baseName) + strlen(fileext) + strlen(compext) + 30); struct stat fst_buf; - sprintf(finalName, "%s/%s-%04d%02d%02d%s", + + //+1 makes the output readable by human. + //ie. January is represented by 0, February by 1 etc. (see: `man localtime`) + // |y | m | d | h | m | s | + sprintf(finalName, "%s/%s-%04d%02d%02d%02d%02d%02d%s", dirName, baseName, now.tm_year+1900, - now.tm_mon+1, now.tm_mday, fileext); + now.tm_mon+1, now.tm_mday, now.tm_hour + 1, now.tm_min + 1, now.tm_sec + 1, fileext); sprintf(destFile, "%s%s", finalName, compext); if(!stat(destFile,&fst_buf)) { message (MESS_DEBUG, "destination %s already exists, skipping rotation\n", firstRotated);