Merge 20e158f076
into d403cbd25c
This commit is contained in:
commit
86a3d785b7
9
os/log.c
9
os/log.c
|
@ -179,9 +179,10 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
|
||||||
FatalError("Cannot allocate space for the log file name\n");
|
FatalError("Cannot allocate space for the log file name\n");
|
||||||
|
|
||||||
if (backup && *backup) {
|
if (backup && *backup) {
|
||||||
|
int fd = open(logFileName, O_RDWR | O_NOFOLLOW);
|
||||||
|
if (fd != -1) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
if (fstat(fd, &buf) == 0 && S_ISREG(buf.st_mode)) {
|
||||||
if (!stat(logFileName, &buf) && S_ISREG(buf.st_mode)) {
|
|
||||||
char *suffix;
|
char *suffix;
|
||||||
char *oldLog;
|
char *oldLog;
|
||||||
|
|
||||||
|
@ -191,12 +192,14 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
|
||||||
}
|
}
|
||||||
free(suffix);
|
free(suffix);
|
||||||
|
|
||||||
if (rename(logFileName, oldLog) == -1) {
|
if (renameat(AT_FDCWD, logFileName, AT_FDCWD, oldLog) == -1) {
|
||||||
FatalError("Cannot move old log file \"%s\" to \"%s\"\n",
|
FatalError("Cannot move old log file \"%s\" to \"%s\"\n",
|
||||||
logFileName, oldLog);
|
logFileName, oldLog);
|
||||||
}
|
}
|
||||||
free(oldLog);
|
free(oldLog);
|
||||||
}
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (remove(logFileName) != 0 && errno != ENOENT) {
|
if (remove(logFileName) != 0 && errno != ENOENT) {
|
||||||
|
|
Loading…
Reference in New Issue