aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/daemon
Commit message (Collapse)AuthorAgeFilesLines
* daemon(8): Add option to write pidfile w/o supervising itAndre Albsmeier2026-08-132-7/+39
| | | | | | | | 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
* daemon(8): Add "--output-file -o" to list of options enabling supervision modeAndre Albsmeier2026-04-121-0/+1
| | | | | | | | | This is the small internal doc fix from https://reviews.freebsd.org/D46313 Reviewed by: michaelo Approved by: (blanket; comment fix) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D55325
* daemon: Add option for output file modeMichael Osipov2026-02-072-9/+36
| | | | | | | | | | | | | | | | 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
* daemon: tests: add a test for missed SIGTERMKyle Evans2024-11-191-0/+38
| | | | | | | | | | | | | | | | | | | This is somewhaht hard to test reliably, but we'll give it a shot. Startup a sleep(1) daemon with a hefty restart delay. In refactoring of daemon(8), we inadvertently started dropping SIGTERMs that came in while we were waiting to restart the child, so we employ the strategy: - Pop the child sleep(1) first - Wait for sleep(1) to exit (pid file truncated) - Pop the daemon(8) with a SIGTERM - Wait for daemon(8) to exit The pidfile is specifically truncated outside of the event loop so that we don't have a kqueue to catch it in the current model. PR: 277959 Reviewed by: des, markj Differential Revision: https://reviews.freebsd.org/D47005
* daemon: stop rebuilding the kqueue every restart of the childKyle Evans2024-11-191-20/+101
| | | | | | | | | | | | | | | | | | 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
* daemon: truncate the pidfile when we're waiting to restart childKyle Evans2024-11-192-2/+35
| | | | | | | | | | | 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
* Update Makefile.depend filesSimon J. Gerraty2024-10-141-0/+10
| | | | | | | After building packages we have a number of new and updated Makefile.depend files Reviewed by: stevek
* Remove residual blank line at start of MakefileWarner Losh2024-07-152-2/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* daemon: Add -C (--restart-count) optionJuraj Lutter2024-05-222-4/+40
| | | | | | | | | 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
* daemon: fix -R to enable supervision modeMathieu2024-04-141-0/+1
| | | | | | | | 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: Prefer sys/cdefs.h __unreachable over the builtinCollin Funk2024-04-121-1/+1
| | | | | | | | | | | | | | 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
* daemon(8): handle case of waitpid() returning without exited childKonstantin Belousov2024-03-201-5/+9
| | | | | | | | | | | | 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
* daemon: fix recent style regressionsKyle Evans2023-12-271-2/+5
| | | | | | | | 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: separate pipe_fd[2] into pipe_rd and pipe_wrIhor Antonov2023-12-271-19/+25
| | | | | | | | This improves code readability and prevents mixing up read and write ends of the pipe. Reviewed by: cperciva, kevans Requested by: kevans
* daemon: replace memchr with memrchrIhor Antonov2023-12-271-4/+8
| | | | | | | | | 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
* daemon: move buffer into daemon_stateIhor Antonov2023-12-271-19/+21
| | | | | | | | | 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
* daemon: remove redundant parameter from listen_child()Ihor Antonov2023-12-271-9/+5
| | | | | | state already contains pipe fd Reviewed by: cperciva, kevans
* daemon: fix clang-tidy warningsIhor Antonov2023-12-272-13/+16
| | | | | | | | | | | | | | 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
* usr.sbin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | 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
* daemon: Disable stdio buffering.Dag-Erling Smørgrav2023-10-061-0/+1
| | | | | | | | | | | 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
* daemon.8: Document -u sets HOME, USER, and SHELLMateusz Piotrowski2023-09-181-1/+6
| | | | | Fixes: 6b3ad1d73732 When -u option is used also set USER, HOME and SHELL MFC after: 3 days
* daemon.8: Sort options in DESCRIPTIONMateusz Piotrowski2023-09-181-48/+48
| | | | MFC after: 3 days
* daemon.8: Use Cm where appropriateMateusz Piotrowski2023-09-181-10/+28
| | | | MFC after: 3 days
* daemon.8: Use Dv for signal namesMateusz Piotrowski2023-09-181-3/+8
| | | | MFC after: 3 days
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-164-5/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* daemon: EINTR from kevent(2) is not a fatal errorKyle Evans2023-05-051-0/+2
| | | | | | | | | | | | 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")
* Update/fix Makefile.depend for userlandSimon J. Gerraty2023-04-191-1/+0
|
* daemon: use kqueue for all eventsIhor Antonov2023-04-141-269/+239
| | | | | | | | | | | | | | | | | 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
* daemon: reformat longoptsKyle Evans2023-03-231-17/+17
| | | | | Use a single tab instead of eight spaces, these aren't line continuations.
* daemon: decouple init logic from main loopIhor Antonov2023-03-231-86/+109
| | | | | | | | | | | | | 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
* daemon: move signal setup into a functionIhor Antonov2023-03-211-63/+79
| | | | | | No functional change intended. Reviewed by: kevans
* daemon: kill off some stray blank linesKyle Evans2023-03-181-3/+0
| | | | | | Overlooked in review; mea culpa. Reported by: jrtc27
* daemon: remove unnecessary memset in daemon_state_init()Ihor Antonov2023-03-181-1/+0
| | | | Pull Request: https://github.com/freebsd/freebsd-src/pull/694
* daemon: repace goto exit with daemon_terminate()Ihor Antonov2023-03-181-25/+40
| | | | | | | | | 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
* daemon: move variables into struct daemon_stateIhor Antonov2023-03-121-134/+154
| | | | | | | | | | | | | | | 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
* daemon: set supervise_enabled during argument processingIhor Antonov2023-03-031-23/+31
| | | | | | | | | | Now when supervsion mode has it's own variable there is really no reason to set it separately from the rest of the variables. Move initialization of supervise_enabled var to the argument processing switch loop, where it belongs. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: decouple restart variableIhor Antonov2023-03-031-9/+11
| | | | | | | | | The 'restart' variable was responsible for enablement of restart behavior and for restart delay. While it may seem convenient it leads to cluttering the exit/restart logic Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: add braces to while loopIhor Antonov2023-03-031-16/+17
| | | | | Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: simplify if/else chainIhor Antonov2023-03-031-13/+21
| | | | | Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: change type of listen_child() to C99 boolIhor Antonov2023-03-031-10/+10
| | | | | Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: flatten and simplify fork() logicIhor Antonov2023-03-031-24/+29
| | | | | Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: style changesIhor Antonov2023-03-031-35/+40
| | | | | | | | | This is not a functional change. - Clean up whitespace (spaces where there should be tabs) - Break up lines that are longer than 80 Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672
* daemon: more human-friendly variable namesIhor Antonov2023-03-021-47/+47
| | | | | Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669
* daemon: move syslog facility and syslog tag into log_paramsIhor Antonov2023-03-021-6/+8
| | | | | | | | | Since struct log_params already contains logging-related varaiables, including syslog-related, move remaining syslog-related variables into struct log_params as well Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669
* daemon: deduplicate log_params varaiblesIhor Antonov2023-03-021-48/+44
| | | | | | | While we're here, sort log_params by size. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669
* daemon: make log_reopen variable a boolIhor Antonov2023-03-021-2/+2
| | | | | | | | Following style(9) and C99 recommendation use bool instead of int for boolean operations. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669
* daemon: make dosyslog variable a bool and give it a better nameIhor Antonov2023-03-021-12/+12
| | | | | | | | | Following style(9) and C99 recommendation use bool instead of int for boolean operations. Also give the variable a more descriptive name that follows boolean naming convention. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669