Act as the "mv" command when rotate log, first rename, if failed, then
read and write.
-Upstream-Status: Pending
+Upstream-Status: Submitted
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
- logrotate.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
- 1 files changed, 53 insertions(+), 6 deletions(-)
+ logrotate.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
+ 1 file changed, 56 insertions(+), 9 deletions(-)
diff --git a/logrotate.c b/logrotate.c
-index 537e8d6..b04482f 100644
+index 174a26b..b18b629 100644
--- a/logrotate.c
+++ b/logrotate.c
-@@ -808,6 +808,53 @@ int findNeedRotating(struct logInfo *log, int logNum)
+@@ -906,6 +906,53 @@ int findNeedRotating(struct logInfo *log, int logNum, int force)
return 0;
}
+ * the strerror(errorno) to handle the error message, so we don't have
+ * to print the error message here */
+
-+int mvFile (char *oldName, char *newName, struct logInfo *log)
++int mvFile (char *oldName, char *newName, struct logInfo *log, acl_type acl)
+{
+ struct stat sbprev;
+ int fd_old, fd_new, n;
+ return 1;
+ else {
+ if ((fd_new = createOutputFile(newName,
-+ O_WRONLY | O_CREAT | O_TRUNC, &sbprev)) < 0 )
++ O_WRONLY | O_CREAT | O_TRUNC, &sbprev, acl, 0)) < 0 )
+ return 1;
+ }
+
int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
struct logNames *rotNames)
{
-@@ -1148,15 +1195,15 @@ int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
- rotNames->baseName, i, fileext, compext);
+@@ -1268,15 +1315,15 @@ int prerotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
+ }
message(MESS_DEBUG,
- "renaming %s to %s (rotatecount %d, logstart %d, i %d), \n",
oldName, newName, rotateCount, logStart, i);
- if (!debug && rename(oldName, newName)) {
-+ if (!debug && mvFile(oldName, newName, log)) {
++ if (!debug && mvFile(oldName, newName, log, prev_acl)) {
if (errno == ENOENT) {
message(MESS_DEBUG, "old log %s does not exist\n",
oldName);
oldName, newName, strerror(errno));
hasErrors = 1;
}
-@@ -1286,11 +1333,11 @@ int rotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
+@@ -1408,11 +1455,11 @@ int rotateSingleLog(struct logInfo *log, int logNum, struct logState *state,
}
}
#endif /* WITH_ACL */
if (!debug && !hasErrors &&
- rename(log->files[logNum], rotNames->finalName)) {
- message(MESS_ERROR, "failed to rename %s to %s: %s\n",
-+ mvFile(log->files[logNum], rotNames->finalName, log)) {
++ mvFile(log->files[logNum], rotNames->finalName, log, prev_acl)) {
+ message(MESS_ERROR, "failed to move %s to %s: %s\n",
log->files[logNum], rotNames->finalName,
strerror(errno));
hasErrors = 1;
+@@ -1775,7 +1822,7 @@ int rotateLogSet(struct logInfo *log, int force)
+ return hasErrors;
+ }
+
+-static int writeState(char *stateFilename)
++static int writeState(struct logInfo *log, char *stateFilename)
+ {
+ struct logState *p;
+ FILE *f;
+@@ -1939,7 +1986,7 @@ static int writeState(char *stateFilename)
+ fclose(f);
+
+ if (error == 0) {
+- if (rename(tmpFilename, stateFilename)) {
++ if (mvFile(tmpFilename, stateFilename, log, prev_acl)) {
+ unlink(tmpFilename);
+ error = 1;
+ message(MESS_ERROR, "error renaming temp state file %s\n",
+@@ -2223,7 +2270,7 @@ int main(int argc, const char **argv)
+ rc |= rotateLogSet(log, force);
+
+ if (!debug)
+- rc |= writeState(stateFile);
++ rc |= writeState(log, stateFile);
+
+ return (rc != 0);
+ }
--
-1.7.4.1
+1.7.10.4
Update the manual
-* Update the mannual
-* Fix a bug in the mannual(\f should be \fR)
+Update the manual for rotating on different filesystems.
-Upstream-Status: Pending
+Upstream-Status: Submitted
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
- logrotate.8 | 9 ++++-----
- 1 files changed, 4 insertions(+), 5 deletions(-)
+ logrotate.8 | 7 +++----
+ 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/logrotate.8 b/logrotate.8
index 8b34167..5f15432 100644
overridden by the \fBnoolddir\fR option.
.TP
-@@ -435,7 +434,7 @@ Log files are rotated only if they grow bigger then \fIsize\fR bytes. If
- \fIsize\fR is followed by \fIk\fR, the size is assumed to be in kilobytes.
- If the \fIM\fR is used, the size is in megabytes, and if \fIG\fR is used, the
- size is in gigabytes. So \fBsize 100\fR, \fIsize 100k\fR, \fIsize 100M\fR and
--\fIsize 100G\f are all valid.
-+\fIsize 100G\fR are all valid.
-
- .TP
- \fBsharedscripts\fR
--
1.7.4.1