summaryrefslogtreecommitdiff
path: root/usr/src/cmd/zoneadm
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2019-06-05 11:43:50 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2019-06-05 11:43:50 +0000
commit6b20f5ea86f57e29a5ccd067ee5cc5d59cad981e (patch)
tree035b51d5fceb0c9d5945ba1ab0474371720c878f /usr/src/cmd/zoneadm
parent4263771df9801298a3c76c40fc650aab69de04e7 (diff)
parent0222d5accac6e2a33600db46cd235825f511de93 (diff)
downloadillumos-joyent-6b20f5ea86f57e29a5ccd067ee5cc5d59cad981e.tar.gz
[illumos-gate merge]
commit 0222d5accac6e2a33600db46cd235825f511de93 6143 Want zoneadm list option for non-global zones only commit 17a5fa85fe0c34b1146222e40a80b42f2aae8500 11108 error: NULL pointer errors commit 1304f648fa20f6bea9d7aa8c2d089ade63ce703c 11104 ldd: NULL pointer errors commit aef9542424e6d6265e68f87a0d573b10ba6a9e1a 11094 libelf: NULL pointer errors commit 4291d474bf7698f3f2016d029ffa665f5b436beb 11077 tem: do not restore image areas also in text mode commit 13a6e30d92032118a54c980158e488cf0aed1abf 11082 loader: Unexpand be32dec() commit 6512942d214590d054e346dac0ae8ce162c1359d 11089 libsldap: return makes integer from pointer without a cast Conflicts: usr/src/cmd/zoneadm/zoneadm.c
Diffstat (limited to 'usr/src/cmd/zoneadm')
-rw-r--r--usr/src/cmd/zoneadm/zoneadm.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/usr/src/cmd/zoneadm/zoneadm.c b/usr/src/cmd/zoneadm/zoneadm.c
index 312159cabd..362a5fa91e 100644
--- a/usr/src/cmd/zoneadm/zoneadm.c
+++ b/usr/src/cmd/zoneadm/zoneadm.c
@@ -133,7 +133,7 @@ struct cmd {
#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]"
@@ -253,7 +253,7 @@ long_help(int cmd_num)
"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 "
@@ -595,14 +595,34 @@ lookup_zone_info(const char *zone_name, zoneid_t zid, zone_entry_t *zent)
}
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)
{
zone_entry_t zent;
FILE *cookie;
struct zoneent *ze;
/*
- * Get the full list of zones from the configuration.
+ * First get the list of running zones from the kernel and print them.
+ * If that is all we need, then return.
+ */
+ if ((i = fetch_zents()) != Z_OK) {
+ /*
+ * No need for error messages; fetch_zents() has already taken
+ * care of this.
+ */
+ return (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);
+ /*
+ * Next, get the full list of zones from the configuration, skipping
+ * any we have already printed.
*/
cookie = setzoneent();
while ((ze = getzoneent_private(cookie)) != NULL) {
@@ -1281,14 +1301,15 @@ list_func(int argc, char *argv[])
{
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);
@@ -1309,6 +1330,9 @@ list_func(int argc, char *argv[])
min_state);
break;
+ case 'n':
+ exclude_global = B_TRUE;
+ break;
case 'p':
parsable = B_TRUE;
break;
@@ -1326,7 +1350,8 @@ list_func(int argc, char *argv[])
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;
@@ -1336,7 +1361,7 @@ list_func(int argc, char *argv[])
}
/*
- * Specific target zone: disallow -i/-c suboptions.
+ * Specific target zone: disallow -i/-c/-n suboptions.
*/
optind = 0;
while ((arg = getopt(argc, argv, "?pv")) != EOF) {