diff options
-rw-r--r-- | sysklogd/syslogd.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index d77fc9475..f75851085 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -648,32 +648,24 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file) | |||
648 | } | 648 | } |
649 | /* newFile == "f.0" now */ | 649 | /* newFile == "f.0" now */ |
650 | rename(log_file->path, newFile); | 650 | rename(log_file->path, newFile); |
651 | /* Incredibly, if F and F.0 are hardlinks, POSIX | ||
652 | * _demands_ that rename returns 0 but does not | ||
653 | * remove F!!! | ||
654 | * (hardlinked F/F.0 pair was observed after | ||
655 | * power failure during rename()). | ||
656 | * Ensure old file is gone: | ||
657 | */ | ||
658 | unlink(log_file->path); | ||
659 | #ifdef SYSLOGD_WRLOCK | ||
660 | fl.l_type = F_UNLCK; | ||
661 | fcntl(log_file->fd, F_SETLKW, &fl); | ||
662 | #endif | ||
663 | close(log_file->fd); | ||
664 | goto reopen; | ||
665 | } | 651 | } |
666 | 652 | ||
667 | /* We don't get here unless G.logFileRotate == 0; | 653 | /* We may or may not have just renamed the file away; |
668 | * in which case don't bother unlinking and reopening, | 654 | * if we didn't rename because we aren't keeping any backlog, |
669 | * just truncate and reset size to match: | 655 | * then it's time to clobber the file. If we did rename it..., |
656 | * incredibly, if F and F.0 are hardlinks, POSIX _demands_ | ||
657 | * that rename returns 0 but does not remove F!!! | ||
658 | * (hardlinked F/F.0 pair was observed after | ||
659 | * power failure during rename()). | ||
660 | * So ensure old file is gone in any case: | ||
670 | */ | 661 | */ |
671 | ftruncate(log_file->fd, 0); | 662 | unlink(log_file->path); |
672 | log_file->size = 0; | ||
673 | #ifdef SYSLOGD_WRLOCK | 663 | #ifdef SYSLOGD_WRLOCK |
674 | fl.l_type = F_UNLCK; | 664 | fl.l_type = F_UNLCK; |
675 | fcntl(log_file->fd, F_SETLKW, &fl); | 665 | fcntl(log_file->fd, F_SETLKW, &fl); |
676 | #endif | 666 | #endif |
667 | close(log_file->fd); | ||
668 | goto reopen; | ||
677 | } | 669 | } |
678 | log_file->size += | 670 | log_file->size += |
679 | #endif | 671 | #endif |