SHORT DESCRIPTION

Give "zlogin" a "-z" option

LONG DESCRIPTION

Unlike:

 zoneadm
 zonecfg

...zlogin does not take a "-z" option.

I find myself doing this quite often:

# zonecfg -z some_zone
...
# zoneadmin -z some_zone something
...
# zlogin -z some_zone
zlogin: illegal option -- z
usage: zlogin [ -CES ] [ -e cmdchar ] [-l user] zonename [command [args ...] ]

Conesquently this proposal is to add a "-z" option so that the last command example above would log you interactively into "some_zone".

CONSIDERATIONS

1. There must be a "zone" specified somehow

   - consequently in the ABSENCE of a -z option, zlogin would assume the
     first thing it sees after any options is the zone name (as it does
     now)

2. "-z" takes precedence over the first non-option after zlogin

   - as far as I can tell, because -z currently errors, this will affect
     no automated scripts [as those scripts would currently not work]

3. If "-z" does occur it cannot be a "null" option

4. Adding "-z" should not overly disturb current code nor introduce
   unnecessary variables

BUGS

There may very well be a more elegant way to do this.

I haven't changed the "man pages".

I think my "Usage" string is wrong; I'm not sure how to say "Either the first atom after the options must be the zone name or it must be specified by using -z".

I wasn't able to get a full nightly to build but got a build environment stable enough to build this for my running system (SXCE b59) which didn't segfault or do anything funny (well, not in *this* version at least).

PATCH

I have included a patch which adds this "-z"

This patch was made from a Mercurial checkout of the onnv source approx. 19/03/2008 and this is, I think, enough info to identify which one:

bash-3.00$ hg -v identify
cbc537e53089+ tip

[if someone could help me out with a better way to identify what version(s) I have, I'd really appreciate it]

I'm wondering if there'd be any comments?

DSL
diff -r cbc537e53089 usr/src/cmd/zlogin/zlogin.c
--- a/usr/src/cmd/zlogin/zlogin.c	Fri Mar 16 17:42:01 2007 -0700
+++ b/usr/src/cmd/zlogin/zlogin.c	Wed Mar 21 20:12:48 2007 +1030
@@ -138,7 +138,7 @@ usage(void)
 usage(void)
 {
 	(void) fprintf(stderr, gettext("usage: %s [ -CES ] [ -e cmdchar ] "
-	    "[-l user] zonename [command [args ...] ]\n"), pname);
+	    "[-l user] [-z zonename | zonename] [command [args ...] ]\n"), pname);
 	exit(2);
 }
 
@@ -1534,13 +1534,14 @@ main(int argc, char **argv)
 	struct stat sb;
 	char kernzone[ZONENAME_MAX];
 	brand_handle_t bh;
+	int twiddle = 0;
 
 	(void) setlocale(LC_ALL, "");
 	(void) textdomain(TEXT_DOMAIN);
 
 	(void) getpname(argv[0]);
 
-	while ((arg = getopt(argc, argv, "ECR:Se:l:")) != EOF) {
+	while ((arg = getopt(argc, argv, "ECR:Se:l:z:")) != EOF) {
 		switch (arg) {
 		case 'C':
 			console = 1;
@@ -1570,6 +1571,13 @@ main(int argc, char **argv)
 			login = optarg;
 			lflag = 1;
 			break;
+		case 'z':
+			zonename = optarg;
+			fprintf(stderr, "Zone: %s\n", zonename);
+			if (isatty(STDIN_FILENO)) {
+				interactive = 1;
+			}
+			break;
 		default:
 			usage();
 		}
@@ -1602,20 +1610,25 @@ main(int argc, char **argv)
 		 */
 		if (isatty(STDIN_FILENO))
 			interactive = 1;
-		zonename = argv[optind];
+
+		if (zonename == NULL) {
+			zonename = argv[optind];
+		}
 	} else if (optind < (argc - 1)) {
-		if (console) {
-			zerror(gettext("Commands may not be specified for "
-			    "console login."));
+			if (console) {
+				zerror(gettext("Commands may not be specified for "
+				    "console login."));
+				usage();
+			}
+			/* zone name and process name, and possibly some args */
+			if (zonename == NULL) {
+				zonename = argv[optind];
+			}
+			proc_args = &argv[optind + 1];
+			interactive = 0;
+		} else if (zonename == NULL) {
 			usage();
 		}
-		/* zone name and process name, and possibly some args */
-		zonename = argv[optind];
-		proc_args = &argv[optind + 1];
-		interactive = 0;
-	} else {
-		usage();
-	}
 
 	if (getzoneid() != GLOBAL_ZONEID) {
 		zerror(gettext("'%s' may only be used from the global zone"),
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to