Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nutcracker sets umask only upon daemonization #682

Open
bugfood opened this issue Apr 4, 2023 · 1 comment
Open

nutcracker sets umask only upon daemonization #682

bugfood opened this issue Apr 4, 2023 · 1 comment

Comments

@bugfood
Copy link

bugfood commented Apr 4, 2023

Describe the bug
When nutcracker is run with the -d option (to daemonize), nutcracker internally sets its umask to 0. When -d is not specified, nutcracker leaves its umask alone.

To Reproduce
Steps to reproduce the behavior:

Set shell umask, e.g.:

umask 0002

Run nutcracker as e.g.:

nutcracker -d -c /etc/nutcracker/nutcracker0.yml -o /var/log/nutcracker/nutcracker0.log -s 2233 -v 5

Observe umask:

$ sudo gdb --pid="$(pidof nutcracker)" --batch -ex 'call/o umask(0)' -ex 'call umask($1)' 2> /dev/null | perl -ne 'print("$1\n")if(/^\$1 = (\d+)$/)'
0

Kill nutcracker and then run without -d, e.g.:

nutcracker -c /etc/nutcracker/nutcracker0.yml -o /var/log/nutcracker/nutcracker0.log -s 2233 -v 5

Observe umask:

$ sudo gdb --pid="$(pidof nutcracker)" --batch -ex 'call/o umask(0)' -ex 'call umask($1)' 2> /dev/null | perl -ne 'print("$1\n")if(/^\$1 = (\d+)$/)'
02

Expected behavior
Nutcracker leaving the umask alone is arguably better (so that the local administrator can specify the umask), but either way, I think nutcracker should be internally consistent.

Additional context

This issue causes unexpected behavior when migrating from sysvinit to systemd. Common practice for systemd is to run daemons in the foreground.

A workaround for systemd is to use the UMask option.

https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Credit for the gdb one-liner:
https://stackoverflow.com/questions/165212/linux-getting-umask-of-an-already-running-process/38861278#38861278

Thanks,
Corey

@yuerugou54
Copy link

yuerugou54 commented Apr 4, 2023 via email

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

No branches or pull requests

2 participants