Skip to content

ch10/my-daemon.c wrong order of umask #5

@larsbergerproductions

Description

@larsbergerproductions

Description

In the my-daemon programs (here, I explicitly refer to ch10/my-daemon-v2.c), the syscall to umask(022) should either be used before creating the pidfile, or the permissions of the pidfile need to be set explicitly for the control client to work as described in the book.

Explanation

This is not the case if the root user uses a umask of e.g. 027 per default (via environment or similar), where the pidfile ends up with permissions 640 (rw-r-----), making it impossible for users other than root to use the control client for querying the status of the daemon.

Steps to reproduce:

$ sudo -i
# umask 027
# ./my-daemon-v2
# exit
$ my-daemon
fopen pidfile: Permission denied
$ ls -ld /var/run/my-daemon.pid
-rw-r----- 1 root root 6 Mar 26 08:19 /run/my-daemon.pid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions