Commit 1e0c7ff
util: Clear FD_CLOEXEC in child instead of parent before fork
SpawnProcess cleared FD_CLOEXEC on the child's socket in the parent
before forking. Between that fcntl() and fork(), a concurrent fork+exec
on another thread would snapshot the descriptor with the close-on-exec
flag already cleared, leaking it into an unrelated child process where
it survives exec.
A leaked duplicate of the socket also prevents the parent from seeing
EOF when the spawned process exits.
Instead, keep both descriptors close-on-exec in the parent for their
entire lifetime and have the intended child clear the flag on its own
copy of the descriptor between fork() and exec().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 8550ee6 commit 1e0c7ffCopy full SHA for 1e0c7ff
1 file changed
+10-5Lines changed: 10 additions & 5 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+10-5Lines changed: 10 additions & 5 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
142 | 142 | |
143 | 143 | |
144 | 144 | |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | 145 | |
151 | 146 | |
152 | 147 | |
| ||
172 | 167 | |
173 | 168 | |
174 | 169 | |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
175 | 180 | |
176 | 181 | |
177 | 182 | |
|
0 commit comments