mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 16:21:15 -03:00
The `mkstemp` function opens files without setting `O_CLOEXEC`. We could manually set this using `fnctl` once the file is opened, but that has the issue of introducing race conditions. If fish `exec`s in another thread before the `fnctl` call completes, the file would be left open. One way of mitigating this is `mkostemp`, but that function is not available on all systems fish supports, so we can't rely on it. Instead, build our own tempfile creation logic which uses the `rand` crate for getting entropy and relies on Rust's stdlib for the rest. The stdlib functions we use set `O_CLOEXEC` by default. For directory creation we keep using `mkdtemp`, since there we don't open anything. We could replace this by extending our custom logic a bit, which would allow us to drop the `nix` dependency for our `tempfile` crate, but since the code is simpler as it is now and we need nix in fish's main crate, there is no need to modify the directory creation code. Part of #12030