Skip to content

Instantly share code, notes, and snippets.

@danmcd
Created February 7, 2020 05:09
Show Gist options
  • Save danmcd/9488bf7942bba391ccdd393254316cf4 to your computer and use it in GitHub Desktop.
Save danmcd/9488bf7942bba391ccdd393254316cf4 to your computer and use it in GitHub Desktop.
diff --git a/usr/src/cmd/zonename/zonename.c b/usr/src/cmd/zonename/zonename.c
index 2ab2f1f520..eebadcfbc6 100644
--- a/usr/src/cmd/zonename/zonename.c
+++ b/usr/src/cmd/zonename/zonename.c
@@ -40,6 +40,7 @@
/*
* -t prints "shared" vs. "exclusive"
+ * -i prints the Zone ID number.
*/
int
main(int argc, char *argv[])
@@ -48,21 +49,34 @@ main(int argc, char *argv[])
char zonename[ZONENAME_MAX];
FILE *fp;
int arg;
- boolean_t stacktype = B_FALSE;
+ boolean_t stacktype = B_FALSE, printzoneid = B_FALSE;
(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
opterr = 0;
- while ((arg = getopt(argc, argv, "t")) != EOF) {
+ while ((arg = getopt(argc, argv, "it")) != EOF) {
switch (arg) {
case 't':
stacktype = B_TRUE;
break;
+ case 'i':
+ printzoneid = B_TRUE;
+ break;
}
}
+ if (printzoneid && stacktype) {
+ (void) fputs(gettext("Must select only one of -i or -t.\n"),
+ stderr);
+ return (1);
+ }
+
zoneid = getzoneid();
+ if (printzoneid) {
+ (void) printf("%d\n", zoneid);
+ return (0);
+ }
if (stacktype) {
ushort_t flags;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment