History log of /src/usr.sbin/daemon/daemon.c (Results 1 – 25 of 289)
Revision Date Author Comments
# a3b90a1f 28-Jan-2026 Michael Osipov <michaelo@FreeBSD.org>

daemon: Add option for output file mode

The daemon utility has always created its output file with a fixed mode
of 0600. This causes issues for log collection setups where the collector
does not run

daemon: Add option for output file mode

The daemon utility has always created its output file with a fixed mode
of 0600. This causes issues for log collection setups where the collector
does not run as root but instead relies on group access to the watched
daemon’s log file.

Introduce a new option that allows specifying the output file mode using
install(1)-style semantics. This enables non-root log collectors to access
the file as intended and improves compatibility with log rotation tools.

Reviewed by: kevans
MFC after: 1 week
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D54930

show more ...


# bc1dfc31 19-Nov-2024 Kyle Evans <kevans@FreeBSD.org>

daemon: stop rebuilding the kqueue every restart of the child

We populate the kqueue with all of four kevents: three signal handlers and
one for read of the child pipe. Every time we start the chil

daemon: stop rebuilding the kqueue every restart of the child

We populate the kqueue with all of four kevents: three signal handlers and
one for read of the child pipe. Every time we start the child, we rebuild
this kqueue from scratch for the child and tear it down before we exit and
check if we need to restart the child. As a consequence, we effectively
drop any of the signals we're interested in between restarts.

Push the kqueue out into the daemon state to avoid losing any signal events
in the process, and reimplement the restart timer in terms of kqueue timers.
The pipe read event will be automatically deleted upon last close, which
leaves us with only the signal events that really get retained between
restarts of the child.

PR: 277959
Reviewed by: des, markj
Differential Revision: https://reviews.freebsd.org/D47004

show more ...


# aa8722cc 19-Nov-2024 Kyle Evans <kevans@FreeBSD.org>

daemon: truncate the pidfile when we're waiting to restart child

We need to be able to test some more restart behavior that depends on
knowing specifically where we're at (inside the event loop or o

daemon: truncate the pidfile when we're waiting to restart child

We need to be able to test some more restart behavior that depends on
knowing specifically where we're at (inside the event loop or outside of
the event loop). Truncate the pidfile until the process is restarted to
give the test a clean marker rather than having to add arbitrary delays
and hoping for the best.

Reviewed by: des, markj
Differential Revision: https://reviews.freebsd.org/D47003

show more ...


# 7618c9e1 25-Apr-2024 Juraj Lutter <otis@FreeBSD.org>

daemon: Add -C (--restart-count) option

Add a new option (-C, --restart-count) to specify the maximum
number of times that the controlled process is restarted if
restart (-r) is restarted.

Reviewed

daemon: Add -C (--restart-count) option

Add a new option (-C, --restart-count) to specify the maximum
number of times that the controlled process is restarted if
restart (-r) is restarted.

Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44944

show more ...


# bbc6e6c5 14-Apr-2024 Mathieu <sigsys@gmail.com>

daemon: fix -R to enable supervision mode

If we're doing restarts, then we must supervise -- the 'R' case simply
got missed.

PR: 278342
Fixes: f907027b49d ("daemon: set supervise_enabled during [..

daemon: fix -R to enable supervision mode

If we're doing restarts, then we must supervise -- the 'R' case simply
got missed.

PR: 278342
Fixes: f907027b49d ("daemon: set supervise_enabled during [..]")

show more ...


# f7a10a77 12-Apr-2024 Collin Funk <collin.funk1@gmail.com>

daemon: Prefer sys/cdefs.h __unreachable over the builtin

The __builtin_unreachable macro provided by Clang and GCC is a hint to
the compiler used for optimization. The programs work fine even if th

daemon: Prefer sys/cdefs.h __unreachable over the builtin

The __builtin_unreachable macro provided by Clang and GCC is a hint to
the compiler used for optimization. The programs work fine even if the
compiler doesn't support it. The sys/cdefs.h has had __unreachable for
9 years (commit 732b31de5d9244bd1cc98192e09ee1881e9f55e9). It expands
to the builtin if it is available. In the rare case that it is
unsupported it expands to a null statement so compilation does not
fail.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Reviewed by: imp, freebsd@igalic.co
Pull Request: https://github.com/freebsd/freebsd-src/pull/1117

show more ...


# 8eaa6be8 18-Mar-2024 Konstantin Belousov <kib@FreeBSD.org>

daemon(8): handle case of waitpid() returning without exited child

Not checking for either WIFEXITED(status) or zero result results in
never finishing the loop.

PR: 277764
Reviewed by: kevans (prev

daemon(8): handle case of waitpid() returning without exited child

Not checking for either WIFEXITED(status) or zero result results in
never finishing the loop.

PR: 277764
Reviewed by: kevans (previous version)
Discussed with: Daniel Tameling
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D44401

show more ...


# e0645579 27-Dec-2023 Kyle Evans <kevans@FreeBSD.org>

daemon: fix recent style regressions

Re-wrap the read(2) line, and make the listen_child loop more explicit
in intent.

Reported by: kib
Fixes: 6ac7c9f06ae9 ("daemon: remove redundant parameter from

daemon: fix recent style regressions

Re-wrap the read(2) line, and make the listen_child loop more explicit
in intent.

Reported by: kib
Fixes: 6ac7c9f06ae9 ("daemon: remove redundant parameter from [...]")

show more ...


# 407e3790 27-Dec-2023 Ihor Antonov <ihor@antonovs.family>

daemon: separate pipe_fd[2] into pipe_rd and pipe_wr

This improves code readability and prevents mixing up read and write
ends of the pipe.

Reviewed by: cperciva, kevans
Requested by: kevans


# 5745a584 27-Dec-2023 Ihor Antonov <ihor@antonovs.family>

daemon: replace memchr with memrchr

Looping over lines in the buffer is not needed.
Same effect can be achieved by looking for the last new line.
If found the buffer is guaranteed to have one or mor

daemon: replace memchr with memrchr

Looping over lines in the buffer is not needed.
Same effect can be achieved by looking for the last new line.
If found the buffer is guaranteed to have one or more complete lines.
All complete lines are flushed at once with no looping.

Reviewed by: cperciva, kevans

show more ...


# 24fd3e96 27-Dec-2023 Ihor Antonov <ihor@antonovs.family>

daemon: move buffer into daemon_state

There is no reason for a buffer in listen_child()
to be a static function variable. The buffer and
its position are parts of the daemon state and should
live to

daemon: move buffer into daemon_state

There is no reason for a buffer in listen_child()
to be a static function variable. The buffer and
its position are parts of the daemon state and should
live together with the rest of the state variables.

Reviewed by: cperciva, kevans

show more ...


# 6ac7c9f0 27-Dec-2023 Ihor Antonov <ihor@antonovs.family>

daemon: remove redundant parameter from listen_child()

state already contains pipe fd

Reviewed by: cperciva, kevans


# a6f795cc 27-Dec-2023 Ihor Antonov <ihor@antonovs.family>

daemon: fix clang-tidy warnings

Fixed narrowing conversions:
- strtol replaced with strtonum with range check
- read returns ssize_t
- kevent.data explicitly cast to int before passing into strerror

daemon: fix clang-tidy warnings

Fixed narrowing conversions:
- strtol replaced with strtonum with range check
- read returns ssize_t
- kevent.data explicitly cast to int before passing into strerror

While we we're here:
- Defined and documented maximum restart delay.
- Fixed typo in a comment.
- Remove unused includes

Reviewed by: cperciva, kevans

show more ...


# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix

show more ...


# cec8e6ba 06-Oct-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

daemon: Disable stdio buffering.

The daemon utility already does its own buffering and retransmits its
child's output line by line. There's no need for stdio to add its own
buffering on top of this

daemon: Disable stdio buffering.

The daemon utility already does its own buffering and retransmits its
child's output line by line. There's no need for stdio to add its own
buffering on top of this.

MFC after: 1 week
Sponsored by: Modirum MDPay
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D42111

show more ...


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 494e7dfd 05-May-2023 Kyle Evans <kevans@FreeBSD.org>

daemon: EINTR from kevent(2) is not a fatal error

Simply resume waiting for events rather than exiting if we took a signal
here.

This at least fixes running programs under daemon(8) in the face of

daemon: EINTR from kevent(2) is not a fatal error

Simply resume waiting for events rather than exiting if we took a signal
here.

This at least fixes running programs under daemon(8) in the face of
suspend/resume, which I suspect hits us with a spurious EINTR rather
than a signal anyways.

Reported and tested by: manu
Fixes: 8935a3993219b ("daemon: use kqueue for all events")

show more ...


# 8935a399 14-Apr-2023 Ihor Antonov <ihor@antonovs.family>

daemon: use kqueue for all events

Refactor daemon to use kqueue/kevent instead of signals.

This changes allows to simplify the code in several ways:
- the execution flow is now linear, no async eve

daemon: use kqueue for all events

Refactor daemon to use kqueue/kevent instead of signals.

This changes allows to simplify the code in several ways:
- the execution flow is now linear, no async events.
- several variables became redundant and got removed.
- all event handling is now concentrated inside of the event loop, which
makes code reading and comprehension easier.
- new kqueuex(2) call is used for CLOEXEC, but maintained closing the
kq fd prior to execve() to ease later MFC

No UX/API changes are intended.

Reviewed by: kevans
Pull Request: https://github.com/freebsd/freebsd-src/pull/701

show more ...


# b84aaf14 23-Mar-2023 Kyle Evans <kevans@FreeBSD.org>

daemon: reformat longopts

Use a single tab instead of eight spaces, these aren't line
continuations.


# 4c41f4a0 23-Mar-2023 Ihor Antonov <ihor@antonovs.family>

daemon: decouple init logic from main loop

main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of

daemon: decouple init logic from main loop

main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.

Reviewed by: kevans
Pull Request: https://github.com/freebsd/freebsd-src/pull/699

show more ...


# 9ee1faee 21-Mar-2023 Ihor Antonov <ihor@antonovs.family>

daemon: move signal setup into a function

No functional change intended.

Reviewed by: kevans


# 6b49a630 18-Mar-2023 Kyle Evans <kevans@FreeBSD.org>

daemon: kill off some stray blank lines

Overlooked in review; mea culpa.

Reported by: jrtc27


# 8117ea0a 18-Mar-2023 Ihor Antonov <ihor@antonovs.family>

daemon: remove unnecessary memset in daemon_state_init()

Pull Request: https://github.com/freebsd/freebsd-src/pull/694


# cf6356fd 18-Mar-2023 Ihor Antonov <ihor@antonovs.family>

daemon: repace goto exit with daemon_terminate()

Start breaking down big main()
Remove goto exit label and replace it with a function that does cleanup.

Comment re-worded by kevans@.

Pull Request:

daemon: repace goto exit with daemon_terminate()

Start breaking down big main()
Remove goto exit label and replace it with a function that does cleanup.

Comment re-worded by kevans@.

Pull Request: https://github.com/freebsd/freebsd-src/pull/694

show more ...


# 298a392e 12-Mar-2023 Ihor Antonov <ihor@antonovs.family>

daemon: move variables into struct daemon_state

The fact that most of the daemon's state is stored on the stack
of the main() makes it hard to split the logic smaller chunks.
Which in turn leads to

daemon: move variables into struct daemon_state

The fact that most of the daemon's state is stored on the stack
of the main() makes it hard to split the logic smaller chunks.
Which in turn leads to huge main func that does a a lot of things.
struct log_params existed because some variables need to be passed
into other functions together.

This change renames struct log_params into daemon_state
and moves the rest of the variables into it. This is a necessary
preparation step for further refactroing.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/687

show more ...


12345678910>>...12