Print this page
5700 add zlogin -d option to allow graceful disconnect when zone is halted
Reviewed by: Andrew Gabriel <illumos@cucumber.demon.co.uk>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

@@ -20,11 +20,11 @@
  */
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2013 DEY Storage Systems, Inc.
  * Copyright (c) 2014 Gary Mills
- * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  */
 
 /*
  * zlogin provides three types of login which allow users in the global
  * zone to access non-global zones.

@@ -102,10 +102,11 @@
 static int interactive = 0;
 static priv_set_t *dropprivs;
 
 static int nocmdchar = 0;
 static int failsafe = 0;
+static int disconnect = 0;
 static char cmdchar = '~';
 static int quiet = 0;
 
 static int pollerr = 0;
 

@@ -150,11 +151,11 @@
 #define CANONIFY_LEN 5
 
 static void
 usage(void)
 {
-        (void) fprintf(stderr, gettext("usage: %s [ -nQCES ] [ -e cmdchar ] "
+        (void) fprintf(stderr, gettext("usage: %s [ -dnQCES ] [ -e cmdchar ] "
             "[-l user] zonename [command [args ...] ]\n"), pname);
         exit(2);
 }
 
 static const char *

@@ -276,12 +277,12 @@
                 zperror(gettext("Could not connect to zone console"));
                 goto bad;
         }
         masterfd = sockfd;
 
-        msglen = snprintf(clientid, sizeof (clientid), "IDENT %lu %s\n",
-            getpid(), setlocale(LC_MESSAGES, NULL));
+        msglen = snprintf(clientid, sizeof (clientid), "IDENT %lu %s %d\n",
+            getpid(), setlocale(LC_MESSAGES, NULL), disconnect);
 
         if (msglen >= sizeof (clientid) || msglen < 0) {
                 zerror("protocol error");
                 goto bad;
         }

@@ -1751,11 +1752,11 @@
         (void) textdomain(TEXT_DOMAIN);
 
         (void) getpname(argv[0]);
         username = get_username();
 
-        while ((arg = getopt(argc, argv, "nECR:Se:l:Q")) != EOF) {
+        while ((arg = getopt(argc, argv, "dnECR:Se:l:Q")) != EOF) {
                 switch (arg) {
                 case 'C':
                         console = 1;
                         break;
                 case 'E':

@@ -1777,10 +1778,13 @@
                         quiet = 1;
                         break;
                 case 'S':
                         failsafe = 1;
                         break;
+                case 'd':
+                        disconnect = 1;
+                        break;
                 case 'e':
                         set_cmdchar(optarg);
                         break;
                 case 'l':
                         login = optarg;

@@ -1824,10 +1828,16 @@
 
         if (failsafe != 0 && lflag != 0) {
                 zerror(gettext("-l may not be specified for failsafe login"));
                 usage();
         }
+
+        if (!console && disconnect != 0) {
+                zerror(gettext(
+                    "-d may only be specified with console login"));
+                usage();
+        }
 
         if (optind == (argc - 1)) {
                 /*
                  * zone name, no process name; this should be an interactive
                  * as long as STDIN is really a tty.