On 08/09/2025 00:35, Collin Funk wrote:
Grisha Levit <grishale...@gmail.com> writes:
On Sun, Sep 7, 2025 at 6:26 PM Collin Funk <collin.fu...@gmail.com> wrote:
Interesting, thanks for the report. Can't we just do the following to
avoid the extra umask() call?
- mode_t umask_value = umask (~mode);
+ mode_t umask_value = umask (~mode & (S_IRWXU | S_IRWXG | S_IRWXO));
This seems likely fine, but after reading the POSIX description[1], I
was worried that in the case that the other bits do serve some
implementation-defined purpose it may not be correct to clear them, so
went the route of only clearing the bits we need to. I'm not aware of
any platform where that would actually matter though.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/umask.html
Lets see what others think.
We restore the original umask before the exec,
so this umask() is only ensuring u+rw aren't set in the umask
so that we create nohup.out with u+rw.
The simplest way to do that I think is just clearing the umask:
index d58fcc53f..6218986cb 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -141,7 +141,7 @@ main (int argc, char **argv)
char const *file = "nohup.out";
int flags = O_CREAT | O_WRONLY | O_APPEND;
mode_t mode = S_IRUSR | S_IWUSR;
- mode_t umask_value = umask (~mode);
+ mode_t umask_value = umask (0);
out_fd = (redirecting_stdout
? fd_reopen (STDOUT_FILENO, file, flags, mode)
: open (file, flags, mode));