--- old/usr/src/cmd/zlogin/zlogin.c	Tue Mar 24 04:17:54 2015
+++ new/usr/src/cmd/zlogin/zlogin.c	Tue Mar 24 04:17:55 2015
@@ -22,7 +22,7 @@
  * 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.
  */
 
 /*
@@ -104,6 +104,7 @@
 
 static int nocmdchar = 0;
 static int failsafe = 0;
+static int disconnect = 0;
 static char cmdchar = '~';
 static int quiet = 0;
 
@@ -152,7 +153,7 @@
 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);
 }
@@ -278,8 +279,8 @@
 	}
 	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");
@@ -1753,7 +1754,7 @@
 	(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;
@@ -1779,6 +1780,9 @@
 		case 'S':
 			failsafe = 1;
 			break;
+		case 'd':
+			disconnect = 1;
+			break;
 		case 'e':
 			set_cmdchar(optarg);
 			break;
@@ -1826,6 +1830,12 @@
 		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)) {
 		/*
--- old/usr/src/cmd/zoneadmd/zcons.c	Tue Mar 24 04:17:55 2015
+++ new/usr/src/cmd/zoneadmd/zcons.c	Tue Mar 24 04:17:55 2015
@@ -23,6 +23,7 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  * Copyright 2012 Joyent, Inc.  All rights reserved.
+ * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  */
 
 /*
@@ -509,7 +510,8 @@
  * the ident string from a client without saving it.
  */
 static int
-get_client_ident(int clifd, pid_t *pid, char *locale, size_t locale_len)
+get_client_ident(int clifd, pid_t *pid, char *locale, size_t locale_len,
+	int *disconnect)
 {
 	char buf[BUFSIZ], *bufp;
 	size_t buflen = sizeof (buf);
@@ -549,7 +551,8 @@
 	}
 
 	/*
-	 * Parse buffer for message of the form: IDENT <pid> <locale>
+	 * Parse buffer for message of the form:
+	 * IDENT <pid> <locale> <disconnect flag>
 	 */
 	bufp = buf;
 	if (strncmp(bufp, "IDENT ", 6) != 0)
@@ -562,6 +565,9 @@
 
 	while (*bufp != '\0' && isspace(*bufp))
 		bufp++;
+	buflen = strlen(bufp) - 1;
+	*disconnect = atoi(&bufp[buflen]);
+	bufp[buflen - 1] = '\0';
 	(void) strlcpy(locale, bufp, locale_len);
 
 	return (0);
@@ -568,7 +574,8 @@
 }
 
 static int
-accept_client(int servfd, pid_t *pid, char *locale, size_t locale_len)
+accept_client(int servfd, pid_t *pid, char *locale, size_t locale_len,
+	int *disconnect)
 {
 	int connfd;
 	struct sockaddr_un cliaddr;
@@ -578,7 +585,8 @@
 	connfd = accept(servfd, (struct sockaddr *)&cliaddr, &clilen);
 	if (connfd == -1)
 		return (-1);
-	if (get_client_ident(connfd, pid, locale, locale_len) == -1) {
+	if (get_client_ident(connfd, pid, locale, locale_len,
+	    disconnect) == -1) {
 		(void) shutdown(connfd, SHUT_RDWR);
 		(void) close(connfd);
 		return (-1);
@@ -601,7 +609,7 @@
 	/*
 	 * After hear its ident string, tell client to get lost.
 	 */
-	if (get_client_ident(connfd, NULL, NULL, 0) == 0) {
+	if (get_client_ident(connfd, NULL, NULL, 0, NULL) == 0) {
 		(void) snprintf(nak, sizeof (nak), "%lu\n",
 		    clientpid);
 		(void) write(connfd, nak, strlen(nak));
@@ -611,7 +619,7 @@
 }
 
 static void
-event_message(int clifd, char *clilocale, zone_evt_t evt)
+event_message(int clifd, char *clilocale, zone_evt_t evt, int dflag)
 {
 	char *str, *lstr = NULL;
 	char lmsg[BUFSIZ];
@@ -635,7 +643,10 @@
 		str = "NOTICE: Zone readied";
 		break;
 	case Z_EVT_ZONE_HALTED:
-		str = "NOTICE: Zone halted";
+		if (dflag)
+			str = "NOTICE: Zone halted.  Disconnecting...";
+		else
+			str = "NOTICE: Zone halted";
 		break;
 	case Z_EVT_ZONE_REBOOTING:
 		if (*boot_args == '\0') {
@@ -651,7 +662,10 @@
 		str = "NOTICE: Zone is being uninstalled.  Disconnecting...";
 		break;
 	case Z_EVT_ZONE_BOOTFAILED:
-		str = "NOTICE: Zone boot failed";
+		if (dflag)
+			str = "NOTICE: Zone boot failed.  Disconnecting...";
+		else
+			str = "NOTICE: Zone boot failed";
 		break;
 	case Z_EVT_ZONE_BADARGS:
 		/*LINTED*/
@@ -708,6 +722,7 @@
 	int pollerr = 0;
 	char clilocale[MAXPATHLEN];
 	pid_t clipid = 0;
+	int disconnect = 0;
 
 	/* console side, watch for read events */
 	pollfds[0].fd = consfd;
@@ -801,7 +816,8 @@
 
 
 			} else if ((clifd = accept_client(servfd, &clipid,
-			    clilocale, sizeof (clilocale))) != -1) {
+			    clilocale, sizeof (clilocale),
+			    &disconnect)) != -1) {
 				pollfds[1].fd = clifd;
 
 			} else {
@@ -827,7 +843,7 @@
 			if (clifd == -1) {
 				break;
 			}
-			event_message(clifd, clilocale, evt);
+			event_message(clifd, clilocale, evt, disconnect);
 			/*
 			 * Special handling for the message that the zone is
 			 * uninstalling; we boot the client, then break out
@@ -838,6 +854,14 @@
 			if (evt == Z_EVT_ZONE_UNINSTALLING) {
 				break;
 			}
+			/*
+			 * Diconnect if -C and -d options were specified and
+			 * zone was halted or failed to boot.
+			 */
+			if ((evt == Z_EVT_ZONE_HALTED ||
+			    evt == Z_EVT_ZONE_BOOTFAILED) && disconnect) {
+				break;
+			}
 		}
 
 	}
--- old/usr/src/man/man1/zlogin.1	Tue Mar 24 04:17:55 2015
+++ new/usr/src/man/man1/zlogin.1	Tue Mar 24 04:17:55 2015
@@ -13,13 +13,14 @@
 .\" Portions Copyright [yyyy] [name of copyright owner]
 .\" Copyright 2013 DEY Storage Systems, Inc.
 .\" Copyright (c) 2014 Gary Mills
-.TH ZLOGIN 1 "Jan 22, 2014"
+.\" Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+.TH ZLOGIN 1 "Mar 17, 2015"
 .SH NAME
 zlogin \- enter a zone
 .SH SYNOPSIS
 .LP
 .nf
-\fBzlogin\fR [\fB-CEQ\fR] [\fB-e\fR \fIc\fR] [\fB-l\fR \fIusername\fR] \fIzonename\fR
+\fBzlogin\fR [\fB-dCEQ\fR] [\fB-e\fR \fIc\fR] [\fB-l\fR \fIusername\fR] \fIzonename\fR
 .fi
 
 .LP
@@ -92,6 +93,16 @@
 Connects to the zone console.
 .RE
 
+.sp
+.ne 2
+.na
+\fB\fB-d\fR\fR
+.ad
+.RS 15n
+Disconnect from the console when the zone halts. This option may only be used
+if the \fB-C\fR option is specified.
+.RE
+
 .sp
 .ne 2
 .na
