diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2012-03-06 09:03:11 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-08 11:55:35 -0800 |
commit | d7663ff7ab2e5ef5c913befad5e0adfbd6cc22a2 (patch) | |
tree | c2826833d18f69146ac6a4e1ae1aaa409a4fb0df /meta/recipes-extended/logrotate | |
parent | 2129519e346f321abcf32f8107dd6f60a96e69aa (diff) | |
download | poky-d7663ff7ab2e5ef5c913befad5e0adfbd6cc22a2.tar.gz |
logrotate 3.7.9: Allow rotate log across filesystems
The logrotate can't save the log across the different filesystems since
it used the "rename(const char *oldpath, const char *newpath)" to save
the file, fix it to act as the "mv" command(first rename, if failed,
read and write) to allow save the log across the different filesystems.
* config.c: Remove the check for different filesystems
* logrotate.c: Act as the "mv" command when rotate log
* logrotate.8: Update the mannual
* logrotate.8: Fix a bug in the mannual(\f should be \fR)
[YOCTO #718]
(From OE-Core rev: fca0a2c597ab40d55da768dac4088234b9b0d773)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-extended/logrotate')
-rw-r--r-- | meta/recipes-extended/logrotate/logrotate-3.7.9/allow-across-different-filesystems.patch | 154 | ||||
-rw-r--r-- | meta/recipes-extended/logrotate/logrotate_3.7.9.bb | 5 |
2 files changed, 157 insertions, 2 deletions
diff --git a/meta/recipes-extended/logrotate/logrotate-3.7.9/allow-across-different-filesystems.patch b/meta/recipes-extended/logrotate/logrotate-3.7.9/allow-across-different-filesystems.patch new file mode 100644 index 0000000000..41df23f997 --- /dev/null +++ b/meta/recipes-extended/logrotate/logrotate-3.7.9/allow-across-different-filesystems.patch | |||
@@ -0,0 +1,154 @@ | |||
1 | Allow rotate log across different filesystems | ||
2 | |||
3 | * Remove the check for different filesystems | ||
4 | * Act as the "mv" command when rotate log | ||
5 | * Update the mannual | ||
6 | * Fix a bug in the mannual(\f should be \fR) | ||
7 | |||
8 | Upstream-Status: Pending | ||
9 | |||
10 | Signed-off-by: Robert Yang <liezhi.yang@windriver.com> | ||
11 | --- | ||
12 | config.c | 8 -------- | ||
13 | logrotate.8 | 9 ++++----- | ||
14 | logrotate.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ | ||
15 | 3 files changed, 57 insertions(+), 19 deletions(-) | ||
16 | |||
17 | diff --git a/config.c b/config.c | ||
18 | --- a/config.c | ||
19 | +++ b/config.c | ||
20 | @@ -1482,14 +1482,6 @@ duperror: | ||
21 | dirName, strerror(errno)); | ||
22 | goto error; | ||
23 | } | ||
24 | - | ||
25 | - if (sb.st_dev != sb2.st_dev) { | ||
26 | - message(MESS_ERROR, | ||
27 | - "%s:%d olddir %s and log file %s " | ||
28 | - "are on different devices\n", configFile, | ||
29 | - lineNum, newlog->oldDir, newlog->files[i]); | ||
30 | - goto error; | ||
31 | - } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | diff --git a/logrotate.8 b/logrotate.8 | ||
36 | --- a/logrotate.8 | ||
37 | +++ b/logrotate.8 | ||
38 | @@ -354,10 +354,9 @@ Do not rotate the log if it is empty (this overrides the \fBifempty\fR option). | ||
39 | .TP | ||
40 | \fBolddir \fIdirectory\fR | ||
41 | Logs are moved into \fIdirectory\fR for rotation. The \fIdirectory\fR | ||
42 | -must be on the same physical device as the log file being rotated, | ||
43 | -and is assumed to be relative to the directory holding the log file | ||
44 | -unless an absolute path name is specified. When this option is used all | ||
45 | -old versions of the log end up in \fIdirectory\fR. This option may be | ||
46 | +is assumed to be relative to the directory holding the log file unless | ||
47 | +an absolute path name is specified. When this option is used all old | ||
48 | +versions of the log end up in \fIdirectory\fR. This option may be | ||
49 | overridden by the \fBnoolddir\fR option. | ||
50 | |||
51 | .TP | ||
52 | @@ -415,7 +414,7 @@ Log files are rotated when they grow bigger than \fIsize\fR bytes. If | ||
53 | \fIsize\fR is followed by \fIk\fR, the size is assumed to be in kilobytes. | ||
54 | If the \fIM\fR is used, the size is in megabytes, and if \fIG\fR is used, the | ||
55 | size is in gigabytes. So \fBsize 100\fR, \fIsize 100k\fR, \fIsize 100M\fR and | ||
56 | -\fIsize 100G\f are all valid. | ||
57 | +\fIsize 100G\fR are all valid. | ||
58 | |||
59 | .TP | ||
60 | \fBsharedscripts\fR | ||
61 | diff --git a/logrotate.c b/logrotate.c | ||
62 | --- a/logrotate.c | ||
63 | +++ b/logrotate.c | ||
64 | @@ -625,6 +625,53 @@ int findNeedRotating(struct logInfo *log, int logNum) | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | +/* Act as the "mv" command, if rename failed, then read the old file and | ||
69 | + * write to new file. The function which invokes the mvFile will use | ||
70 | + * the strerror(errorno) to handle the error message, so we don't have | ||
71 | + * to print the error message here */ | ||
72 | + | ||
73 | +int mvFile (char *oldName, char *newName, struct logInfo *log) | ||
74 | +{ | ||
75 | + struct stat sbprev; | ||
76 | + int fd_old, fd_new, n; | ||
77 | + char buf[BUFSIZ]; | ||
78 | + | ||
79 | + /* Do the rename first */ | ||
80 | + if (!rename(oldName, newName)) | ||
81 | + return 0; | ||
82 | + | ||
83 | + /* If the errno is EXDEV, then read old file, write newfile and | ||
84 | + * remove the oldfile */ | ||
85 | + if (errno == EXDEV) { | ||
86 | + /* Open the old file to read */ | ||
87 | + if ((fd_old = open(oldName, O_RDONLY)) < 0) | ||
88 | + return 1; | ||
89 | + | ||
90 | + /* Create the file to write, keep the same attribute as the old file */ | ||
91 | + if (stat(oldName, &sbprev)) | ||
92 | + return 1; | ||
93 | + else { | ||
94 | + if ((fd_new = createOutputFile(newName, | ||
95 | + O_WRONLY | O_CREAT | O_TRUNC, &sbprev)) < 0 ) | ||
96 | + return 1; | ||
97 | + } | ||
98 | + | ||
99 | + /* Read and write */ | ||
100 | + while ((n = read(fd_old, buf, BUFSIZ)) > 0) | ||
101 | + if (write(fd_new, buf, n) != n) | ||
102 | + return 1; | ||
103 | + | ||
104 | + if ((close(fd_old) < 0) || | ||
105 | + removeLogFile(oldName, log) || | ||
106 | + (close(fd_new) < 0)) | ||
107 | + return 1; | ||
108 | + | ||
109 | + return 0; | ||
110 | + } | ||
111 | + | ||
112 | + return 1; | ||
113 | +} | ||
114 | + | ||
115 | int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state, | ||
116 | struct logNames *rotNames) | ||
117 | { | ||
118 | @@ -958,15 +1005,15 @@ int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state, | ||
119 | rotNames->baseName, i, fileext, compext); | ||
120 | |||
121 | message(MESS_DEBUG, | ||
122 | - "renaming %s to %s (rotatecount %d, logstart %d, i %d), \n", | ||
123 | + "moving %s to %s (rotatecount %d, logstart %d, i %d), \n", | ||
124 | oldName, newName, rotateCount, logStart, i); | ||
125 | |||
126 | - if (!debug && rename(oldName, newName)) { | ||
127 | + if (!debug && mvFile(oldName, newName, log)) { | ||
128 | if (errno == ENOENT) { | ||
129 | message(MESS_DEBUG, "old log %s does not exist\n", | ||
130 | oldName); | ||
131 | } else { | ||
132 | - message(MESS_ERROR, "error renaming %s to %s: %s\n", | ||
133 | + message(MESS_ERROR, "error moving %s to %s: %s\n", | ||
134 | oldName, newName, strerror(errno)); | ||
135 | hasErrors = 1; | ||
136 | } | ||
137 | @@ -1082,11 +1129,11 @@ int rotateSingleLog(struct logInfo *log, int logNum, struct logState *state, | ||
138 | log->files[logNum]); | ||
139 | } | ||
140 | #endif | ||
141 | - message(MESS_DEBUG, "renaming %s to %s\n", log->files[logNum], | ||
142 | + message(MESS_DEBUG, "moving %s to %s\n", log->files[logNum], | ||
143 | rotNames->finalName); | ||
144 | if (!debug && !hasErrors && | ||
145 | - rename(log->files[logNum], rotNames->finalName)) { | ||
146 | - message(MESS_ERROR, "failed to rename %s to %s: %s\n", | ||
147 | + mvFile(log->files[logNum], rotNames->finalName, log)) { | ||
148 | + message(MESS_ERROR, "failed to move %s to %s: %s\n", | ||
149 | log->files[logNum], rotNames->finalName, | ||
150 | strerror(errno)); | ||
151 | hasErrors = 1; | ||
152 | -- | ||
153 | 1.7.4.1 | ||
154 | |||
diff --git a/meta/recipes-extended/logrotate/logrotate_3.7.9.bb b/meta/recipes-extended/logrotate/logrotate_3.7.9.bb index 8dc0504cfb..40d1a38eab 100644 --- a/meta/recipes-extended/logrotate/logrotate_3.7.9.bb +++ b/meta/recipes-extended/logrotate/logrotate_3.7.9.bb | |||
@@ -2,13 +2,14 @@ DESCRIPTION = "Rotates, compresses, removes and mails system log files" | |||
2 | SECTION = "console/utils" | 2 | SECTION = "console/utils" |
3 | HOMEPAGE = "https://fedorahosted.org/releases/l/o/logrotate" | 3 | HOMEPAGE = "https://fedorahosted.org/releases/l/o/logrotate" |
4 | LICENSE = "GPLv2" | 4 | LICENSE = "GPLv2" |
5 | PR = "r1" | 5 | PR = "r2" |
6 | 6 | ||
7 | DEPENDS="coreutils popt" | 7 | DEPENDS="coreutils popt" |
8 | 8 | ||
9 | LIC_FILES_CHKSUM = "file://COPYING;md5=18810669f13b87348459e611d31ab760" | 9 | LIC_FILES_CHKSUM = "file://COPYING;md5=18810669f13b87348459e611d31ab760" |
10 | 10 | ||
11 | SRC_URI = "https://fedorahosted.org/releases/l/o/logrotate/logrotate-${PV}.tar.gz" | 11 | SRC_URI = "https://fedorahosted.org/releases/l/o/logrotate/logrotate-${PV}.tar.gz \ |
12 | file://allow-across-different-filesystems.patch" | ||
12 | 13 | ||
13 | SRC_URI[md5sum] = "eeba9dbca62a9210236f4b83195e4ea5" | 14 | SRC_URI[md5sum] = "eeba9dbca62a9210236f4b83195e4ea5" |
14 | SRC_URI[sha256sum] = "080caf904e70e04da16b8dfa95a5a787ec7d722ee1af18ccea437d3ffdd6fec0" | 15 | SRC_URI[sha256sum] = "080caf904e70e04da16b8dfa95a5a787ec7d722ee1af18ccea437d3ffdd6fec0" |