From nobody Wed Dec 27 06:08:07 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T0Lm80vs4z55BTN; Wed, 27 Dec 2023 06:08:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T0Lm80PS9z3Hq1; Wed, 27 Dec 2023 06:08:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703657288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dTGTc424aJjJMP7A4WbHvZejcMu0+aIPMf97P88IZ5A=; b=SFAr85mvpgfhTrf4gGKEBTQ7Ce8/s6T6lEdz1I1ejV683+VYH1kYV3B08DyeFF3kYRFjTc rirL62P9IbrdO2ulg7lUH9PsIE+hOqqKdh8MkEHcHe0vhjbXKkVcLp8+nH9Scuc7siJYxT g5i+irN8cpswUioWKGT9009aS93Y2c7zWoW7/f36vig6bN8loprdZVJt7/uSdIFSHgmiu9 wHaEmBzQtAZYy2fWUjQxxz+5DWPDlVumvorcZyFQicInojMGJ3ponqUV543Rm688/cdGD0 lyK/YSIhOQ4fSFWiBjigbS9D6uzhmKoUKtp1Toz0HDJF50R+B1gJz7LHFPKp4Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703657288; a=rsa-sha256; cv=none; b=ujFMHwKsa9LoOkCQGmXf3effE92jQqWoifz4XRof0C9yLe7yzyFT5bPjFdfCip3deplgAO gHUcnmS0rSkY4EuZY5GPBQ9pWzWmZ/oQ/l/M+dHkW/LBwHUbgcGmqCfJAcPfFfZqQTE2kQ CSz7G6e11wzPElt8biggsXILYo0SdNPC923N2kIdiRB77RV7PV0WjcHGwTtWum32HKbf46 dcIPCmgHSvM986mdQxcqCdK9MZZRGqjvjtkl51HOt/p83Tv7AxuKaJpRG5yjm5U69X3ahr 87aKc0ZT6Y57r/si/e//VdMPl3s+SpxIyTHtJvcPYmhJq3PvKu1xRpFWIiy1iw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703657288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dTGTc424aJjJMP7A4WbHvZejcMu0+aIPMf97P88IZ5A=; b=u6uIFnakxoYfeHu3MvaA5UTUu8yQ7dS9oKAQBWdLmaCQwKy4Pb9wBE4J1KKm0ddpk5sg5T y3dbt+gYDCC/3bgYoQd++3tRERw55R85CxSsnyshlVlBByFMyTVyYhacqVLVJpJv+bFIfA SgboAtOI4/64LzDmZcrbng6xi9qH7BQ806Abpl965a3Jat4GL8TH2S6maLLPTYfA/gTyvu xKKexc6rZt2t13i2kDbLDLllcqrhtAzouCIAuvx5wnofgEKJbvY3NQgljB0zCB8tEgbajg i0f9GHn5P5QkQD2Kyrorydnd+kzEvSRZ7OfXX9+vT+cqtnWKStqB2g4JA3cCDQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T0Lm76ZLFzC9l; Wed, 27 Dec 2023 06:08:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BR687gf024842; Wed, 27 Dec 2023 06:08:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BR687UZ024839; Wed, 27 Dec 2023 06:08:07 GMT (envelope-from git) Date: Wed, 27 Dec 2023 06:08:07 GMT Message-Id: <202312270608.3BR687UZ024839@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: a6f795cc89cb - main - daemon: fix clang-tidy warnings List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a6f795cc89cbedbf1be0ab504fa6ed863e1eec5e Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=a6f795cc89cbedbf1be0ab504fa6ed863e1eec5e commit a6f795cc89cbedbf1be0ab504fa6ed863e1eec5e Author: Ihor Antonov AuthorDate: 2023-12-27 06:07:25 +0000 Commit: Kyle Evans CommitDate: 2023-12-27 06:07:25 +0000 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 --- usr.sbin/daemon/daemon.8 | 3 ++- usr.sbin/daemon/daemon.c | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/usr.sbin/daemon/daemon.8 b/usr.sbin/daemon/daemon.8 index fce08bc90e62..4fafb8528f18 100644 --- a/usr.sbin/daemon/daemon.8 +++ b/usr.sbin/daemon/daemon.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 18, 2023 +.Dd December 27, 2023 .Dt DAEMON 8 .Os .Sh NAME @@ -151,6 +151,7 @@ option is used or not. .It Fl R , Fl -restart-delay Ar restart_delay_seconds Supervise and restart the program after the specified delay if it has been terminated. +Valid values are 1-31536000 (up to 1 year). .It Fl r , Fl -restart Supervise and restart the program after a one-second delay if it has been terminated. diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index dc488993b1af..14ea87af646d 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -30,7 +30,6 @@ * From BSDI: daemon.c,v 1.2 1996/08/15 01:11:09 jch Exp */ -#include #include #include #include @@ -49,12 +48,14 @@ #include #include #include -#include #define SYSLOG_NAMES #include #include #include +/* 1 year in seconds */ +#define MAX_RESTART_DELAY 60*60*24*365 + #define LBUF_SIZE 4096 enum daemon_mode { @@ -161,7 +162,7 @@ usage(int exitcode) int main(int argc, char *argv[]) { - char *p = NULL; + const char *e = NULL; int ch = 0; struct daemon_state state; @@ -209,9 +210,9 @@ main(int argc, char *argv[]) state.mode = MODE_SUPERVISE; break; case 'm': - state.stdmask = strtol(optarg, &p, 10); - if (p == optarg || state.stdmask < 0 || state.stdmask > 3) { - errx(6, "unrecognized listening mask"); + state.stdmask = (int)strtonum(optarg, 0, 3, &e); + if (e != NULL) { + errx(6, "unrecognized listening mask: %s", e); } break; case 'o': @@ -238,9 +239,10 @@ main(int argc, char *argv[]) break; case 'R': state.restart_enabled = true; - state.restart_delay = strtol(optarg, &p, 0); - if (p == optarg || state.restart_delay < 1) { - errx(6, "invalid restart delay"); + state.restart_delay = (int)strtonum(optarg, 1, + MAX_RESTART_DELAY, &e); + if (e != NULL) { + errx(6, "invalid restart delay: %s", e); } break; case 's': @@ -347,7 +349,7 @@ daemon_exec(struct daemon_state *state) } /* Main event loop: fork the child and watch for events. - * After SIGTERM is recieved and propagated to the child there are + * After SIGTERM is received and propagated to the child there are * several options on what to do next: * - read until EOF * - read until EOF but only for a while @@ -434,7 +436,7 @@ daemon_eventloop(struct daemon_state *state) if (event.flags & EV_ERROR) { errx(EXIT_FAILURE, "Event error: %s", - strerror(event.data)); + strerror((int)event.data)); } switch (event.filter) { @@ -588,7 +590,7 @@ listen_child(int fd, struct daemon_state *state) { static unsigned char buf[LBUF_SIZE]; static size_t bytes_read = 0; - int rv; + ssize_t rv; assert(state != NULL); assert(bytes_read < LBUF_SIZE - 1);