Repository navigation
mkfifo, mknod: set the umask through mode::with_umask - #14768
Conversation
a85690e to
56b1e1d
Compare
|
cool PR :) |
56b1e1d to
2f632ab
Compare
2f632ab to
42b8bc8
Compare
|
Ordering note: this branch sits on top of #12715, so the install hunks in the diff belong to that PR and will vanish once it lands. Say the word and I'll rebase it onto main afterwards if you'd rather review it standalone. The clippy and doc failures were mine: |
Merging this PR will improve performance by 30.52%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | factor_three_39_bit_primes |
567 ms | 347.3 ms | +63.25% |
| ⚡ | Simulation | factor_thirteen_39_bit_primes |
9.5 s | 9.1 s | +4.35% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing abendrothj:fix/uucore-serialize-umask-changes (236b46d) with main (c76f272)
Footnotes
-
70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
GNU testsuite comparison: |
5a106d1 to
3896a36
Compare
3896a36 to
2b0978d
Compare
|
reworked after #15121: mkdir moved there, as you asked on that PR, and the lock is reentrant now, so this is just mkfifo and mknod, on #15121 directly instead of #12715. with_umask_from_current and the debug_assert are gone: mkdir is single-threaded and with_umask restores the mask before releasing the lock, so its read and set can't go stale. checked outside the suite that mkfifo and mknod modes still match GNU 9.12 at umasks 022, 077 and 002. |
2b0978d to
79f5e19
Compare
79f5e19 to
484803e
Compare
Utilities that create files or directories at an exact mode, whatever the caller's umask, change the process umask around the call. Done by hand, overlapping calls can restore each other's mask and leave the process at the wrong value, and an unwind between the set and the restore leaks the temporary mask. with_umask runs an operation with a temporary umask, holds a mutex shared with get_umask, and restores the previous mask on return or unwind. Calls nest: the thread that holds the mutex skips it, and get_umask there returns the mask in effect. Only Unix sets the umask this way, so Windows' get_umask takes no lock.
Replace mkdir's own umask guard with the shared helper, so its change is serialized with get_umask and other callers. The shaped umask is computed as a plain mask, which drops mkdir's rustix dependency.
The test set and restored the umask with its own guard, outside the lock that get_umask and with_umask share.
Both changed the process-wide umask directly around a single syscall. Overlapping calls can restore each other's mask and leave the process at the wrong value, and a panic between the set and the restore leaks the temporary mask into the rest of the run. Use uucore::mode::with_umask, which serializes the change with get_umask and restores the mask on unwind. No behavior change: modes for mkfifo -m and plain mkfifo match GNU 9.12 at umasks 022, 077 and 002. test_mknod.rs now pins the umask with and without -m, as test_mkfifo.rs does. Narrow rustix to the fs feature in uu_mkfifo, which no longer needs process.
484803e to
236b46d
Compare
|
Thanks for your PR |
Based on #15121; until it merges, the diff here shows its commits too.
mkfifoandmknodchange the process-wide umask directly around a single syscall. Overlapping calls can restore each other's mask, and a panic between set and restore leaks the temporary mask into the rest of the run.They now use
uucore::mode::with_umask, which holds the umask mutex and restores the previous mask on unwind; mkdir moves to it in #15121.No behavior change:
mkfifoandmknodmodes match GNU 9.12 at umasks 022, 077 and 002.rustixis narrowed to thefsfeature inuu_mkfifo.Closes #14994