Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144469130
D51541.1774808690.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D51541.1774808690.diff
View Options
diff --git a/usr.sbin/jls/jls.8 b/usr.sbin/jls/jls.8
--- 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 @@
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 @@
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
--- a/usr.sbin/jls/jls.c
+++ b/usr.sbin/jls/jls.c
@@ -37,6 +37,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <jail.h>
@@ -59,6 +60,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;
@@ -81,6 +83,14 @@
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)
{
@@ -94,12 +104,15 @@
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) {
@@ -130,7 +143,7 @@
PRINT_VERBOSE;
break;
default:
- xo_errx(1, "usage: jls [-dhNnqv] [-j jail] [param ...]");
+ usage();
}
#ifdef INET6
@@ -144,7 +157,24 @@
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) {
@@ -239,9 +269,17 @@
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; )
;
@@ -392,6 +430,8 @@
jid = jailparam_get(params, nparams, jflags);
if (jid < 0)
return jid;
+ else if (pflags & PRINT_EXISTS)
+ return 0;
xo_open_instance("jail");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 29, 6:24 PM (5 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28225287
Default Alt Text
D51541.1774808690.diff (3 KB)
Attached To
Mode
D51541: jls: add a -c mode to check for a jail's existence
Attached
Detach File
Event Timeline
Log In to Comment