From nobody Fri Mar 17 21:01:22 2023 X-Original-To: dev-commits-src-all@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 4Pdc4M2L4hz3yqN6; Fri, 17 Mar 2023 21:01:23 +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 4Pdc4M1kKmz3pQs; Fri, 17 Mar 2023 21:01:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086883; 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=8HkAOcq8iXCuRJPCuKv44A3sOciagTTQCp9gqw8Mj40=; b=uTjxObWWRHEIK3PWbgw0Cca/7f7CYPTRjjydZ2+7CGrnOuPv3nX5IetzovsMB78UTIw80n caMOA/mGVpxlWyJzP0spqY1S21xwKNuhbFG++tC7NydK+kgq2KCKz/xSYnUwiwe+3ZGux+ lrk/KbculRgV/LWcGOcTMXDScTysvXQCacR1/2jEDd5GFK3pKOjsKAhW/LdXSYFJcteu0/ wdykwcd5OW1vEiX5aCYeeT4tjxOT2J/DQu4UTW2+VHH5dsbJUihyRc4Pas2saBLPAUBa+o cKYD2C6/GQ2qArCgeHNV3L/DysYCZi+ly7HtWfqGMwKF7tzb2ihjN4cyNbpThg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086883; 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=8HkAOcq8iXCuRJPCuKv44A3sOciagTTQCp9gqw8Mj40=; b=ENkPAmwboJSxtLO7k0fONjdMnHfbH933sdwx7jraAOzZdBOWNxotnyUWbCkFNxPY2te6GJ /8j1+Hy1Li/qBkPzTkYjApaTaAz+hj+4wnRVjGvnrigqHeWAyNABYsCIt8vkminl+lPShd xLSX1CkHajtSQmF0f7ZqTe2N/FsMIwv+ZJovo6Z8OUTS3oYi1ozBIX1gGiUOQf6pNlRZui 5is1+P+N0HNS2JJMv46yqNg8O4TpSA7X372ry6BoCTMGwlWF9JeyKCZmeo/wifFXGSl+fb 57wC119K8rU/nYo2GFDPQ693G4w5aY1jhDwx59+pObzFLbe4hEbN/FLgh2Iz9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679086883; a=rsa-sha256; cv=none; b=sbNPEF5VH3dXc3QBg6zfGWrKL6yVZwHHLIz+3guYXshslcG3qEPeyjRGd30hnS1gwhWWDh 5G33X2JEbies567Z9Ku6EbZdMYfiU3IfRAfYWYhV5wSwI/GWM6f+UxztdKgqUZY+iltl5e wDHwUM1yYrOhJgT3wzt7o+ZauGBHMnMsh5a3xqXfJBI2lHPmawzQ16K2AMan3/LosI8jd8 HrE2Dz+zSZjdbQZvh+ZIj9wxPU67RAC+GZU3k65oefb1rEUtY1RVIwkI5Nhe8EogfTk3Sd ij8bulG+dL1y4059BooZY+1RhrFTwjHt/P3FWt7CmHEBMBtO+hbKfEeffAyVVA== 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 4Pdc4M0QR3zgNW; Fri, 17 Mar 2023 21:01:23 +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 32HL1Mx1014953; Fri, 17 Mar 2023 21:01:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HL1MDk014952; Fri, 17 Mar 2023 21:01:22 GMT (envelope-from git) Date: Fri, 17 Mar 2023 21:01:22 GMT Message-Id: <202303172101.32HL1MDk014952@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: 488cf4bb6fa1 - stable/13 - daemon: use braces with 'if' consistently List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 488cf4bb6fa1e43dfe923067fdde660a625948c6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=488cf4bb6fa1e43dfe923067fdde660a625948c6 commit 488cf4bb6fa1e43dfe923067fdde660a625948c6 Author: Ihor Antonov AuthorDate: 2023-03-02 03:00:41 +0000 Commit: Kyle Evans CommitDate: 2023-03-17 21:01:01 +0000 daemon: use braces with 'if' consistently Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669 (cherry picked from commit 6b4ef4b16a6930d91d0d99c4ceb75cd43a7526c1) --- usr.sbin/daemon/daemon.c | 81 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index edcdf3141fcc..f9c1f73e193c 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -173,14 +173,16 @@ main(int argc, char *argv[]) break; case 'l': logfac = get_log_mapping(optarg, facilitynames); - if (logfac == -1) + if (logfac == -1) { errx(5, "unrecognized syslog facility"); + } dosyslog = 1; break; case 'm': stdmask = strtol(optarg, &p, 10); - if (p == optarg || stdmask < 0 || stdmask > 3) + if (p == optarg || stdmask < 0 || stdmask > 3) { errx(6, "unrecognized listening mask"); + } break; case 'o': outfn = optarg; @@ -196,13 +198,15 @@ main(int argc, char *argv[]) break; case 'R': restart = strtol(optarg, &p, 0); - if (p == optarg || restart < 1) + if (p == optarg || restart < 1) { errx(6, "invalid restart delay"); + } break; case 's': logpri = get_log_mapping(optarg, prioritynames); - if (logpri == -1) + if (logpri == -1) { errx(4, "unrecognized syslog priority"); + } dosyslog = 1; break; case 'S': @@ -228,20 +232,24 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc == 0) + if (argc == 0) { usage(1); + } - if (!title) + if (!title) { title = argv[0]; + } if (outfn) { outfd = open_log(outfn); - if (outfd == -1) + if (outfd == -1) { err(7, "open"); + } } - if (dosyslog) + if (dosyslog) { openlog(logtag, LOG_PID | LOG_NDELAY, logfac); + } ppfh = pfh = NULL; /* @@ -329,8 +337,9 @@ main(int argc, char *argv[]) goto exit; } restart: - if (pipe(pfd)) + if (pipe(pfd)) { err(1, "pipe"); + } /* * Spawn a child to exec the command. */ @@ -356,27 +365,32 @@ restart: /* Now that we are the child, write out the pid. */ pidfile_write(pfh); - if (user != NULL) + if (user != NULL) { restrict_process(user); + } /* * When forking, the child gets the original sigmask, * and dup'd pipes. */ if (pid == 0) { close(pfd[0]); - if (sigprocmask(SIG_SETMASK, &mask_orig, NULL)) + if (sigprocmask(SIG_SETMASK, &mask_orig, NULL)) { err(1, "sigprogmask"); + } if (stdmask & STDERR_FILENO) { - if (dup2(pfd[1], STDERR_FILENO) == -1) + if (dup2(pfd[1], STDERR_FILENO) == -1) { err(1, "dup2"); + } } if (stdmask & STDOUT_FILENO) { - if (dup2(pfd[1], STDOUT_FILENO) == -1) + if (dup2(pfd[1], STDOUT_FILENO) == -1) { err(1, "dup2"); + } } if (pfd[1] != STDERR_FILENO && - pfd[1] != STDOUT_FILENO) + pfd[1] != STDOUT_FILENO) { close(pfd[1]); + } } execvp(argv[0], argv); /* @@ -436,8 +450,9 @@ restart: } } } - if (restart && !terminate) + if (restart && !terminate) { daemon_sleep(restart, 0); + } if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) { warn("sigprocmask"); goto exit; @@ -451,8 +466,9 @@ exit: close(outfd); close(pfd[0]); close(pfd[1]); - if (dosyslog) + if (dosyslog) { closelog(); + } pidfile_remove(pfh); pidfile_remove(ppfh); exit(1); /* If daemon(3) succeeded exit status does not matter. */ @@ -464,8 +480,9 @@ daemon_sleep(time_t secs, long nsecs) struct timespec ts = { secs, nsecs }; while (!terminate && nanosleep(&ts, &ts) == -1) { - if (errno != EINTR) + if (errno != EINTR) { err(1, "nanosleep"); + } } } @@ -507,8 +524,9 @@ get_log_mapping(const char *str, const CODE *c) { const CODE *cp; for (cp = c; cp->c_name; cp++) - if (strcmp(cp->c_name, str) == 0) + if (strcmp(cp->c_name, str) == 0) { return cp->c_val; + } return -1; } @@ -518,11 +536,13 @@ restrict_process(const char *user) struct passwd *pw = NULL; pw = getpwnam(user); - if (pw == NULL) + if (pw == NULL) { errx(1, "unknown user: %s", user); + } - if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) + if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) { errx(1, "failed to set user environment"); + } setenv("USER", pw->pw_name, 1); setenv("HOME", pw->pw_dir, 1); @@ -546,8 +566,9 @@ listen_child(int fd, struct log_params *logpar) assert(logpar); assert(bytes_read < LBUF_SIZE - 1); - if (do_log_reopen) + if (do_log_reopen) { reopen_log(logpar); + } rv = read(fd, buf + bytes_read, LBUF_SIZE - bytes_read - 1); if (rv > 0) { unsigned char *cp; @@ -568,8 +589,9 @@ listen_child(int fd, struct log_params *logpar) memmove(buf, cp + 1, bytes_read); } /* Wait until the buffer is full. */ - if (bytes_read < LBUF_SIZE - 1) + if (bytes_read < LBUF_SIZE - 1) { return 1; + } do_output(buf, bytes_read, logpar); bytes_read = 0; return 1; @@ -601,16 +623,19 @@ do_output(const unsigned char *buf, size_t len, struct log_params *logpar) assert(len <= LBUF_SIZE); assert(logpar); - if (len < 1) + if (len < 1) { return; - if (logpar->dosyslog) + } + if (logpar->dosyslog) { syslog(logpar->logpri, "%.*s", (int)len, buf); + } if (logpar->outfd != -1) { if (write(logpar->outfd, buf, len) == -1) warn("write"); } - if (logpar->noclose && !logpar->dosyslog && logpar->outfd == -1) + if (logpar->noclose && !logpar->dosyslog && logpar->outfd == -1) { printf("%.*s", (int)len, buf); + } } /* @@ -620,8 +645,9 @@ do_output(const unsigned char *buf, size_t len, struct log_params *logpar) static void handle_term(int signo) { - if (pid > 0 && !child_gone) + if (pid > 0 && !child_gone) { kill(pid, signo); + } terminate = 1; } @@ -662,8 +688,9 @@ reopen_log(struct log_params *lpp) do_log_reopen = 0; outfd = open_log(lpp->outfn); - if (lpp->outfd >= 0) + if (lpp->outfd >= 0) { close(lpp->outfd); + } lpp->outfd = outfd; }