Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mknod: set cli specified file mode even when it's 0o666#8343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
TheJJ wants to merge3 commits intouutils:main
base:main
Choose a base branch
Loading
fromTheJJ:fix-mknod-mode

Conversation

TheJJ
Copy link

@TheJJTheJJ commentedJul 16, 2025
edited
Loading

libc's mknod function applies the process' umask in the usual way: the permissions of the created node aremode & ~umask.

the umask of uu-mknod is currently only set to 0 (= no mask) when the supplied mode is not 0o666:

let set_umask_0 = config.mode&MODE_RW_UGO !=MODE_RW_UGO;

becauseMODE_RW_UGO == 0o666 is also the default--mode argument value.

but when--mode 0666 is given explicitly, the permissions should be set exactly to the requested bits, and the umask should not be applied.

this patch fixes the issue by tracking if a custom mode was supplied by argument.

interestingly, GNU coreutils issue a call tofchmodat2 aftermknod was called, even though they also set the umask to 0 if a custom mode was specified via--mode. this patch doesn't add that, but it may be necessary for other cases in the future.

fixes#8342

this does now result in:

strace mknod --mode 0666 /tmp/rofl/null c 1 3umask(000)                              = 022mknodat(AT_FDCWD, "/tmp/rofl/null", S_IFCHR|0666, makedev(0x1, 0x3)) = 0umask(022)                              = 000-> crw-rw-rw- 1 root root 1, 3 Jul 16 23:54 /tmp/rofl/null

@TheJJTheJJ changed the titlefix(mknod): set specified file modemknod: set cli specified file mode even when it's 0o666Jul 16, 2025
@setharnold
Copy link

setharnold commentedJul 16, 2025
edited
Loading

Forgive me if I've missed a conversation or discussion elsewhere. This feels more complex than the implementation that I expected:

  • setumask(0) at program start (and discard the old umask, what else will the process do?)
  • use default0o666 if the user doesn't include a--mode

What motivates the more complex implementation?

Thanks

@github-actionsGitHub Actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@TheJJ
Copy link
Author

TheJJ commentedJul 17, 2025
edited
Loading

Good point, I don't know :) but I tried to change the currently implemented behavior as little as possible.

The umask restoring is probably done so the functions are usable inside single executables?

My updated implementation now does

  • 0o666+umask by default
  • --mode without umask (and restores the umask).

just like the GNU coreutils manpage says:

-m, --mode=MODE set file permission bits to MODE, not a=rw - umask

@TheJJTheJJforce-pushed thefix-mknod-mode branch 2 times, most recently from042b5d7 toa3c0e53CompareJuly 17, 2025 09:55
libc's mknod function applies the process' umask in the usual way:the permissions of the created node are `mode & ~umask`.the umask of uu-mknod is currently only set to 0 (= no mask)when the supplied mode is not 0o666:```rustlet set_umask_0 = config.mode & MODE_RW_UGO != MODE_RW_UGO;```because `MODE_RW_UGO == 0o666` is also the default `--mode` argument value.but when `--mode 0666` is given explicitly, the permissions should be setexactly to the requested bits, and the umask should not be applied.this patch fixes the issue by tracking if a custom mode was supplied by argument.interestingly, GNU coreutils issue a call to `fchmodat2` after `mknod` was called,even though they also set the umask to 0 if a custom mode was specified via `--mode`.this patch doesn't add that, but it may be necessary for other cases in the future.fixesuutils#8342
@sylvestre
Copy link
Contributor

Could you please add a test to make sure we don't regress?

@github-actionsGitHub Actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

@TheJJ
Copy link
Author

done, it requiresroot though.

@github-actionsGitHub Actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

mknod doesn't respect --mode
3 participants
@TheJJ@setharnold@sylvestre

[8]ページ先頭

©2009-2025 Movatter.jp