Commit 42770de
committed
qemu-static: document cleanup-ordering invariant for LOCK_SH inheritance
Codex reviewer flagged a real fragility in the simplified design: BSD
flock is per-OFD, so a forked subshell inheriting our LOCK_SH fd shares
the same lock entry. Closing the parent's fd does not release the lock
while any inheriting child remains alive. If our cleanup handler ran
before the build's other subshell-killing handlers, the LOCK_EX-LOCK_NB
last-out probe could falsely block on our own stale child and skip the
restore — leaving qemu-arm globally disabled.
In practice this does not manifest because Armbian's add_cleanup_handler
runs registrations in order, and the umount/SDCARD/MOUNT teardown
handlers (registered earlier) execute mount(8)/umount(8) subprocesses
that finish before returning. By the time our handler runs, the docker
container has been killed and its mount-bound children with it.
SIGINT-during-image-late-apt-install was empirically verified to clean
up correctly: last-out fires, qemu-arm restored, no stale state.
Document the dependency so a future refactor of cleanup ordering does
not silently break the invariant. Note POSIX F_SETLK and explicit
descendant-kill as alternative fixes if the ordering becomes hard to
guarantee, with their respective footguns called out (POSIX releases
all locks on the file when the process closes any fd to it, including
shell builtin redirects like `echo 0 > file`).
Assisted-by: Claude:claude-opus-4.71 parent fe2733b commit 42770de
1 file changed
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
293 | 324 | | |
294 | 325 | | |
295 | 326 | | |
| |||
0 commit comments