From nobody Sat Mar 18 05:58:04 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 4Pdqzg4kvzz3y8F4 for ; Sat, 18 Mar 2023 05:58:07 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pdqzg2W1Xz3GM6 for ; Sat, 18 Mar 2023 05:58:07 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f42.google.com with SMTP id m35so4475078wms.4 for ; Fri, 17 Mar 2023 22:58:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679119086; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iai2MH9zXq5Lv30BAY43uEemuKzrDsosDJCMtsRtWKw=; b=OlasfWzRIbxIP5vmtcyUjlYgZtaYKZ5Wnls/4plr7uMdnUctB6/XidncuWYWHYvD9i wZdb9Nuq2M88uqJ6jPjoYKchghpvhdD/yv9/yZcI/v1BgbDCzWAQ3U6meYOl33suFDw0 hEbSIl+rskQ0HmAgXj/UIuhkCvhq4itqN/awhgGj0vHak9t781XwyKLC/ZDFXiFt+3WH akQ/cCPti+6Z4QrLdlhcL8iaec1IN/W+FMCToFNlw7tk2X2g922ZZRwoVBDqiuAILV7A HzuVbS8TbD1rzGQKX0QtqRKGhQr1v4L1tL6bp1n8jy/gU2L+ipetxGuau46b6wWPbGmb 2nZQ== X-Gm-Message-State: AO0yUKVmu7XIcIR6ldcVtY9lFAztrTip8hRRW7PyS1u2OJwdDX61yxVO ia//6HP6z9EAeJnhenB/NS1eMI1BpJ7P914H6BjRFw== X-Google-Smtp-Source: AK7set+PgZUWbUMMkiprhVt81xozcglhW0pEVtHJruDWUu5zkBzVrY93ryyA14I3vtGvxR34L6TxPw== X-Received: by 2002:a05:600c:3ac8:b0:3eb:3f2d:f237 with SMTP id d8-20020a05600c3ac800b003eb3f2df237mr27188614wms.6.1679119085950; Fri, 17 Mar 2023 22:58:05 -0700 (PDT) Received: from smtpclient.apple (global-5-144.n-2.net.cam.ac.uk. [131.111.5.144]) by smtp.gmail.com with ESMTPSA id r13-20020a05600c2c4d00b003ed2a3eab71sm3810124wmg.31.2023.03.17.22.58.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2023 22:58:05 -0700 (PDT) Content-Type: text/plain; charset=utf-8 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 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: cf6356fd471c - main - daemon: repace goto exit with daemon_terminate() From: Jessica Clarke In-Reply-To: <202303180553.32I5rfRu088924@gitrepo.freebsd.org> Date: Sat, 18 Mar 2023 05:58:04 +0000 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <202303180553.32I5rfRu088924@gitrepo.freebsd.org> To: Kyle Evans X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Rspamd-Queue-Id: 4Pdqzg2W1Xz3GM6 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 18 Mar 2023, at 05:53, Kyle Evans wrote: >=20 > The branch main has been updated by kevans: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dcf6356fd471cdf4e5c52550f63599881= d722962c >=20 > commit cf6356fd471cdf4e5c52550f63599881d722962c > Author: Ihor Antonov > AuthorDate: 2023-03-18 05:31:12 +0000 > Commit: Kyle Evans > CommitDate: 2023-03-18 05:52:59 +0000 >=20 > daemon: repace goto exit with daemon_terminate() >=20 > Start breaking down big main() > Remove goto exit label and replace it with a function that does = cleanup. >=20 > Comment re-worded by kevans@. >=20 > Pull Request: https://github.com/freebsd/freebsd-src/pull/694 > --- > usr.sbin/daemon/daemon.c | 65 = +++++++++++++++++++++++++++++------------------- > 1 file changed, 40 insertions(+), 25 deletions(-) >=20 > diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c > index b215803cf3c6..2a57d021258e 100644 > --- a/usr.sbin/daemon/daemon.c > +++ b/usr.sbin/daemon/daemon.c > @@ -95,6 +95,8 @@ static void open_pid_files(struct daemon_state *); > static void do_output(const unsigned char *, size_t, struct = daemon_state *); > static void daemon_sleep(time_t, long); > static void daemon_state_init(struct daemon_state *); > +static void daemon_terminate(struct daemon_state *); > + What=E2=80=99s with the whitespace? >=20 > static volatile sig_atomic_t terminate =3D 0; > static volatile sig_atomic_t child_gone =3D 0; > @@ -305,7 +307,7 @@ main(int argc, char *argv[]) > open_pid_files(&state); > if (daemon(state.keep_cur_workdir, state.keep_fds_open) =3D=3D = -1) { > warn("daemon"); > - goto exit; > + daemon_terminate(&state); > } > /* Write out parent pidfile if needed. */ > pidfile_write(state.parent_pidfh); > @@ -341,15 +343,15 @@ main(int argc, char *argv[]) > /* Block SIGTERM to avoid racing until we have forked. = */ > if (sigprocmask(SIG_BLOCK, &mask_term, &mask_orig)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } > if (sigaction(SIGTERM, &act_term, NULL) =3D=3D -1) { > warn("sigaction"); > - goto exit; > + daemon_terminate(&state); > } > if (sigaction(SIGCHLD, &act_chld, NULL) =3D=3D -1) { > warn("sigaction"); > - goto exit; > + daemon_terminate(&state); > } > /* > * Try to protect against pageout kill. Ignore the > @@ -360,7 +362,7 @@ main(int argc, char *argv[]) > if (state.log_reopen && state.output_fd >=3D 0 && > sigaction(SIGHUP, &act_hup, NULL) =3D=3D -1) { > warn("sigaction"); > - goto exit; > + daemon_terminate(&state); > } > restart: > if (pipe(state.pipe_fd)) { > @@ -376,7 +378,7 @@ restart: > /* fork failed, this can only happen when supervision is enabled = */ > if (pid =3D=3D -1) { > warn("fork"); > - goto exit; > + daemon_terminate(&state); > } >=20 >=20 > @@ -425,7 +427,7 @@ restart: > */ > if (sigprocmask(SIG_UNBLOCK, &mask_term, NULL)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } > close(state.pipe_fd[1]); > state.pipe_fd[1] =3D -1; > @@ -458,34 +460,34 @@ restart: > } >=20 > if (terminate) { > - goto exit; > + daemon_terminate(&state); > } >=20 > if (state.child_eof) { > if (sigprocmask(SIG_BLOCK, &mask_susp, NULL)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } > while (!terminate && !child_gone) { > sigsuspend(&mask_orig); > } > if (sigprocmask(SIG_UNBLOCK, &mask_susp, NULL)) = { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } > continue; > } >=20 > if (sigprocmask(SIG_BLOCK, &mask_read, NULL)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } >=20 > state.child_eof =3D !listen_child(state.pipe_fd[0], = &state); >=20 > if (sigprocmask(SIG_UNBLOCK, &mask_read, NULL)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } >=20 > } > @@ -494,23 +496,14 @@ restart: > } > if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) { > warn("sigprocmask"); > - goto exit; > + daemon_terminate(&state); > } > if (state.restart_enabled && !terminate) { > close(state.pipe_fd[0]); > state.pipe_fd[0] =3D -1; > goto restart; > } > -exit: > - close(state.output_fd); > - close(state.pipe_fd[0]); > - close(state.pipe_fd[1]); > - if (state.syslog_enabled) { > - closelog(); > - } > - pidfile_remove(state.child_pidfh); > - pidfile_remove(state.parent_pidfh); > - exit(1); /* If daemon(3) succeeded exit status does not matter. = */ > + daemon_terminate(&state); > } >=20 > static void > @@ -601,7 +594,7 @@ listen_child(int fd, struct daemon_state *state) > static size_t bytes_read =3D 0; > int rv; >=20 > - assert(state); > + assert(state !=3D NULL); > assert(bytes_read < LBUF_SIZE - 1); >=20 > if (do_log_reopen) { > @@ -659,7 +652,7 @@ static void > do_output(const unsigned char *buf, size_t len, struct daemon_state = *state) > { > assert(len <=3D LBUF_SIZE); > - assert(state); > + assert(state !=3D NULL); >=20 > if (len < 1) { > return; > @@ -762,3 +755,25 @@ daemon_state_init(struct daemon_state *state) > .output_filename =3D NULL, > }; > } > + > + Ditto. Jess > +static _Noreturn void > +daemon_terminate(struct daemon_state *state) > +{ > + assert(state !=3D NULL); > + close(state->output_fd); > + close(state->pipe_fd[0]); > + close(state->pipe_fd[1]); > + if (state->syslog_enabled) { > + closelog(); > + } > + pidfile_remove(state->child_pidfh); > + pidfile_remove(state->parent_pidfh); > + > + /* > + * Note that the exit value here doesn't matter in the case of a = clean > + * exit; daemon(3) already detached us from the caller, nothing = is left > + * to care about this one. > + */ > + exit(1); > +}