Commit 8406beb
committed
Close non-stdio file handles when daemonizing
Otherwise, when the compiler wrapper spawns the sccache server, the
server may end up with unintended file descriptors, which can lead to
unexpected problems.
This is particularly problematic if any of those file descriptors that
accidentally end up in the server process is a pipe, as the pipe will
only be closed when all the processes with that file descriptor close it
or exit.
This was causing sccache to hang ninja, as ninja uses the EOF of a pipe
given to the subprocess to detect when that subprocess has exited:
ninja-build/ninja#2444 (comment)
This patch adds a dependency on the
[close_fds](https://crates.io/crates/close_fds) crate, which
automatically chooses an appropriate mechanism to close a range of file
descriptors. On Linux 5.9+ that mechanism will be libc::close_range().
Fixes #23131 parent bf49d4c commit 8406beb
File tree
5 files changed
+31
-24
lines changed- src
- bin/sccache-dist
5 files changed
+31
-24
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | 129 | | |
140 | 130 | | |
141 | 131 | | |
| |||
165 | 155 | | |
166 | 156 | | |
167 | 157 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | 158 | | |
176 | 159 | | |
177 | 160 | | |
| |||
654 | 637 | | |
655 | 638 | | |
656 | 639 | | |
| 640 | + | |
657 | 641 | | |
658 | 642 | | |
| 643 | + | |
659 | 644 | | |
660 | | - | |
661 | | - | |
| 645 | + | |
662 | 646 | | |
663 | 647 | | |
664 | | - | |
| 648 | + | |
665 | 649 | | |
666 | 650 | | |
667 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
844 | | - | |
| 844 | + | |
845 | 845 | | |
846 | 846 | | |
847 | 847 | | |
| |||
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
853 | | - | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
854 | 865 | | |
855 | 866 | | |
856 | 867 | | |
| |||
928 | 939 | | |
929 | 940 | | |
930 | 941 | | |
931 | | - | |
| 942 | + | |
932 | 943 | | |
933 | 944 | | |
934 | 945 | | |
| |||
0 commit comments