Bug 280487 - daemon(8): Add option to write pidfile w/o supervising it
Summary: daemon(8): Add option to write pidfile w/o supervising it
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: Michael Osipov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-29 04:32 UTC by Andre Albsmeier
Modified: 2026-08-22 21:22 UTC (History)
7 users (show)

See Also:


Attachments
Patch for adding -C option (2.45 KB, patch)
2024-07-29 04:32 UTC, Andre Albsmeier
no flags Details | Diff
Patch for adding -C option (2.46 KB, patch)
2024-07-29 04:46 UTC, Andre Albsmeier
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andre Albsmeier 2024-07-29 04:32:10 UTC
Created attachment 252342 [details]
Patch for adding -C option

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).

The attached patch adds an option -C to accomplish this.
Comment 1 Andre Albsmeier 2024-07-29 04:46:04 UTC
Created attachment 252343 [details]
Patch for adding -C option

Correct version of the patch
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2024-08-09 17:16:50 UTC
This seems ok to me, I cc'ed a few folks who have hacked on daemon(8) recently.  It would be useful to have a patch in the form of git format-patch's output (or you can submit the patch on github), so that author metadata etc. is filled out correctly.

It appears that -C has been taken for a different purpose in commit 7618c9e1637caea97723ff8accd60f3dc436b044, so this can't be applied as-is.
Comment 3 Juraj Lutter freebsd_committer freebsd_triage 2024-08-09 19:24:09 UTC
If I get it right, it's suitable for situations where the command to be run daemon()-izes itself, does not have any ability to run in foreground and a shell wrapper with $! output written into a file is not a solution?

I'd also rephrase the "ID of the executed command" to "PID of the command executed".

Other than that, LGTM.

And as stated by Mark Johnston, "git format-patch" output would be more usable, or even a review in phabricator (reviews.FreeBSD.org) would be fine.
Comment 4 Andre Albsmeier 2024-08-10 05:37:40 UTC
Didn't know about -C being taken (as I am on 14-STABLE). Of course, any free letter will be fine. Any suggestions?

ID <-> PID: The man page talks about ID for -P and -p. Now that you've mentioned it I also think "PID" would be better but then we should change it within the whole man page.

Regarding using $!: Yes, this could be used and in fact I have used it until I needed to run "command" as a different user. I tried su but this failed as this very user was not listed in our /etc/login.access.

I can look into "git format-patch" but as I use gitup this will probably be something complicated I'd like to avoid ;-).

Regarding reviews.freebsd.org: Is this available for "ordinary" users? If yes, is there a manual (or short doc) of how to use it properly?

In general: Is there a documentation of the preferred way how to submit stuff like this (for ordinary users)? I didn't find anything on freebsd.org but I might have overlooked something...
Comment 5 Juraj Lutter freebsd_committer freebsd_triage 2024-08-10 12:02:33 UTC
The "ID" vs. "PID" argument is valid, let's keep ID then.

Regarding -C, it's taken already. Please, do your patch against "main" branch, then backport it to other branches where you need to run it.

And if you want to submit, then you can submit it to phabricator for review, as phabricator is open, you can create an account there.
Comment 6 Andre Albsmeier 2024-08-17 09:21:42 UTC
OK, thanks for your feedback -- I just gave it a try:

https://reviews.freebsd.org/D46313
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-08-13 14:22:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=fe06e383cc64fce8b604d21f8526b91fa6aecc39

commit fe06e383cc64fce8b604d21f8526b91fa6aecc39
Author:     Andre Albsmeier <mail@fbsd2.e4m.org>
AuthorDate: 2024-08-17 09:20:00 +0000
Commit:     Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2026-08-13 14:21:52 +0000

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

    Co-authored-by: Michael Osipov <michaelo@FreeBSD.org>
    PR:             280487
    Reviewed by:    kevans, michaelo
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D46313

 usr.sbin/daemon/daemon.8 | 19 ++++++++++++++++---
 usr.sbin/daemon/daemon.c | 27 +++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 7 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2026-08-22 21:13:24 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=79f020ffcad205ef82b0a098fd356dbbc5fba8cd

commit 79f020ffcad205ef82b0a098fd356dbbc5fba8cd
Author:     Andre Albsmeier <mail@fbsd2.e4m.org>
AuthorDate: 2024-08-17 09:20:00 +0000
Commit:     Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2026-08-22 21:12:10 +0000

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

    Co-authored-by: Michael Osipov <michaelo@FreeBSD.org>
    PR:             280487
    Reviewed by:    kevans, michaelo
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D46313

    (cherry picked from commit fe06e383cc64fce8b604d21f8526b91fa6aecc39)

 usr.sbin/daemon/daemon.8 | 19 ++++++++++++++++---
 usr.sbin/daemon/daemon.c | 27 +++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 7 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-08-22 21:15:36 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=21f5c8438851ed2a8ac9251a42648999f8b36439

commit 21f5c8438851ed2a8ac9251a42648999f8b36439
Author:     Andre Albsmeier <mail@fbsd2.e4m.org>
AuthorDate: 2024-08-17 09:20:00 +0000
Commit:     Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2026-08-22 21:13:51 +0000

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

    Co-authored-by: Michael Osipov <michaelo@FreeBSD.org>
    PR:             280487
    Reviewed by:    kevans, michaelo
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D46313

    (cherry picked from commit fe06e383cc64fce8b604d21f8526b91fa6aecc39)

 usr.sbin/daemon/daemon.8 | 19 ++++++++++++++++---
 usr.sbin/daemon/daemon.c | 27 +++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 7 deletions(-)