This commit is contained in:
Collin 2025-07-05 01:25:47 +05:30 committed by GitHub
commit 86a3d785b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -179,9 +179,10 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
FatalError("Cannot allocate space for the log file name\n");
if (backup && *backup) {
int fd = open(logFileName, O_RDWR | O_NOFOLLOW);
if (fd != -1) {
struct stat buf;
if (!stat(logFileName, &buf) && S_ISREG(buf.st_mode)) {
if (fstat(fd, &buf) == 0 && S_ISREG(buf.st_mode)) {
char *suffix;
char *oldLog;
@ -191,12 +192,14 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
}
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",
logFileName, oldLog);
}
free(oldLog);
}
close(fd);
}
}
else {
if (remove(logFileName) != 0 && errno != ENOENT) {