From nobody Thu Apr 23 03:50:02 2026 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 4g1MYQ67jyz6bTn5 for ; Thu, 23 Apr 2026 03:50:02 +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" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1MYQ2QQYz44jP for ; Thu, 23 Apr 2026 03:50:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776916202; 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=ZMIYXWHoLAaScSzd5/l0+2oDbw6JEq6AxONPSgSGlJU=; b=BboAV1NPCyxgoVFKikmvvUd28tlzDgQAOn0yFe4ZRk3JXap++QxIr7gMVCL9UImuiae3ab wThEXj8YtisBQCY4SYDjCsjZK+GlDdHzpKTDhXOLmhhfZNSISDj0VRkwmxPGSNBZuhZ1yC t3gbLAgKjoEe6UMrUzKyCNuHfF+BBD0HcRI2HJcoM3GrJe4lOif4mWrOWSCB1A7xIzDln7 q4LfdUNWO0kl8kDA2BjVJm3+1k+gbQ1oyrw4t0ZDXI/g37PsOElFYISrQxK6Af4rCFimaI 0w+t1PjtKTd1Ox5jbjZLwkn/6NlHNBLyvHgjGv/YnqN/L1M6e68dTJCLOoPeeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776916202; a=rsa-sha256; cv=none; b=ZdQUTsFnggO7x/IJNHkaYy4tx01Uh7YXz9+IH0KdguEqhai/g8g6wLQ+Z4fl+wnwyieEzn Flp19qX5TrB86X2/nwqh1HgnZ/VM2H/zUwSD1E9qsA8TLOzqmN+8KWNNKAJefjeXFJlwUf inKsIwnbuxQkbSSPlKq7iJ3nxiYtm4nQXV2yW7fKPl7EgM1PHDcm8zUkoFsVOqrkaUpzQn fVXf/w2u2zbXI241mBxf63QmWr9LIFWLvSIm8mS5QfY/ndsVo6n8lZUd3xtwaTGmrpr3Wi C3eEil3ivFZkMthkk4Z+xhtqwbvzpA4FuZkMyl9P5CbBqg2QrRsWX/lkDM6ErQ== 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=1776916202; 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=ZMIYXWHoLAaScSzd5/l0+2oDbw6JEq6AxONPSgSGlJU=; b=iqoBK/NKgNVhXOux4SF5h7+j55vQdkMhCisn5IbJLqLMOYG6WT1pdaT41di674CbwCRXJj 7w4j6g33cIJKjUoCH6YQCDOgxmBOmvYduLQgHuXGvQF3M1Jk4paaSxQXxD9yuid00AWWv3 eUxiOJI/CFGpZHT8jjB07LKsfW63RS/WrCVamKAxqK7sfHJltacmtJgu2brV/O811DPNlv iEjHEAEMHv6DPb15M6hYuhCyOH47a6/UtxlBiaU8j1W4+uanbc0ZaLE+TqT2K41XeGzczX 4B11Zs+6IjDQIdO+K8lh3ZPe2JUAmwVuPA4ebl/mCYnjoyOdQxLxSR6ZH4M7Vg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1MYQ1ZLbz10ws for ; Thu, 23 Apr 2026 03:50:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3b6c9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Apr 2026 03:50:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 6260b7d09a0c - stable/14 - jls: add a -c mode to check for a jail's existence 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6260b7d09a0c52a823caab4cfabc61ff5503bd11 Auto-Submitted: auto-generated Date: Thu, 23 Apr 2026 03:50:02 +0000 Message-Id: <69e996ea.3b6c9.446471b8@gitrepo.freebsd.org> The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6260b7d09a0c52a823caab4cfabc61ff5503bd11 commit 6260b7d09a0c52a823caab4cfabc61ff5503bd11 Author: Kyle Evans AuthorDate: 2025-07-26 03:13:43 +0000 Commit: Kyle Evans CommitDate: 2026-04-23 03:27:47 +0000 jls: add a -c mode to check for a jail's existence This is intended to be primarily used in scripts that want to check if a jail exists before taking some action -- for instance, the jail(8) test cleanup functions that want to remove the jail if it still exists. Having a mode that limits its output for their usage is useful both for cleaner scripts and also to avoid masking real problems. Reviewed by: jamie (cherry picked from commit 1d8590371049bb14a6410fa83cd03d9eca32f764) --- usr.sbin/jls/jls.8 | 20 ++++++++++++++++++-- usr.sbin/jls/jls.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/usr.sbin/jls/jls.8 b/usr.sbin/jls/jls.8 index f7a5eeb321ef..715033082963 100644 --- a/usr.sbin/jls/jls.8 +++ b/usr.sbin/jls/jls.8 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 13, 2025 +.Dd July 25, 2025 .Dt JLS 8 .Os .Sh NAME @@ -35,6 +35,10 @@ .Op Fl dhNnqsv .Op Fl j Ar jail .Op Ar parameter ... +.Nm +.Fl c +.Op Fl d +.Fl j Ar jail .Sh DESCRIPTION The .Nm @@ -54,11 +58,21 @@ for a description of some core parameters. If no .Ar parameters or any of the options -.Fl hns +.Fl chns are given, the following four columns will be printed: jail identifier (jid), IP address (ip4.addr), hostname (host.hostname), and path (path). .Pp +When the +.Fl c +option is used, +.Nm +will not emit any output except for usage errors. +This mode is intended solely to check for a single jail's existence, and it does +not accept any +.Ar parameter +or print-option flags. +.Pp The following options are available: .Bl -tag -width indent .It Fl -libxo @@ -68,6 +82,8 @@ in a selection of different human and machine readable formats. See .Xr xo_options 7 for details on command line arguments. +.It Fl c +Only check for the jail's existence. .It Fl d List .Va dying diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c index 6f8b214e8b9a..f1bddb9bf139 100644 --- a/usr.sbin/jls/jls.c +++ b/usr.sbin/jls/jls.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,7 @@ #define PRINT_SKIP 0x10 #define PRINT_VERBOSE 0x20 #define PRINT_JAIL_NAME 0x40 +#define PRINT_EXISTS 0x80 static struct jailparam *params; static int *param_parent; @@ -82,6 +84,14 @@ static void quoted_print(int pflags, char *name, char *value); static void emit_ip_addr_list(int af_family, const char *list_name, struct jailparam *param); +static void +usage(void) +{ + xo_errx(1, + "usage: jls [-dhNnqv] [-j jail] [param ...]\n" + " jls -c [-d] -j jail"); +} + int main(int argc, char **argv) { @@ -95,12 +105,15 @@ main(int argc, char **argv) xo_set_version(JLS_XO_VERSION); jname = NULL; pflags = jflags = jid = 0; - while ((c = getopt(argc, argv, "adj:hNnqsv")) >= 0) + while ((c = getopt(argc, argv, "acdj:hNnqsv")) >= 0) switch (c) { case 'a': case 'd': jflags |= JAIL_DYING; break; + case 'c': + pflags |= PRINT_EXISTS; + break; case 'j': jid = strtoul(optarg, &ep, 10); if (!jid || *ep) { @@ -131,7 +144,7 @@ main(int argc, char **argv) PRINT_VERBOSE; break; default: - xo_errx(1, "usage: jls [-dhNnqv] [-j jail] [param ...]"); + usage(); } #ifdef INET6 @@ -145,7 +158,24 @@ main(int argc, char **argv) argv += optind; /* Add the parameters to print. */ - if (argc == 0) { + if ((pflags & PRINT_EXISTS) != 0) { + if ((pflags & ~PRINT_EXISTS) != 0) { + xo_warnx("-c is incompatible with other print options"); + usage(); + } else if (argc != 0) { + xo_warnx("-c does not accept non-option arguments"); + usage(); + } else if (jid == 0 && jname == NULL) { + xo_warnx("-j jail to check must be provided for -c"); + usage(); + } + + /* + * Force libxo to be silent, as well -- we're only wanting our + * exit status. + */ + xo_set_style(NULL, XO_STYLE_TEXT); + } else if (argc == 0) { if (pflags & (PRINT_HEADER | PRINT_NAMEVAL)) add_param("all", NULL, (size_t)0, NULL, JP_USER); else if (pflags & PRINT_VERBOSE) { @@ -240,9 +270,17 @@ main(int argc, char **argv) xo_open_list("jail"); /* Fetch the jail(s) and print the parameters. */ if (jid != 0 || jname != NULL) { - if (print_jail(pflags, jflags) < 0) + if (print_jail(pflags, jflags) < 0) { + /* + * We omit errors from existential issues if we're just + * doing a -c check that the jail exists. + */ + if (pflags & PRINT_EXISTS) + exit(1); xo_errx(1, "%s", jail_errmsg); + } } else { + assert((pflags & PRINT_EXISTS) == 0); for (lastjid = 0; (lastjid = print_jail(pflags, jflags)) >= 0; ) ; @@ -393,6 +431,8 @@ print_jail(int pflags, int jflags) jid = jailparam_get(params, nparams, jflags); if (jid < 0) return jid; + else if (pflags & PRINT_EXISTS) + return 0; xo_open_instance("jail");