Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Aug 2018 15:21:47 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r337380 - projects/bectl/sbin/bectl
Message-ID:  <201808061521.w76FLltR038578@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Aug  6 15:21:46 2018
New Revision: 337380
URL: https://svnweb.freebsd.org/changeset/base/337380

Log:
  bectl(8): Provide -u option to unset jail parameters
  
  All but name, host.hostname, and path may be completely unset.

Modified:
  projects/bectl/sbin/bectl/bectl.8
  projects/bectl/sbin/bectl/bectl.c
  projects/bectl/sbin/bectl/bectl_jail.c

Modified: projects/bectl/sbin/bectl/bectl.8
==============================================================================
--- projects/bectl/sbin/bectl/bectl.8	Mon Aug  6 14:40:45 2018	(r337379)
+++ projects/bectl/sbin/bectl/bectl.8	Mon Aug  6 15:21:46 2018	(r337380)
@@ -40,7 +40,7 @@ destroy
 .Ao Ar beName | beName@snapshot Ac
 .Nm
 jail
-.Op Fl o Ar key Ns = Ns Ar value Oc Ns ...
+.Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ...
 .Ao Ar jailID | jailName Ac
 .Ao Ar bootenv Ac
 .Nm
@@ -124,15 +124,32 @@ Specifying
 will automatically unmount without confirmation.
 .Pp
 .It Ic jail
-.Op Fl o Ar key Ns = Ns Ar value Oc Ns ...
+.Oo Fl o Ar key Ns = Ns Ar value | Fl u Ar key Oc Ns ...
 .Ao Ar jailID | jailName Ac
 .Ao Ar bootenv Ac
 .Pp
 Creates a jail of the given boot environment.
 Multiple
 .Fl o
+and
+.Fl u
 arguments may be specified.
-Al
+.Fl o
+will set a jail parameter, and
+.Fl u
+will unset a jail parameter.
+.Pp
+The
+.Va name ,
+.Va host.hostname ,
+and
+.Va path
+may not actually be unset.
+Attempts to unset any of these will revert them to the default values specified
+below, if they have been overwritten by
+.Fl o .
+.Pp
+All
 .Ar key ,
 .Ar value
 pairs are interpreted as jail parameters as described in
@@ -148,9 +165,8 @@ The following default parameters are provided:
 Set to a path in /tmp generated by
 .Xr libbe 8 .
 .El
-.pp
-All default parameters may be overwritten.
 .Pp
+All default parameters may be overwritten.
 .It Ic list
 .Op Fl a
 .Op Fl D

Modified: projects/bectl/sbin/bectl/bectl.c
==============================================================================
--- projects/bectl/sbin/bectl/bectl.c	Mon Aug  6 14:40:45 2018	(r337379)
+++ projects/bectl/sbin/bectl/bectl.c	Mon Aug  6 15:21:46 2018	(r337380)
@@ -70,7 +70,7 @@ usage(bool explicit)
 	    "\tbectl export sourceBe\n"
 	    "\tbectl import targetBe\n"
 	    "\tbectl add (path)*\n"
-	    "\tbectl jail [ -o key=value ]... bootenv\n"
+	    "\tbectl jail [ -o key=value | -u key ]... bootenv\n"
 	    "\tbectl list [-a] [-D] [-H] [-s]\n"
 	    "\tbectl mount beName [mountpoint]\n"
 	    "\tbectl rename origBeName newBeName\n"

Modified: projects/bectl/sbin/bectl/bectl_jail.c
==============================================================================
--- projects/bectl/sbin/bectl/bectl_jail.c	Mon Aug  6 14:40:45 2018	(r337379)
+++ projects/bectl/sbin/bectl/bectl_jail.c	Mon Aug  6 15:21:46 2018	(r337380)
@@ -43,7 +43,9 @@
 
 static void jailparam_grow(void);
 static void jailparam_add(const char *name, const char *val);
+static void jailparam_del(const char *name);
 static bool jailparam_addarg(char *arg);
+static bool jailparam_delarg(char *arg);
 
 static int bectl_search_jail_paths(const char *mnt);
 static int bectl_locate_jail(const char *ident);
@@ -89,6 +91,34 @@ jailparam_add(const char *name, const char *val)
 	++jpused;
 }
 
+static void
+jailparam_del(const char *name)
+{
+	int i;
+	char *val;
+
+	for (i = 0; i < jpused; ++i) {
+		if (strcmp(name, jp[i].jp_name) == 0)
+			break;
+	}
+
+	/* Not found... technically successful */
+	if (i == jpused)
+		return;
+
+	for (; i < jpused - 1; ++i) {
+		val = jailparam_export(&jp[i + 1]);
+
+		jailparam_free(&jp[i], 1);
+		jailparam_init(&jp[i], jp[i + 1].jp_name);
+		jailparam_import(&jp[i], val);
+		free(val);
+	}
+
+	jailparam_free(&jp[i], 1);
+	--jpused;
+}
+
 static bool
 jailparam_addarg(char *arg)
 {
@@ -117,6 +147,23 @@ jailparam_addarg(char *arg)
 	return (true);
 }
 
+static bool
+jailparam_delarg(char *arg)
+{
+	char *name, *val;
+
+	if (arg == NULL)
+		return (false);
+	name = arg;
+	if ((val = strchr(name, '=')) != NULL)
+		*val++ = '\0';
+
+	if (strcmp(name, "path") == 0)
+		*mnt_loc = '\0';
+	jailparam_del(name);
+	return (true);
+}
+
 int
 bectl_cmd_jail(int argc, char *argv[])
 {
@@ -135,7 +182,7 @@ bectl_cmd_jail(int argc, char *argv[])
 	jailparam_add("allow.mount.devfs", "true");
 	jailparam_add("enforce_statfs", "1");
 
-	while ((opt = getopt(argc, argv, "o:")) != -1) {
+	while ((opt = getopt(argc, argv, "o:u:")) != -1) {
 		switch (opt) {
 		case 'o':
 			if (jailparam_addarg(optarg)) {
@@ -147,6 +194,14 @@ bectl_cmd_jail(int argc, char *argv[])
 					default_name = false;
 				if (strcmp(optarg, "host.hostname") == 0)
 					default_hostname = false;
+			}
+			break;
+		case 'u':
+			if (jailparam_delarg(optarg)) {
+				if (strcmp(optarg, "name") == 0)
+					default_name = true;
+				if (strcmp(optarg, "host.hostname") == 0)
+					default_hostname = true;
 			}
 			break;
 		default:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808061521.w76FLltR038578>