changeset 18408:a2ff6d3af7f6

OS-4136 would like SIGUSR to zlogin to switch in and out of '-N' modes Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
author Patrick Mooney <patrick.f.mooney@gmail.com>
date Fri, 10 Apr 2015 19:26:51 +0000
parents 7f2f1f305bf3
children 9febfcb4d9b7
files usr/src/cmd/zlogin/zlogin.c usr/src/cmd/zoneadmd/zfd.c usr/src/man/man1/zlogin.1
diffstat 3 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/zlogin/zlogin.c	Fri Apr 10 19:42:22 2015 +0000
+++ b/usr/src/cmd/zlogin/zlogin.c	Fri Apr 10 19:26:51 2015 +0000
@@ -113,6 +113,7 @@
 static volatile pid_t child_pid = -1;
 static int interactive = 0;
 static priv_set_t *dropprivs;
+static unsigned int connect_flags = 0;
 
 static int nocmdchar = 0;
 static int failsafe = 0;
@@ -565,6 +566,22 @@
 	}
 }
 
+/*
+ * Toggle zfd EOF mode and notify zoneadmd
+ */
+/*ARGSUSED*/
+static void
+sigusr1(int s)
+{
+	connect_flags ^= ZLOGIN_ZFD_EOF;
+	if (ctlfd != -1) {
+		char buf[BUFSIZ];
+		snprintf(buf, sizeof (buf), "SETFLAGS %u\n",
+		    connect_flags);
+		(void) send_ctl_sock(buf, strlen(buf));
+	}
+}
+
 static volatile int close_on_sig = -1;
 
 static void
@@ -1866,7 +1883,6 @@
 	brand_handle_t bh;
 	char user_cmd[MAXPATHLEN];
 	char authname[MAXAUTHS];
-	unsigned int connect_flags = 0;
 
 	(void) setlocale(LC_ALL, "");
 	(void) textdomain(TEXT_DOMAIN);
@@ -2169,6 +2185,11 @@
 		(void) sigset(SIGWINCH, sigwinch);
 		(void) sigwinch(0);
 
+		if (imode) {
+			/* Allow EOF mode toggling via SIGUSR1 */
+			(void) sigset(SIGUSR1, sigusr1);
+		}
+
 		/*
 		 * Run the I/O loop until we get disconnected.
 		 */
--- a/usr/src/cmd/zoneadmd/zfd.c	Fri Apr 10 19:42:22 2015 +0000
+++ b/usr/src/cmd/zoneadmd/zfd.c	Fri Apr 10 19:26:51 2015 +0000
@@ -600,7 +600,7 @@
 }
 
 static void
-ctlcmd_process(int sockfd, int stdoutfd)
+ctlcmd_process(int sockfd, int stdoutfd, unsigned int *flags)
 {
 	char buf[BUFSIZ];
 	int i;
@@ -634,6 +634,18 @@
 			return;
 		}
 	}
+	if (strncmp(buf, "SETFLAGS ", 9) == 0) {
+		char *next = buf + 9;
+		unsigned int result;
+		errno = 0;
+		result = strtoul(next, &next, 10);
+		if (errno == EINVAL) {
+			goto fail;
+		}
+		*flags = result;
+		(void) write(sockfd, "OK\n", 3);
+		return;
+	}
 fail:
 	(void) write(sockfd, "FAIL\n", 5);
 }
@@ -873,7 +885,7 @@
 		if (pollfds[0].revents &
 		    (POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI)) {
 			/* process control message */
-			ctlcmd_process(ctlfd, stdoutfd);
+			ctlcmd_process(ctlfd, stdoutfd, &flags);
 		} else if (pollfds[0].revents) {
 			/* bail if any error occurs */
 			pollerr = pollfds[0].revents;
--- a/usr/src/man/man1/zlogin.1	Fri Apr 10 19:42:22 2015 +0000
+++ b/usr/src/man/man1/zlogin.1	Fri Apr 10 19:26:51 2015 +0000
@@ -31,7 +31,6 @@
 .fi
 
 .SH DESCRIPTION
-.sp
 .LP
 The \fBzlogin\fR utility is used by the administrator to enter an operating
 system zone. Only a superuser operating in the global system zone can use this
@@ -93,7 +92,6 @@
 .RE
 
 .SH OPTIONS
-.sp
 .LP
 The following options are supported:
 .sp
@@ -184,7 +182,8 @@
 .ad
 .RS 15n
 Nohup. This may only be used with the -I option to avoid sending EOF to the zfd
-device when zlogin's stdin receives EOF.
+device when zlogin's stdin receives EOF. It can also be toggled by sending
+\fBSIGUSR1\fR to an attached zlogin process.
 .RE
 
 .sp
@@ -213,7 +212,6 @@
 .RE
 
 .SS "Escape Sequences"
-.sp
 .LP
 Lines that you type that start with the tilde character (\fB~\fR) are "escape
 sequences". The escape character can be changed using the \fB-e\fR option.
@@ -228,12 +226,10 @@
 .RE
 
 .SH SECURITY
-.sp
 .LP
 Once a process has been placed in a zone other than the global zone, the
 process cannot change zone again, nor can any of its children.
 .SH OPERANDS
-.sp
 .LP
 The following operands are supported:
 .sp
@@ -264,7 +260,6 @@
 .RE
 
 .SH EXIT STATUS
-.sp
 .LP
 In interactive and non-interactive modes, the \fBzlogin\fR utility exits when
 the command or shell in the non-global zone exits. In non-interactive mode, the
@@ -309,7 +304,6 @@
 .RE
 
 .SH ATTRIBUTES
-.sp
 .LP
 See \fBattributes\fR(5) for descriptions of the following attributes:
 .sp
@@ -325,12 +319,10 @@
 .TE
 
 .SH SEE ALSO
-.sp
 .LP
 \fBlogin\fR(1), \fBrsh\fR(1), \fBvi\fR(1), \fBsu\fR(1M), \fBzoneadm\fR(1M),
 \fBzonecfg\fR(1M), \fBattributes\fR(5), \fBzones\fR(5)
 .SH NOTES
-.sp
 .LP
 \fBzlogin\fR fails if its open files or any portion of its address space
 corresponds to an NFS file. This includes the executable itself or the shared