summaryrefslogtreecommitdiff
path: root/sysutils/rtty/patches/patch-ac
blob: 41cb6a14b8e0b04e3fcf80268fb691af2285775e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$NetBSD: patch-ac,v 1.3 2000/08/02 17:33:45 thorpej Exp $

Make this compile on Solaris.

Fix a bug where rtty would loop forever if its parent process
(such as a shell) were to die and close rtty's standard input.

--- rtty.c.orig	Fri Aug 23 15:25:28 1996
+++ rtty.c	Wed Aug  2 10:25:30 2000
@@ -35,6 +35,10 @@
 #include <pwd.h>
 #include <termios.h>
 
+#if (defined(__sun__) && defined(__svr4__))
+#include <fcntl.h>
+#endif
+
 #include "rtty.h"
 #ifdef NEED_BITYPES_H
 # include "bitypes.h"
@@ -266,13 +270,16 @@
 static void
 tty_input(fd) {
 	static enum {base, need_cr, tilde} state = base;
+	ssize_t cnt;
+	int readone = 0;
 	u_char buf[1];
 
 #if 0
 	fcntl(Tty, F_SETFL, fcntl(Tty, F_GETFL, 0)|O_NONBLOCK);
 #endif
-	while (1 == read(fd, buf, 1)) {
+	while (1 == (cnt = read(fd, buf, 1))) {
 		u_char ch = buf[0];
+		readone = 1;
 
 		switch (state) {
 		case base:
@@ -346,6 +353,14 @@
 			write(Log, buf, 1);
 		}
 	}
+
+	if (readone == 0 && cnt == 0) {
+		/*
+		 * True EOF -- get out now rather than loop forever.
+		 */
+		quit(0);
+	}
+
 #if 0
 	fcntl(Tty, F_SETFL, fcntl(Tty, F_GETFL, 0)&~O_NONBLOCK);
 #endif