summaryrefslogtreecommitdiffstats
path: root/patches/logrotate-3.7.1/compressutime.patch
blob: e2da5cba2b872e5c3a32b1c255fb1a1be5faae01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Preserve mtime/atime on compression. (Closes: #286957)

--- ./logrotate.c	2005-09-03 14:07:42.000000000 +0100
+++ /tmp/dpep-work.m2M7hf/logrotate-3.7.1/logrotate.c	2005-09-03 14:08:14.000000000 +0100
@@ -12,6 +12,8 @@
 #include <time.h>
 #include <unistd.h>
 #include <glob.h>
+#include <sys/types.h>
+#include <utime.h>
 
 #ifdef WITH_SELINUX
 #include <selinux/selinux.h>
@@ -120,6 +122,7 @@
 static int compressLogFile(char * name, logInfo * log, struct stat *sb) {
     char * compressedName;
     const char ** fullCommand;
+    struct utimbuf utim;
     int inFile;
     int outFile;
     int i;
@@ -190,6 +193,12 @@
 	message(MESS_ERROR, "failed to compress log %s\n", name);
 	return 1;
     }
+   
+    utim.actime = sb->st_atime;
+    utim.modtime = sb->st_mtime;
+    utime(compressedName,&utim);
+    /* If we can't change atime/mtime, it's not a disaster.
+       It might possibly fail under SELinux. */
 
     unlink(name);