Skip to content

nutcracker sets umask only upon daemonization #682

Description

@bugfood

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions