From nobody Thu Jan 15 05:34:36 2026 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 4dsBWP1tbgz6NS17 for ; Thu, 15 Jan 2026 05:34: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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dsBWP1Ckpz41Bn for ; Thu, 15 Jan 2026 05:34:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768455281; 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=yCwZJg/GtrzwroKYf7PZJxhzxkDTTHXP/p9OAi1+PF0=; b=nqZ7NMhy7uz4dX5tzmvPnNKFSHpU0AORtUOpk7CcK/konnY5G6Y5K0VI5YCj6BFoISCtJp j85kmgq0DpkrfEPVWJGjl7mfliJk4bhjzYyHbXzc3g8mlUFw5cNRn9eivw8dYrJAAGnae/ iV59XuEazpckTXJ4xqgal/VQ3tH6nYiHKBcLVVbxsH4o4bWmUnrbceDZnlj7eNBYljYoeQ WbJRG6h8Q6w+2QOl0Dyb/CkWGQ/QVrBUh9yTs+4AeN9RiXw1dC2S58cJhtvucCEvtbaZWj z7De7n5Y+A/kojCsSwbS2qzH5WhW9UAS9NXYmOrraBY72Vvw+eV9dRog7w/8hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768455281; 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=yCwZJg/GtrzwroKYf7PZJxhzxkDTTHXP/p9OAi1+PF0=; b=nVwsw6HZ3uAlj4TpEXoYFLvLwEFCqQvnir7iqnOFooep6j98QXuiHD8hInvjXsbX0cpIH6 ssQCJ4piOc8FG8usz7tQFMnNbRfT1Ba3155jWtjx9hE59QDELUD7+MUFEGKL2PjQPxeMx6 Z7fI8ZtWE3NOdrKfb9mYBNiunrwKHDtnfr85TTb4pVy8kcC+WKdEqM5BTQTc1ucHYloIl0 a7L+7R9Tqf8dgIKCx0xrqWPxq1vc2YVgXVqaMnBzNEVmox/jM4mEHcDrLyJctSa3UYgAD5 t2deUS9i5SNwOE1OfwanlsTN+iz65NosVxdso0vmVKto3Od5NTfCooaW8ZqMfA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768455281; a=rsa-sha256; cv=none; b=uaEnN75S3qNTq5bcyoEZnN7vMSWg6TH9tcCM4rsfcc18MX0ravZZyjkKkX272PdY7FjNFv isq3PAzPdR6url80AFi9fn3SQNUjgejlZDW3ln9cHvgWa2ui77Oi8b5UKjtpNjfjaxJLaC E3HI/WVRvfe9azbZd6ExQHKz6Rps/L2CgzKb+dKhsHd49h+Wr5mXsrO3dVVQDYYeGhdUUr QjXL14eKC+uitjO2KcejzKPUxdiw3MXVP2LOQuXpCjol1pleSq+TxMCaNAGFu21IVKfDsY 4rDZWtyCrr/McQ5pb1oKa8Jt88xWlCOaWXXXcFY95peHaXebA/sOFlxxR+nN5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dsBWP0CJMz4Q for ; Thu, 15 Jan 2026 05:34:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33ba7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 15 Jan 2026 05:34:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jes=C3=BAs?= Daniel Colmenares Oviedo Subject: git: 5810786791d6 - main - jexec: Add -e parameter to customize the environment 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: dtxdf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5810786791d61aa085170afd5a7d449dbd1ec7c6 Auto-Submitted: auto-generated Date: Thu, 15 Jan 2026 05:34:36 +0000 Message-Id: <69687c6c.33ba7.7b15f010@gitrepo.freebsd.org> The branch main has been updated by dtxdf: URL: https://cgit.FreeBSD.org/src/commit/?id=5810786791d61aa085170afd5a7d449dbd1ec7c6 commit 5810786791d61aa085170afd5a7d449dbd1ec7c6 Author: Jesús Daniel Colmenares Oviedo AuthorDate: 2026-01-15 05:25:25 +0000 Commit: Jesús Daniel Colmenares Oviedo CommitDate: 2026-01-15 05:33:25 +0000 jexec: Add -e parameter to customize the environment Currently, to define a new environment variable or modify an existing one, we need to use env(1), which may or may not be available inside the jail, especially in OCI containers created with the scratch layer (i.e., those containers that are only a single static binary, plus configuration files and related stuff). With this option, we can specify environment variables of arbitrary length for the specified process running inside the jail. Reviewed by: jamie@ Approved by: jamie@ Differential Revision: https://reviews.freebsd.org/D54660 --- usr.sbin/jexec/jexec.8 | 13 ++++++++++++- usr.sbin/jexec/jexec.c | 27 ++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/usr.sbin/jexec/jexec.8 b/usr.sbin/jexec/jexec.8 index afcc1839ef75..595d5c2f835d 100644 --- a/usr.sbin/jexec/jexec.8 +++ b/usr.sbin/jexec/jexec.8 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 5, 2025 +.Dd January 11, 2026 .Dt JEXEC 8 .Os .Sh NAME @@ -33,6 +33,7 @@ .Nm .Op Fl l .Op Fl d Ar working-directory +.Op Oo Fl e Ar name Ns = Ns Ar value Oc ... .Op Fl u Ar username | Fl U Ar username .Ar jail Op Ar command ... .Sh DESCRIPTION @@ -66,6 +67,16 @@ or and absent the .Fl d option, commands are run from that (possibly jailed) user's directory. +.It Fl e Ar name Ns = Ns Ar value +Set environment variables. +.Pp +This parameter allows arbitrary environment variables that are available to the process +to be executed inside of the jail, overwriting any previously defined environment variables, +such as those specified by the +.Fl l +parameter. +.Pp +This option can be set multiple times. .It Fl u Ar username The user name from host environment as whom the .Ar command diff --git a/usr.sbin/jexec/jexec.c b/usr.sbin/jexec/jexec.c index a1e443c5ba04..03be63cf8799 100644 --- a/usr.sbin/jexec/jexec.c +++ b/usr.sbin/jexec/jexec.c @@ -59,21 +59,29 @@ main(int argc, char *argv[]) int jid; login_cap_t *lcap = NULL; int ch, clean, dflag, uflag, Uflag; + int env_argc = argc; + char **env_argv = argv; char *cleanenv; const struct passwd *pwd = NULL; const char *username, *shell, *term; const char *workdir; + const char *jexec_args = "d:e:lnu:U:"; ch = clean = dflag = uflag = Uflag = 0; username = NULL; workdir = "/"; - while ((ch = getopt(argc, argv, "d:lnu:U:")) != -1) { + while ((ch = getopt(argc, argv, jexec_args)) != -1) { switch (ch) { case 'd': workdir = optarg; dflag = 1; break; + case 'e': + /* Used later. */ + if (strchr(optarg, '=') == NULL) + errx(1, "%s: Invalid environment variable.", optarg); + break; case 'l': clean = 1; break; @@ -140,6 +148,19 @@ main(int argc, char *argv[]) endpwent(); } + optreset = 1; + optind = 1; + + /* Custom environment */ + while ((ch = getopt(env_argc, env_argv, jexec_args)) != -1) { + switch (ch) { + case 'e': + if (putenv(optarg) == -1) + err(1, "putenv"); + break; + } + } + /* Run the specified command, or the shell */ if (argc > 1) { if (execvp(argv[1], argv + 1) < 0) @@ -192,7 +213,7 @@ usage(void) { fprintf(stderr, "%s\n", - "usage: jexec [-l] [-d working-directory] [-u username | -U username] jail\n" - " [command ...]"); + "usage: jexec [-l] [-d working-directory] [[-e name=value] ...]\n" + " [-u username | -U username] jail [command ...]"); exit(1); }