From nobody Fri Mar 17 21:01:41 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 4Pdc4j2xcVz3yqff; Fri, 17 Mar 2023 21:01:41 +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 4Pdc4j1xncz3qYX; Fri, 17 Mar 2023 21:01:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086901; 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=30CCbIcxp1R/w7MHCneZ2NtTePIrbJ69MdhFFLwgu4E=; b=QHJFc7U2PAjHr2XVgkULdp9gf7LpjXSSYL0jhxwXO/arc0/LbiqeDCrKjtNFdVxCSJYsVP GhEXmrtMrivCaAqZHae7Td4TpTmrPbki1jdUrhv3TPJu5Em3Qacr/Ng7V8BHsoqYBm+6xp guROjGtIvk4x9ev4jYoNSjC5JWpsIO4tc27XSeIt2x0sbCBRMXPVhJM7M6f/6rvPH/10x1 69GoKO8VGzvz783z79Ia4SZGseTcQB8hs/RWSWJHdzCSwJ9uVN7jDt4905UBiQDCmgy9SI pSszcO7RnTBlQrjEnLGEOXoIwZZC7336/ECUn8jjZFdptq8ACUEGtWLZC46OqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086901; 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=30CCbIcxp1R/w7MHCneZ2NtTePIrbJ69MdhFFLwgu4E=; b=cqkMp8Wo6dyxEskGhKQljvsuIbvhwr8oJj2oe9fOvOCcXzqxu5iFqtyQ4Ftr40LWodQoxC y3OzVYt0b8V71HM5q4Mkt+N1ednamrK+jvOXzZzy9Me2KlybMlCnwPvQbSiRMX1xzgNG4A tr2FaIXd5mNDn04SPUgFgeJDFya+VWy5DZ2HY37x8EYdKc9giTlkylNuirTnIoatUWtr+5 Blr+z6eCvtvWbe6rwsTf8FZSU8jjjj9RnPiLtOxcDgsq3YXPSvOF7j5d1p9MkL4UsiSfnO c4MKRKS7p4syWaF8USAvFfNrBwqBvXQ+yobmLcZeU2lAHwgN3mW1K+7mg2Wp6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679086901; a=rsa-sha256; cv=none; b=dn0tCS/+rBpSNIBC9jLvxPVGmV5vsVdCA214JoLgi49yAn2awQQodq0xkoYMhX5aaiI92P sAaSOMYdhk64r7Ziy99fWcl0OLPS3WALI7QzjHFPKkhnOHo2ygAa6FO1So7/2IzfefIefA iCIJd0jkcH2npidmXOPMwZlzkWUTgYKZrg3nG9HG02/NewCO5Skocxm4Eom90KR2e3KkCY FpaYHte/AfM5y26JeMfwthPoBw06bwlkBVZrmFS4z2PmpJcSr4aL8a/VzDsHtRomBp/He1 nfZkj7TpYBXYAC7wmcqsnurpkZvbWxTPLaQSOxbWndSGm2NKccPswe3nh7Infw== 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 4Pdc4j13FVzgbV; Fri, 17 Mar 2023 21:01:41 +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 32HL1fGe015290; Fri, 17 Mar 2023 21:01:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HL1fOm015289; Fri, 17 Mar 2023 21:01:41 GMT (envelope-from git) Date: Fri, 17 Mar 2023 21:01:41 GMT Message-Id: <202303172101.32HL1fOm015289@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: ec3a7d28289f - stable/13 - daemon: decouple restart variable 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: ec3a7d28289f40b55ecbd95bdc6c6e2b008de269 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=ec3a7d28289f40b55ecbd95bdc6c6e2b008de269 commit ec3a7d28289f40b55ecbd95bdc6c6e2b008de269 Author: Ihor Antonov AuthorDate: 2023-03-03 05:17:02 +0000 Commit: Kyle Evans CommitDate: 2023-03-17 21:01:03 +0000 daemon: decouple restart variable The 'restart' variable was responsible for enablement of restart behavior and for restart delay. While it may seem convenient it leads to cluttering the exit/restart logic Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672 (cherry picked from commit e781739084e9cb120ef4b6657074d2b7336ee405) --- usr.sbin/daemon/daemon.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index d1efebd0fcc2..08ae5c74b8c2 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -147,6 +147,7 @@ main(int argc, char *argv[]) bool supervision_enabled = false; bool log_reopen = false; bool child_eof = false; + bool restart_enabled = false; char *p = NULL; const char *child_pidfile = NULL; const char *parent_pidfile = NULL; @@ -155,7 +156,7 @@ main(int argc, char *argv[]) int ch = 0; int keep_cur_workdir = 1; int pipe_fd[2] = { -1, -1 }; - int restart = 0; + int restart_delay = 1; int stdmask = STDOUT_FILENO | STDERR_FILENO; struct log_params logparams = { .syslog_enabled = false, @@ -213,11 +214,12 @@ main(int argc, char *argv[]) parent_pidfile = optarg; break; case 'r': - restart = 1; + restart_enabled = true; break; case 'R': - restart = strtol(optarg, &p, 0); - if (p == optarg || restart < 1) { + restart_enabled = true; + restart_delay = strtol(optarg, &p, 0); + if (p == optarg || restart_delay < 1) { errx(6, "invalid restart delay"); } break; @@ -303,8 +305,8 @@ main(int argc, char *argv[]) */ supervision_enabled = child_pidfile != NULL || parent_pidfile != NULL || - restart != 0 || - logparams.output_fd != -1 || + restart_enabled == true || + logparams.output_fd != -1 || logparams.syslog_enabled == true; if (supervision_enabled) { @@ -486,14 +488,14 @@ restart: } } - if (restart && !terminate) { - daemon_sleep(restart, 0); + if (restart_enabled && !terminate) { + daemon_sleep(restart_delay, 0); } if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) { warn("sigprocmask"); goto exit; } - if (restart && !terminate) { + if (restart_enabled && !terminate) { close(pipe_fd[0]); pipe_fd[0] = -1; goto restart;