The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=20a3c611f53dfad830f9907e24fa08b80b674860
commit 20a3c611f53dfad830f9907e24fa08b80b674860 Author: Vladimir Kondratyev <[email protected]> AuthorDate: 2026-02-10 22:59:06 +0000 Commit: Vladimir Kondratyev <[email protected]> CommitDate: 2026-02-10 22:59:06 +0000 moused(8): Use KQUEUE_CPONFORK flag to pass kqueue fd through fork and use libc daemon() instead of private rfork-based copy. --- usr.sbin/moused/moused/moused.c | 58 ++--------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/usr.sbin/moused/moused/moused.c b/usr.sbin/moused/moused/moused.c index 36cb8cc27eab..7de6832a1eb8 100644 --- a/usr.sbin/moused/moused/moused.c +++ b/usr.sbin/moused/moused/moused.c @@ -492,7 +492,6 @@ static void usage(void); static void log_or_warn(int log_pri, int errnum, const char *fmt, ...) __printflike(3, 4); -static int r_daemon(void); static enum device_if r_identify_if(int fd); static enum device_type r_identify_evdev(int fd); static enum device_type r_identify_sysmouse(int fd); @@ -761,7 +760,7 @@ main(int argc, char *argv[]) if ((cfd = open("/dev/consolectl", O_RDWR, 0)) == -1) logerr(1, "cannot open /dev/consolectl"); - if ((kfd = kqueue()) == -1) + if ((kfd = kqueuex(KQUEUE_CPONFORK)) == -1) logerr(1, "cannot create kqueue"); if (portname == NULL && (dfd = connect_devd()) == -1) logwarnx("cannot open devd socket"); @@ -827,7 +826,7 @@ main(int argc, char *argv[]) logerrx(1, "moused already running, pid: %d", mpid); logwarn("cannot open pid file"); } - if (r_daemon()) { + if (daemon(0, 0)) { int saved_errno = errno; pidfile_remove(pfh); errno = saved_errno; @@ -1284,59 +1283,6 @@ log_or_warn(int log_pri, int errnum, const char *fmt, ...) va_end(ap); } -static int -r_daemon(void) -{ - struct sigaction osa, sa; - pid_t newgrp; - int oerrno; - int osa_ok; - int nullfd; - - /* A SIGHUP may be thrown when the parent exits below. */ - sigemptyset(&sa.sa_mask); - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - osa_ok = sigaction(SIGHUP, &sa, &osa); - - /* Keep kqueue fd alive */ - switch (rfork(RFPROC)) { - case -1: - return (-1); - case 0: - break; - default: - /* - * A fine point: _exit(0), not exit(0), to avoid triggering - * atexit(3) processing - */ - _exit(0); - } - - newgrp = setsid(); - oerrno = errno; - if (osa_ok != -1) - sigaction(SIGHUP, &osa, NULL); - - if (newgrp == -1) { - errno = oerrno; - return (-1); - } - - (void)chdir("/"); - - nullfd = open("/dev/null", O_RDWR, 0); - if (nullfd != -1) { - (void)dup2(nullfd, STDIN_FILENO); - (void)dup2(nullfd, STDOUT_FILENO); - (void)dup2(nullfd, STDERR_FILENO); - } - if (nullfd > 2) - close(nullfd); - - return (0); -} - static inline int bit_find(bitstr_t *array, int start, int stop) {
