changeset 21425:2520e61c1c15

6143 Want zoneadm list option for non-global zones only Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk> Reviewed by: Joshua M. Clulow <josh@sysmgr.org> Approved by: Joshua M. Clulow <josh@sysmgr.org>
author Ryan England <rcengland@gmail.com>
date Mon, 03 Jun 2019 20:16:08 -0700
parents 915509b0c716
children 1ac65b648ab2
files usr/src/cmd/zoneadm/zoneadm.c usr/src/man/man1m/zoneadm.1m
diffstat 2 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/zoneadm/zoneadm.c	Thu Apr 18 17:24:11 2019 +0000
+++ b/usr/src/cmd/zoneadm/zoneadm.c	Mon Jun 03 20:16:08 2019 -0700
@@ -134,7 +134,7 @@
 #define	SHELP_READY	"ready"
 #define	SHELP_SHUTDOWN	"shutdown [-r [-- boot_arguments]]"
 #define	SHELP_REBOOT	"reboot [-- boot_arguments]"
-#define	SHELP_LIST	"list [-cipv]"
+#define	SHELP_LIST	"list [-cinpv]"
 #define	SHELP_VERIFY	"verify"
 #define	SHELP_INSTALL	"install [brand-specific args]"
 #define	SHELP_UNINSTALL	"uninstall [-F] [brand-specific args]"
@@ -254,7 +254,7 @@
 		    "option.  When used with the general -z <zone> and/or -u "
 		    "<uuid-match>\n\toptions, lists only the specified "
 		    "matching zone, but lists it\n\tregardless of its state, "
-		    "and the -i and -c options are disallowed.  The\n\t-v "
+		    "and the -i, -c, and -n options are disallowed.  The\n\t-v "
 		    "option can be used to display verbose information: zone "
 		    "name, id,\n\tcurrent state, root directory and options.  "
 		    "The -p option can be used\n\tto request machine-parsable "
@@ -714,7 +714,8 @@
 }
 
 static int
-zone_print_list(zone_state_t min_state, boolean_t verbose, boolean_t parsable)
+zone_print_list(zone_state_t min_state, boolean_t verbose, boolean_t parsable,
+    boolean_t exclude_global)
 {
 	int i;
 	zone_entry_t zent;
@@ -732,8 +733,11 @@
 		 */
 		return (i);
 	}
-	for (i = 0; i < nzents; i++)
+	for (i = 0; i < nzents; i++) {
+		if (exclude_global && zents[i].zid == GLOBAL_ZONEID)
+			continue;
 		zone_print(&zents[i], verbose, parsable);
+	}
 	if (min_state >= ZONE_STATE_RUNNING)
 		return (Z_OK);
 	/*
@@ -1369,14 +1373,15 @@
 {
 	zone_entry_t *zentp, zent;
 	int arg, retv;
-	boolean_t output = B_FALSE, verbose = B_FALSE, parsable = B_FALSE;
+	boolean_t output = B_FALSE, verbose = B_FALSE, parsable = B_FALSE,
+	    exclude_global = B_FALSE;
 	zone_state_t min_state = ZONE_STATE_RUNNING;
 	zoneid_t zone_id = getzoneid();
 
 	if (target_zone == NULL) {
 		/* all zones: default view to running but allow override */
 		optind = 0;
-		while ((arg = getopt(argc, argv, "?cipv")) != EOF) {
+		while ((arg = getopt(argc, argv, "?cinpv")) != EOF) {
 			switch (arg) {
 			case '?':
 				sub_usage(SHELP_LIST, CMD_LIST);
@@ -1397,6 +1402,9 @@
 				    min_state);
 
 				break;
+			case 'n':
+				exclude_global = B_TRUE;
+				break;
 			case 'p':
 				parsable = B_TRUE;
 				break;
@@ -1414,7 +1422,8 @@
 			return (Z_ERR);
 		}
 		if (zone_id == GLOBAL_ZONEID || is_system_labeled()) {
-			retv = zone_print_list(min_state, verbose, parsable);
+			retv = zone_print_list(min_state, verbose, parsable,
+			    exclude_global);
 		} else {
 			fake_up_local_zone(zone_id, &zent);
 			retv = Z_OK;
@@ -1424,7 +1433,7 @@
 	}
 
 	/*
-	 * Specific target zone: disallow -i/-c suboptions.
+	 * Specific target zone: disallow -i/-c/-n suboptions.
 	 */
 	optind = 0;
 	while ((arg = getopt(argc, argv, "?pv")) != EOF) {
--- a/usr/src/man/man1m/zoneadm.1m	Thu Apr 18 17:24:11 2019 +0000
+++ b/usr/src/man/man1m/zoneadm.1m	Mon Jun 03 20:16:08 2019 -0700
@@ -306,8 +306,8 @@
 regardless of its state. In this case, the \fB-i\fR and \fB-c\fR options are
 disallowed.
 .sp
-If neither the \fB-i\fR or \fB-c\fR options are given, all running zones are
-listed.
+If neither the \fB-i\fR, \fB-c\fR, or \fB-n\fR options are given, all running
+zones are listed.
 .sp
 The following \fIlist_options\fR are supported:
 .sp
@@ -333,6 +333,16 @@
 .sp
 .ne 2
 .na
+\fB\fB-n\fR\fR
+.ad
+.sp .6
+.RS 4n
+Do not include the global zone in the list of zones returned.
+.RE
+
+.sp
+.ne 2
+.na
 \fB\fB-p\fR\fR
 .ad
 .sp .6