summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch')
-rw-r--r--meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch107
1 files changed, 107 insertions, 0 deletions
diff --git a/meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch b/meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch
new file mode 100644
index 0000000000..c9fb1d2525
--- /dev/null
+++ b/meta/recipes-extended/logrotate/logrotate-3.8.1/act-as-mv-when-rotate.patch
@@ -0,0 +1,107 @@
1Act as the "mv" command when rotate log
2
3Act as the "mv" command when rotate log, first rename, if failed, then
4read and write.
5
6Upstream-Status: Pending
7
8Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
9---
10 logrotate.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
11 1 files changed, 53 insertions(+), 6 deletions(-)
12
13diff --git a/logrotate.c b/logrotate.c
14index 537e8d6..b04482f 100644
15--- a/logrotate.c
16+++ b/logrotate.c
17@@ -808,6 +808,53 @@ int findNeedRotating(struct logInfo *log, int logNum)
18 return 0;
19 }
20
21+/* Act as the "mv" command, if rename failed, then read the old file and
22+ * write to new file. The function which invokes the mvFile will use
23+ * the strerror(errorno) to handle the error message, so we don't have
24+ * to print the error message here */
25+
26+int mvFile (char *oldName, char *newName, struct logInfo *log)
27+{
28+ struct stat sbprev;
29+ int fd_old, fd_new, n;
30+ char buf[BUFSIZ];
31+
32+ /* Do the rename first */
33+ if (!rename(oldName, newName))
34+ return 0;
35+
36+ /* If the errno is EXDEV, then read old file, write newfile and
37+ * remove the oldfile */
38+ if (errno == EXDEV) {
39+ /* Open the old file to read */
40+ if ((fd_old = open(oldName, O_RDONLY)) < 0)
41+ return 1;
42+
43+ /* Create the file to write, keep the same attribute as the old file */
44+ if (stat(oldName, &sbprev))
45+ return 1;
46+ else {
47+ if ((fd_new = createOutputFile(newName,
48+ O_WRONLY | O_CREAT | O_TRUNC, &sbprev)) < 0 )
49+ return 1;
50+ }
51+
52+ /* Read and write */
53+ while ((n = read(fd_old, buf, BUFSIZ)) > 0)
54+ if (write(fd_new, buf, n) != n)
55+ return 1;
56+
57+ if ((close(fd_old) < 0) ||
58+ removeLogFile(oldName, log) ||
59+ (close(fd_new) < 0))
60+ return 1;
61+
62+ return 0;
63+ }
64+
65+ return 1;
66+}
67+
68 int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
69 struct logNames *rotNames)
70 {
71@@ -1148,15 +1195,15 @@ int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
72 rotNames->baseName, i, fileext, compext);
73
74 message(MESS_DEBUG,
75- "renaming %s to %s (rotatecount %d, logstart %d, i %d), \n",
76+ "moving %s to %s (rotatecount %d, logstart %d, i %d), \n",
77 oldName, newName, rotateCount, logStart, i);
78
79- if (!debug && rename(oldName, newName)) {
80+ if (!debug && mvFile(oldName, newName, log)) {
81 if (errno == ENOENT) {
82 message(MESS_DEBUG, "old log %s does not exist\n",
83 oldName);
84 } else {
85- message(MESS_ERROR, "error renaming %s to %s: %s\n",
86+ message(MESS_ERROR, "error moving %s to %s: %s\n",
87 oldName, newName, strerror(errno));
88 hasErrors = 1;
89 }
90@@ -1286,11 +1333,11 @@ int rotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
91 }
92 }
93 #endif /* WITH_ACL */
94- message(MESS_DEBUG, "renaming %s to %s\n", log->files[logNum],
95+ message(MESS_DEBUG, "moving %s to %s\n", log->files[logNum],
96 rotNames->finalName);
97 if (!debug && !hasErrors &&
98- rename(log->files[logNum], rotNames->finalName)) {
99- message(MESS_ERROR, "failed to rename %s to %s: %s\n",
100+ mvFile(log->files[logNum], rotNames->finalName, log)) {
101+ message(MESS_ERROR, "failed to move %s to %s: %s\n",
102 log->files[logNum], rotNames->finalName,
103 strerror(errno));
104 hasErrors = 1;
105--
1061.7.4.1
107