Page MenuHomeFreeBSD

daemon(8): Add option to write pidfile w/o supervising it
Needs ReviewPublic

Authored by mail_fbsd2.e4m.org on Aug 17 2024, 9:20 AM.
Tags
None
Referenced Files
F132484933: D46313.id142129.diff
Fri, Oct 17, 7:47 AM
Unknown Object (File)
Tue, Oct 7, 4:59 AM
Unknown Object (File)
Sun, Sep 21, 12:50 PM
Unknown Object (File)
Wed, Sep 17, 11:54 PM
Unknown Object (File)
Sep 7 2025, 6:03 AM
Unknown Object (File)
Aug 30 2025, 2:32 PM
Unknown Object (File)
Aug 26 2025, 6:48 PM
Unknown Object (File)
Aug 26 2025, 6:14 PM

Details

Reviewers
markj
otis
kevans
Summary

I needed to get the pid of a process started by daemon(8) but without using its supervising functionality of --child-pidfile (and therefore without the need of having daemon(8) hang around as another process). This comes handy when you want to switch the user but can't use su(1) (e.g. because the user has a negative listing in /etc/login.access).

This patch adds an option "-x file" to accomplish this (see also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280487)

It also fixes an internal comment regarding which options enable Supervision mode.

(Note: This is my first time using reviews.freebsd.org so please be lenient towards me :-))

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

When I think of it more closely, couldn't it be modified to do something like --no-supervise or --execute-only and use -p to get the command's pid file in child-pidfile? I'm just trying to avoid duplicate functionality.

Hmm, what will happen if one uses --no-supervise (with or even w/o -p) but has given other
options which need supervising? Should we silently ignore --no-supervise? Or spit out a
warning or even an error?
Not thinking about the code which has to honour --no-supervise when finished parsing all
options and then has to decide what to do...

So how shall we proceed with this? While I am not happy with the --no-supervise idea (because of
the confusion it might produce) I could make a patch which

  1. Adds --no-supervise (or whatever we want to call it)
  2. decides what to do with it when option processing has finished

In this case: How shall we call it? Do we want a short option for it?

Please upload diffs with full context (-U999999) or use git-arc from devel/freebsd-git-devtools going forward- it helps to be able to expand files a little bit.

The manpage also needs to note that the pidfile isn't locked like it is with -p -- the lock gets dropped after we exec the child. This also has implications for preventing concurrent instances: daemon(8) relies on the pidfle(3) API and the pidfile(3) API relies on advisory locks -- if the file existed but was not locked, we'll just truncate it rather than trying to investigate if the pid was valid for another instance of the same daemon (since that's hard or impossible to do reliably). This is all a good reason for the current pidfile option forcing supervisor mode, since the value drops down to whatever rc provides as a wrapper around pidfiles if we don't hold it locked.

usr.sbin/daemon/daemon.8
170

New sentence should start on new line

173

Ditto

Thanks for the input. I've changed the manpage -- hopefully addressing all issues correctly.
But just to be sure I understood things properly: I should upload a diff with 1260 lines
containing just 30 lines of changes?

Thanks for the input. I've changed the manpage -- hopefully addressing all issues correctly.
But just to be sure I understood things properly: I should upload a diff with 1260 lines
containing just 30 lines of changes?

Correct- Phab will hide all of the unchanged lines, but it gives us the opportunity to unhide those bits if we need to for review purposes.

Updated version, hopefully adressing kevans input.