Created attachment 337528 [details]
Patch allowing opening of stdout/stderr files before chuid
When using --user (and --group) options, start-stop-daemon opens the specified --pidfile (and creates it) BEFORE changing to specified user. This means the pidfile is owned by root, which is fine.
However, --stdout and --stderr get opened (and created) AFTER changing to the specified user. This means that extra commands are needed in init.d scripts (or done manually) to create and chown the log files.
Of course some users like this as log files are then owned by the same user as the daemon so we need to continue to support this.
I'm proposing a new start-stop-daemon flag called --rootlog (and associated --userlog which is the default so unnecessary) which opens the log files before the chuid.
I've written a quick patch attempting to kept the changes as minor as possible.
Putting the patch file in /etc/portage/patches/sys-apps/openrc/ works flawlessly.
- Indenting of original section
- Moving original section to a function so code is not repeated
- Adding input sanity checks
- Useless without --user
- Other issues I forgot