The meaning of non-file permission umask bits is implementation defined.
On Bionic libc, attempting to set them triggers a FORTIFY runtime check.
$ nohup true
FORTIFY: umask: called with invalid mask -601
Aborted nohup true
* src/nohup.c: (main) Avoid setting non-permission bits in umask.
Just clear the umask to ensure we create nohup.out with u+rw,
as we restore the original umask before the exec().
* tests/misc/nohup.sh: Add a test case.
* NEWS: Mention the bug fix.
with multi-byte thousands grouping characters.
[This bug was present in "the beginning".]
+ 'nohup' avoids implementation defined behavior setting umask,
+ avoiding a FORTIFY runtime failure on Bionic libc.
+ [This bug was present in "the beginning".]
+
'od --strings' with '-N' now works correctly. Previously od might
write a NUL byte after a heap buffer, or output invalid addresses.
[These bugs were present in "the beginning".]
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));
returns_ 127 nohup >/dev/null 2>&1 || fail=1
unset POSIXLY_CORRECT
+# Make sure we create nohup.out with u+rw permissions
+(
+ rm -f nohup.out
+
+ # POSIX shells immediately exit the subshell on exec error.
+ # So check we can write to /dev/tty before the exec, which
+ # isn't possible if we've no controlling tty for example.
+ test -c /dev/tty && >/dev/tty || exit 0
+ exec >/dev/tty
+ test -t 1 || exit 0
+
+ umask 600 # Ensure nohup undoes this
+
+ nohup echo hi || fail=1
+ test "$(stat -c %a nohup.out)" = 600 || fail=1
+
+ rm -f nohup.out
+ exit $fail
+) || fail=1
+
Exit $fail