From nobody Fri Mar 17 21:01:24 2023 X-Original-To: dev-commits-src-branches@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 4Pdc4N3hplz3yqmd; Fri, 17 Mar 2023 21:01:24 +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 4Pdc4N2XHtz3pWm; Fri, 17 Mar 2023 21:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086884; 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=RwSGAE5AD2Wrkh8GYdillLVV9WfyMZ0qVwxdu8C0sNI=; b=CxAG2alwfBevkuaI0Me03oVCDscEUeSYqGSl1dCzGWhe8CF26k2S79pGmnfDQoskioJJVg gs97uU/kq3T3uDQ/2NNyW25b30j+4DK2ur6ArOhnBt542JMV9Gw1CmCNuH8ozNXp7yUGvj tcjqeJjoK8S4zqHpv1gCGL1c6jOHCPwCS8rG4YgXPPhb3bsgeGdnE7ny5upe53WLTssOP3 jyrv6367MBIvO3anzHIUFtrIxJOY24cxBbLRXdZkyERLntifa8ypzXMTMvFa6Of3EsMiZe +6Khza2wSAx8nl0M+Rbr+CHTqHy86GZ3+7DreP7C4kDh0Mdo2D/FBjuqWAus4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086884; 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=RwSGAE5AD2Wrkh8GYdillLVV9WfyMZ0qVwxdu8C0sNI=; b=BCd+eYJwJukEiaa6LT7ef3U7NwTH9Jct7odc7AxKHbbIUmiP93Mci5KJzx45vVZ564M7Vi LAPow+D4J+nGM37mu0WKhCCttddB5tceIp+ysCZjC7g0CJCVlAUlTrCMObwTjDRLGOcukQ 0/gp0liuc174GmmzmWQjnl1RZPjbJj1EJcnXU9UQGb/ksPA4Fgao0uSEz5s9FajeGiaBV4 +DUugbNNpuLiPe8FviRGoHzv3TzVPrNVp/PYa2e7kvOjV5sn8zh3XPfd3hNjXCTqt5Dz98 xNB34Jw4ZC/767KfIDesbk2haQygeYtQkP/NGWQaiz/MvUexr6uAgdYZnNjbVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679086884; a=rsa-sha256; cv=none; b=k5/M+WVhBf8r7OhlI3A44pH4JLSZhGwS1kTFlg4bb+t2Rw++lZDwAUX0Iq2OT+XLIvGt/c 2aeacq5QOk1YcpAb8P2m1SQwK2hPIgfnaLPXJrq6HJ/1g2DWaUyZLTNulPWyVNX3Z1B+es l0IuXqZb2ufJ7ZFUJ3yVTgvL7ipcy0Gu7mDBZs2FfuMcM4TYj7g/D8vgCR+sLhMUlT5u3u 2EqkYwJENsMN65qOt+zPEaboZmwOtq788DIxRMEDolTWkpfat0bw1zzxfIQo6WKP8HYIO/ LErxKmkhord+frP3J6Cr2DBqJQQPg+Aaw3ynaapTaru74NcC6VOXv2HZV1gTsg== 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 4Pdc4N1GsdzgbP; Fri, 17 Mar 2023 21:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32HL1OCC014979; Fri, 17 Mar 2023 21:01:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HL1OJa014978; Fri, 17 Mar 2023 21:01:24 GMT (envelope-from git) Date: Fri, 17 Mar 2023 21:01:24 GMT Message-Id: <202303172101.32HL1OJa014978@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: d24c97ebfb86 - stable/13 - daemon: consolidate variable declarations and initializaions List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: d24c97ebfb86040436acdc63b9b0e8bc6ef10078 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d24c97ebfb86040436acdc63b9b0e8bc6ef10078 commit d24c97ebfb86040436acdc63b9b0e8bc6ef10078 Author: Ihor Antonov AuthorDate: 2023-03-02 03:00:41 +0000 Commit: Kyle Evans CommitDate: 2023-03-17 21:01:01 +0000 daemon: consolidate variable declarations and initializaions - improve readability by breaking apart single-line multi-variable declarations - initialize simple variables at declaration site - move other top-level variable initializations closer declarations to avoid potential UB and unclutter the use-site. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669 (cherry picked from commit e745dc2287ac4844c1a21aaa31d0bc3dad6b1b06) --- usr.sbin/daemon/daemon.c | 63 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index f9c1f73e193c..c8ccd8f892fa 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -79,8 +79,10 @@ static void open_pid_files(const char *, const char *, struct pidfh **, static void do_output(const unsigned char *, size_t, struct log_params *); static void daemon_sleep(time_t, long); -static volatile sig_atomic_t terminate = 0, child_gone = 0, pid = 0, - do_log_reopen = 0; +static volatile sig_atomic_t terminate = 0; +static volatile sig_atomic_t child_gone = 0; +static volatile sig_atomic_t pid = 0; +static volatile sig_atomic_t do_log_reopen = 0; static const char shortopts[] = "+cfHSp:P:ru:o:s:l:t:m:R:T:h"; @@ -139,27 +141,37 @@ usage(int exitcode) int main(int argc, char *argv[]) { - const char *pidfile, *ppidfile, *title, *user, *outfn, *logtag; - int ch, nochdir, noclose, restart, dosyslog, child_eof; - sigset_t mask_susp, mask_orig, mask_read, mask_term; - struct log_params logpar; - int pfd[2] = { -1, -1 }, outfd = -1; - int stdmask, logpri, logfac, log_reopen; - struct pidfh *ppfh, *pfh; - char *p; - - memset(&logpar, 0, sizeof(logpar)); - stdmask = STDOUT_FILENO | STDERR_FILENO; - ppidfile = pidfile = user = NULL; - nochdir = noclose = 1; - logpri = LOG_NOTICE; - logfac = LOG_DAEMON; - logtag = "daemon"; - restart = 0; - dosyslog = 0; - log_reopen = 0; - outfn = NULL; - title = NULL; + char *p = NULL; + const char *pidfile = NULL; + const char *logtag = "daemon"; + const char *outfn = NULL; + const char *ppidfile = NULL; + const char *title = NULL; + const char *user = NULL; + int ch = 0; + int child_eof = 0; + int dosyslog = 0; + int log_reopen = 0; + int logfac = LOG_DAEMON; + int logpri = LOG_NOTICE; + int nochdir = 1; + int noclose = 1; + int outfd = -1; + int pfd[2] = { -1, -1 }; + int restart = 0; + int stdmask = STDOUT_FILENO | STDERR_FILENO; + struct log_params logpar = { 0 }; + struct pidfh *ppfh = NULL; + struct pidfh *pfh = NULL; + sigset_t mask_orig; + sigset_t mask_read; + sigset_t mask_term; + sigset_t mask_susp; + + sigemptyset(&mask_susp); + sigemptyset(&mask_read); + sigemptyset(&mask_term); + while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (ch) { case 'c': @@ -251,7 +263,6 @@ main(int argc, char *argv[]) openlog(logtag, LOG_PID | LOG_NDELAY, logfac); } - ppfh = pfh = NULL; /* * Try to open the pidfile before calling daemon(3), * to be able to report the error intelligently @@ -294,18 +305,15 @@ main(int argc, char *argv[]) sigemptyset(&act_hup.sa_mask); /* Block these when avoiding racing before sigsuspend(). */ - sigemptyset(&mask_susp); sigaddset(&mask_susp, SIGTERM); sigaddset(&mask_susp, SIGCHLD); /* Block SIGTERM when we lack a valid child PID. */ - sigemptyset(&mask_term); sigaddset(&mask_term, SIGTERM); /* * When reading, we wish to avoid SIGCHLD. SIGTERM * has to be caught, otherwise we'll be stuck until * the read() returns - if it returns. */ - sigemptyset(&mask_read); sigaddset(&mask_read, SIGCHLD); /* Block SIGTERM to avoid racing until we have forked. */ if (sigprocmask(SIG_BLOCK, &mask_term, &mask_orig)) { @@ -406,7 +414,6 @@ restart: * might have closed its stdout and stderr, so we must wait for * the SIGCHLD to ensure that the process is actually gone. */ - child_eof = 0; for (;;) { /* * We block SIGCHLD when listening, but SIGTERM we accept