Skip to content

mkfifo, mknod: set the umask through mode::with_umask - #14768

Merged
sylvestre merged 4 commits into
uutils:mainfrom
abendrothj:fix/uucore-serialize-umask-changes
Oct 17, 2026
Merged

sylvestre merged 4 commits into
uutils:mainfrom
abendrothj:fix/uucore-serialize-umask-changes

Conversation

@abendrothj

@abendrothj abendrothj commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Based on #15121; until it merges, the diff here shows its commits too.

mkfifo and mknod change 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: mkfifo and mknod modes match GNU 9.12 at umasks 022, 077 and 002. rustix is narrowed to the fs feature in uu_mkfifo.

Closes #14994

Copilot AI lite review requested due to automatic review settings September 21, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 21, 2026 02:27
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from a85690e to 56b1e1d Compare September 21, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj abendrothj changed the title uucore: serialize process-wide umask changes mkdir, mkfifo, mknod: use uucore's serialized umask helpers Sep 21, 2026
Comment thread src/uu/mkdir/src/mkdir.rs Resolved
Comment thread src/uu/mkdir/src/mkdir.rs Resolved
Comment thread src/uucore/src/lib/features/mode.rs Resolved
Comment thread src/uucore/src/lib/features/mode.rs Resolved
@sylvestre

Copy link
Copy Markdown
Contributor

cool PR :)

@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 56b1e1d to 2f632ab Compare September 22, 2026 01:00
Copilot AI review requested due to automatic review settings September 22, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 22, 2026 01:42
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 2f632ab to 42b8bc8 Compare September 22, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj

Copy link
Copy Markdown
Contributor Author

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: DEFAULT_PERM became dead code on Windows once the non-unix path stopped using it, and the new doc comment linked to the private UmaskLock type. Both fixed; those jobs are green.

Comment thread src/uucore/src/lib/features/mode.rs Resolved
Copilot AI review requested due to automatic review settings September 28, 2026 02:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 30.52%

⚠️ 122 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 2 improved benchmarks
✅ 399 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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. ↩

Copilot AI review requested due to automatic review settings September 28, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)

Copilot AI lite review requested due to automatic review settings October 6, 2026 07:15
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 5a106d1 to 3896a36 Compare October 6, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI lite review requested due to automatic review settings October 7, 2026 00:39
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 3896a36 to 2b0978d Compare October 7, 2026 00:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj

Copy link
Copy Markdown
Contributor Author

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.

@abendrothj abendrothj changed the title mkdir, mkfifo, mknod: use uucore's serialized umask helpers mkfifo, mknod: set the umask through mode::with_umask Oct 7, 2026
Comment thread src/uu/mknod/src/mknod.rs Resolved
Copilot AI lite review requested due to automatic review settings October 10, 2026 04:26
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 2b0978d to 79f5e19 Compare October 10, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI lite review requested due to automatic review settings October 13, 2026 09:56
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 79f5e19 to 484803e Compare October 13, 2026 09:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.
@abendrothj
abendrothj force-pushed the fix/uucore-serialize-umask-changes branch from 484803e to 236b46d Compare October 14, 2026 22:08
Copilot AI lite review requested due to automatic review settings October 14, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sylvestre
sylvestre merged commit 94c109a into uutils:main Oct 17, 2026
193 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mkdir, mkfifo, mknod: umask changes are not serialized or panic-safe

4 participants