From nobody Fri Feb 16 13:33:10 2024 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 4TbtFt14D5z5BvgN; Fri, 16 Feb 2024 13:34:42 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [176.36.249.139]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4TbtFs59nVz4bLs; Fri, 16 Feb 2024 13:34:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 41GDXAmM056350; Fri, 16 Feb 2024 15:33:13 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 41GDXAmM056350 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 41GDXA89056349; Fri, 16 Feb 2024 15:33:10 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 16 Feb 2024 15:33:10 +0200 From: Konstantin Belousov To: Warner Losh Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 33a2406eed00 - main - reboot: Use posix_spawn instead of system Message-ID: References: <202402160400.41G40Jgd018717@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202402160400.41G40Jgd018717@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Spamd-Bar: ---- X-Rspamd-Queue-Id: 4TbtFs59nVz4bLs X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:39608, ipnet:176.36.0.0/16, country:UA] On Fri, Feb 16, 2024 at 04:00:19AM +0000, Warner Losh wrote: > The branch main has been updated by imp: > > URL: https://cgit.FreeBSD.org/src/commit/?id=33a2406eed009dbffd7dfa44285c23f0db5a3750 > > commit 33a2406eed009dbffd7dfa44285c23f0db5a3750 > Author: Warner Losh > AuthorDate: 2024-02-16 03:52:31 +0000 > Commit: Warner Losh > CommitDate: 2024-02-16 03:59:22 +0000 > > reboot: Use posix_spawn instead of system > > Use posix_spawn to avoid having to allocate memory needed for the system > command line. > > Sponsored by: Netflix > Reviewed by: jrtc27 > Differential Revision: https://reviews.freebsd.org/D43860 > --- > sbin/reboot/reboot.c | 54 ++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 38 insertions(+), 16 deletions(-) > > diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c > index e9d6487da6a5..d3f1fc9bbb86 100644 > --- a/sbin/reboot/reboot.c > +++ b/sbin/reboot/reboot.c > @@ -29,19 +29,21 @@ > * SUCH DAMAGE. > */ > > -#include > #include > #include > #include > #include > #include > #include > +#include > +#include sys/types.h should go first, the previous location was right > > #include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -69,23 +71,43 @@ static bool donextboot; > static void > zfsbootcfg(const char *pool, bool force) > { > - char *k; > - int rv; > - > - asprintf(&k, > - "zfsbootcfg -z %s -n freebsd:nvstore -k nextboot_enable -v YES", > - pool); > - if (k == NULL) > - E("No memory for zfsbootcfg"); > - > - rv = system(k); > - if (rv == 0) > - return; > + const char * const av[] = { Why not 'static'? > + "zfsbootcfg", > + "-z", > + pool, > + "-n", > + "freebsd:nvstore", > + "-k", > + "nextboot_enable" > + "-v", > + "YES", > + NULL > + }; > + int rv, status; > + pid_t p; > + extern char **environ; > + > + rv = posix_spawnp(&p, av[0], NULL, NULL, __DECONST(char **, av), > + environ); > if (rv == -1) > E("system zfsbootcfg"); > - if (rv == 127) > - E("zfsbootcfg not found in path"); > - E("zfsbootcfg returned %d", rv); > + if (waitpid(p, &status, WEXITED) < 0) { > + if (errno == EINTR) > + return; > + E("waitpid zfsbootcfg"); > + } > + if (WIFEXITED(status)) { > + int e = WEXITSTATUS(status); > + > + if (e == 0) > + return; > + if (e == 127) > + E("zfsbootcfg not found in path"); > + E("zfsbootcfg returned %d", e); > + } > + if (WIFSIGNALED(status)) > + E("zfsbootcfg died with signal %d", WTERMSIG(status)); > + E("zfsbootcfg unexpected status %d", status); > } > > static void