[Date Prev] [Date Index] [Date Next] [Thread Prev] [Thread Index] [Thread Next]

[patch] Exec slaves and controlling TTY

Matthew Gabeler-Lee cheetah@fastcat.org
Thu, 28 Sep 2017 01:58:26 GMT


Like several others on the mailing list before me, I'm having problem
with exec consoles that run a program that needs /dev/tty -- i.e. they
need a controlling TTY.

The problem seems to be a (trivial to fix!) bug in conserver -- It
doesn't call the ioctl to set a controlling TTY as part of the child
process setup.

When I went to fix that, I noticed another small bug in the same
function -- it takes an arg for which FD to configure ... but never
obeys it.

Here's a simple patch to fix both.  I /hope/ it's portable.

---- snip ----
diff -urNp conserver-8.2.1/conserver/consent.c
conserver-8.2.1-fixed/conserver/consent.c
--- conserver-8.2.1/conserver/consent.c	2016-11-02 15:54:38.000000000 -0400
+++ conserver-8.2.1-fixed/conserver/consent.c	2017-09-27
21:39:52.249987884 -0400
@@ -513,9 +513,9 @@ SetupTty(CONSENT *pCE, int fd)
      * under PTX (others?) we have to push the compatibility
      * streams modules `ptem', `ld', and `ttcompat'
      */
-    ioctl(1, I_PUSH, "ptem");
-    ioctl(1, I_PUSH, "ldterm");
-    ioctl(1, I_PUSH, "ttcompat");
+    ioctl(fd, I_PUSH, "ptem");
+    ioctl(fd, I_PUSH, "ldterm");
+    ioctl(fd, I_PUSH, "ttcompat");
 #endif

     if (0 != tcgetattr(1, &n_tio)) {
@@ -544,8 +544,13 @@ SetupTty(CONSENT *pCE, int fd)
     n_tio.c_cc[VSTART] = '\021';
     n_tio.c_cc[VSTOP] = '\023';
     n_tio.c_cc[VSUSP] = '\032';
-    if (0 != tcsetattr(1, TCSANOW, &n_tio))
+    if (0 != tcsetattr(fd, TCSANOW, &n_tio))
 	exit(EX_OSERR);
+#ifdef TIOCSCTTY
+    /* Set the tty to be the controlling tty */
+    if (0 != ioctl(fd, TIOCSCTTY, 0))
+	exit(EX_OSERR);
+#endif
 }

 /* setup a virtual device						(ksb)
---- snip ---

-- 
	-Matt
"Reality is that which, when you stop believing in it, doesn't go away".
                -- Philip K. Dick
GPG fingerprint: 0061 15DF D282 D4A9 57CE  77C5 16AF 1460 4A3C C4E9