Commit b13b985
authored
Fix stderr closure bug in LogFile::check_fd() using fstat() (#12407)
The check_fd() function had a critical bug where it would close and reopen
log files to verify existence, which could inadvertently close stderr/stdout
when logging to these special files, breaking error reporting for the entire
process.
Fixed by replacing the unsafe access() + close/reopen pattern with fstat()
on the open file descriptor. This approach:
- Uses st_nlink == 0 to detect when regular files have been unlinked
- Never triggers for special files like stderr/stdout (they maintain st_nlink > 0)
- Eliminates string comparisons and special-case handling
- Provides universal safety across all file descriptor types
- Maintains detection of externally moved/deleted log files for rotation1 parent 5b0d86c commit b13b985
2 files changed
Lines changed: 30 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
715 | | - | |
716 | | - | |
| 715 | + | |
| 716 | + | |
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
733 | 733 | | |
734 | | - | |
735 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
736 | 757 | | |
737 | 758 | | |
738 | 759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 261 | + | |
0 commit comments