From nobody Thu Mar 2 03:00:58 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 4PRwpg21P2z3vk49; Thu, 2 Mar 2023 03:00:59 +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 4PRwpg1STtz43yr; Thu, 2 Mar 2023 03:00:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677726059; 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=AhYFLty0UUipE96A+QGCSkgSkXyJHST6Ipsov6ICbU0=; b=k9VLe3abNfK/948MofLGkMHBZpAY7s1JcIWrqtc2yQ0QkFr7BX1GkY7csqGrpUqp9lT2XI uiHkgmB9r8/Zwld4JAQ3RUcWwHYj1xuii7yOkseaV0+x1VaCYU6CV6fRglax6uhCw81J9p mt4PiWHlLmuwcsNo37o8YuIer1UqT6+X13Rzn1FO8sDU9GAzvPaJuRykeq7I6WsMKZVFBW HiEwTsSPmhu1mSn4QwEVHlPfz9wQ6FYwHG29u2rfkFIp2+Nr/VAYxrIEqi1jSLWvrxDGtP iyXr72+Y6c8Df9xptL/09qlv7NG0gT7WLvGZH4D5YNmJk0CpN6qp8oZEno7c3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677726059; 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=AhYFLty0UUipE96A+QGCSkgSkXyJHST6Ipsov6ICbU0=; b=mY9U/E2xT2k4GPnA5ZgWNMaksCP99LsDAixivJFMT4IPTsmivGOmsXTSwcZMCRjUhSxNjt Ly09bn9HVgFopKIIsC0Xr3fdRus6axkX9KdcpISeckw1cLR6mKaf5OrQlkEJ6+eSEZ/kPt cWi7FV4wZesTrPIPnRkhMTt1UyIDz0/Ns95NUUCyK3Sc1/QF4SeRKHGjmhK/jIECopX/Al LijlnnoiRI2B/hCS+tDn75r+0UPRKAYsKWmRm4bcdGnFqhKqNVUV1xn/My2/OF3EvkBix8 9CFZZmJGGukQTsrUT+jfdgyZFryqb8uwjDF3b55CxxbPyb3iQ8kLJbHkfEJaCA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677726059; a=rsa-sha256; cv=none; b=YM4ucxofabRllGvrmIJtxFySLhpQD4xHRgB3wobtHcAOpMsTxoxlmLVMsdEl+rkJqpTYsc XuhTibtcaqToRluOdc9TBKjA14CDnlDs36POpbnoIdWPe2jFYvW5lXm1caJvbYot7Fpq/b XqcTmaPPQU2MiPAmnQqDjRYwUQlMHfuLFbcp5rgYJk8LdOt44rJoWquWlfMDEYSE/AJk7F pdLUlFw5QJlLkdQiUVp3dJ6OVlR+Z5WrfXHw3xfCy2d4FsMECDUTLdoiuPNVvQ/WA4CxME ZqYFhs5WTxmyK1awGLi/JbcthCrU12JJNlJK/L8C0TbhuA7eBOzO6UdDeO01PQ== 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 4PRwpg0WjvzyxW; Thu, 2 Mar 2023 03:00:59 +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 32230wYO032430; Thu, 2 Mar 2023 03:00:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32230wHb032429; Thu, 2 Mar 2023 03:00:58 GMT (envelope-from git) Date: Thu, 2 Mar 2023 03:00:58 GMT Message-Id: <202303020300.32230wHb032429@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: 6b4ef4b16a69 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6b4ef4b16a6930d91d0d99c4ceb75cd43a7526c1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6b4ef4b16a6930d91d0d99c4ceb75cd43a7526c1 commit 6b4ef4b16a6930d91d0d99c4ceb75cd43a7526c1 Author: Ihor Antonov AuthorDate: 2023-03-02 03:00:41 +0000 Commit: Kyle Evans CommitDate: 2023-03-02 03:00:41 +0000 daemon: use braces with 'if' consistently Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669 --- 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; }