From nobody Fri Feb 16 04:00:19 2024 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 4TbdW81TTdz59Z36; Fri, 16 Feb 2024 04:00:20 +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 4TbdW80m6cz4GgF; Fri, 16 Feb 2024 04:00:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708056020; 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=a4Q2HgQws7ZeneMdqgAGtc+wKYpIwE5HwTGGgr+ftL4=; b=qRi92jU3PF9IMx5nO//G0z8eYWkQhSbPXdNWZWizqBggOXJibVdw84hidyfjadx7aZ9MsV dbNeGpNf78BE503j1jYxQ+CtEMGayq4Je6P8CSOWI4VI6f2o6lvUzQNmsikFg/9nsZyZRe qW5BEHkTzyT9Cvtr5kfp63j3JsUF9kCJDVsRTFzxfz26khFqb4rUgvBKwVHpR+25At//mj sOArJtdwzvS/uqRHL+q0XXygt0ojHnayIz7TJMLsdMI+eCQKwvRiXpnBFOF2RHtkFThxOU av+MQHo6y4/K2KBCyFwcb6RNTgpxYNVAkrX7fAFCIOiJKV/H8mv/QIPfTT8qsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708056020; 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=a4Q2HgQws7ZeneMdqgAGtc+wKYpIwE5HwTGGgr+ftL4=; b=WNgCD6gFgiUFtOjwMHpDPrIwr2Q2novoUU2RT8CKLDH63MnqAbuIIK53x4voMaRokWZfin woxB+Xs1zMBWMk0SuvKIMhFMoKuL/Rfzpt1JPQQ26VS4jqsUdm5OKMxexYMWdVmdGWwUUd 3egsoexE/UB+26RUh3+so/S4PxvquaeEvSp+I+HvPs5ABl8jQFQgzywvR/H/SJPVsw4Yzg ynZ/9Y1T8mcumTsAQeMPcFV3KUZfBoaaHPsk6nUKrZ5kePr4xTFk206+jqN4xdzK1JIzrE u73mtDGHRjEPsllsZMqgmV+M9GG/OnxH0Hwf5g0SrGh6VMAIoX4HkLkCJCX6pQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708056020; a=rsa-sha256; cv=none; b=bOD+z8hPGFk5G7TAKFe1RqbxKmJv1aQ5+GTaCpE1bHczGhCs75zFTPf74FAaTAtpMFfCEq 05fImrFrKSXu7Kgmw3QXtQBkKDmkM8/yIWjDB7claLtBa+3+jvrYJi6IeXuAnNoKL449rI gHgL35Uw00YQpbnyh1KHNDfXiCVTdEor7Aa2MyIsSvFRRQe+q7rjy01EDF7mjEY4XuFxQC 4H5wfpRitD7/UJphohlgcTW2ThMwxB6ToxK4qeUsAV3HEZtRKSsQxHujLHqL4uRyKmwFw+ 9thFy1D0hN7ZoDwTERf8q0oQJUkx1+GtXGrTTW8vxm5LOIKyaUl7xE62+KOjcQ== 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 4TbdW76wXTz18b2; Fri, 16 Feb 2024 04:00:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41G40JIb018720; Fri, 16 Feb 2024 04:00:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41G40Jgd018717; Fri, 16 Feb 2024 04:00:19 GMT (envelope-from git) Date: Fri, 16 Feb 2024 04:00:19 GMT Message-Id: <202402160400.41G40Jgd018717@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 33a2406eed00 - main - reboot: Use posix_spawn instead of system 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 33a2406eed009dbffd7dfa44285c23f0db5a3750 Auto-Submitted: auto-generated 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 #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[] = { + "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