From nobody Thu Aug 15 22:44:02 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 4WlKtC0TBvz5T1rw; Thu, 15 Aug 2024 22:44:03 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WlKtB6pV8z4HJR; Thu, 15 Aug 2024 22:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723761843; 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=YkGKOwwIH/AyxaqdzMUnjTdwNSmv/ojhP3D/94L+a1o=; b=D8Jhjkmztq+hjqGzdUZzKDu/rzOVaiHwp3MLpNbRcdUjqWjfc3MX1gQFddkQjNM+FWrs+D JYYiUxYZ+lEhru6vfc+V1OAHZqVsdh1gRJ69y12LqtBLVkxpFaiXHNvQ7om1EEi5qDsRDG N9w/pzVdXM0UcXOLbwO0CYTyjpiDyc45yftBkHqtgp3KIxaQ+CTSwtOZMHifK7j6FynCDV U2P5oQWjsxerGeJCKpEe0uRJOlgXL9TUEa0DsSK87cwTo9HdjcmdsmftGTnRUb30ipeFSj z1VdFm4zx9lvVf8fk0Yk4KJjf4zq1ECa8LcHrg9xu5ptpZfNkO/Be66Qb2Hnlw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723761843; a=rsa-sha256; cv=none; b=QQctlR8jFHtv0oyHn425uhmSXzOZMFfpDJ5tTYqyaYazZYIFVs1Bg8Cqmw5CE/wxMA/HGG tV/XAspeKzVV1fF51DV7WmYHp8oTUt7QI7Xbetsyy9futXjEVWkLs2P5aRZ9yflqLuWEuK OrM0DEpAOuT0Zw4i/11Yc7Cik7w5UNtSJHl+PKziT+tbyPpxSH3Ks/Z0Oj+xhEsppLT+To 8/lsIwQG2SH4T5rWqduisg+QtUZljO5MFoi2vy1IIhahN3UEHb6+dQB85bGNFa3tp8FWrM pNHkZpPH3uP3Y+TmhjHSUuIOQoi+eOvmziE3ngQ3u/M+mEmd8I9Wt51QznLUEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723761843; 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=YkGKOwwIH/AyxaqdzMUnjTdwNSmv/ojhP3D/94L+a1o=; b=A4EDRYtJ+V+vcw3Z3qbExkqyNRRmRwmaTgI57DZkYbHIzdfWAGRp1CgUbb/nPqmDVCOzdo cf4yBYI+vLWJijMaT4V3VoUycTlrHLqQQ2MUGDtb6qvqeW4eDEssXiOVKKfXAf2G9MiJtu CO3M5ZJbU938a+PRGPt++5AFrV4hZlCmyb0bxddYJA/yKuVa2LaQPCDjGLrk68D7ERlXP0 GYTpAAjZDlSxeM41i1yeE2uazskrM+MgJR10AdFanUPuzqQ/LHuT/xoqSWviKHkawIk7VG mmfGX0zP3a1H6CculOQyly+RhIxsO6S4NLK6o/zzu/cMkvBMus53Bpts+0vc2w== 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 4WlKtB6HnGzhtM; Thu, 15 Aug 2024 22:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47FMi2OF063886; Thu, 15 Aug 2024 22:44:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47FMi2ju063883; Thu, 15 Aug 2024 22:44:02 GMT (envelope-from git) Date: Thu, 15 Aug 2024 22:44:02 GMT Message-Id: <202408152244.47FMi2ju063883@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: 82cb2a4158fa - main - Update safe_eval.sh to support --export 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 82cb2a4158fa79ec230a5ab41a2f61c253e65c0b Auto-Submitted: auto-generated The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=82cb2a4158fa79ec230a5ab41a2f61c253e65c0b commit 82cb2a4158fa79ec230a5ab41a2f61c253e65c0b Author: Simon J. Gerraty AuthorDate: 2024-08-15 22:42:39 +0000 Commit: Simon J. Gerraty CommitDate: 2024-08-15 22:42:39 +0000 Update safe_eval.sh to support --export This update allows safe_dot --export file ... to export any variables that get set. Reviewed by: obrien --- libexec/rc/safe_eval.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/libexec/rc/safe_eval.sh b/libexec/rc/safe_eval.sh index 10b6ed09c769..0e1410b771cb 100644 --- a/libexec/rc/safe_eval.sh +++ b/libexec/rc/safe_eval.sh @@ -1,9 +1,9 @@ # SPDX-License-Identifier: BSD-2-Clause # RCSid: -# $Id: safe_eval.sh,v 1.12 2023/10/12 18:46:53 sjg Exp $ +# $Id: safe_eval.sh,v 1.16 2024/08/15 02:28:30 sjg Exp $ # -# @(#) Copyright (c) 2023 Simon J. Gerraty +# @(#) Copyright (c) 2023-2024 Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -37,14 +37,33 @@ safe_eval() { eval `cat "$@" | safe_set` } +## +# safe_eval_export [file] +# +# eval variable assignments only from file +# taking care to eliminate any shell meta chars +# export any variables thus set +# +safe_eval_export() { + eval `cat "$@" | safe_set | ${SED:-sed} 's/^\([^=]*\)=.*/&; export \1/'` +} + ## # safe_dot file [...] # # feed all "file" that exist to safe_eval # safe_dot() { - local ef= f - + eval ${local:-:} ef ex f + ef= + ex= + while : + do + case "$1" in + --export) ex=_export; shift;; + *) break;; + esac + done for f in "$@" do test -s $f || continue @@ -52,7 +71,7 @@ safe_dot() { dotted="$dotted $f" done test -z "$ef" && return 1 - safe_eval $ef + safe_eval$ex $ef return 0 }