summaryrefslogtreecommitdiff
path: root/x11/mlterm/patches/patch-ad
blob: 8e2e27edc1ecb75ba02e88e02adf9a5b92638d7e (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
$NetBSD: patch-ad,v 1.1 2005/03/06 17:50:49 hira Exp $

--- kiklib/src/kik_pty_streams.c.orig	2004-10-23 06:59:39.000000000 +0900
+++ kiklib/src/kik_pty_streams.c	2005-03-05 23:07:02.000000000 +0900
@@ -9,6 +9,7 @@
 /* When _XOPEN_SOURCE is defined,
  * u_int/u_long/... may not be defined without _BSD_SOURCE */
 #define  _BSD_SOURCE 1
+#define  _NETBSD_SOURCE 1
 
 /* for solaris */
 #define __EXTENSIONS__
@@ -34,6 +35,9 @@
 #ifdef  HAVE_SYS_STROPTS_H
 #include  <sys/stropts.h>
 #endif
+#ifdef __NetBSD__
+#include  <util.h>
+#endif
 
 #include  "kik_str.h"		/* strdup */
 #include  "kik_debug.h"
@@ -99,13 +103,30 @@
 		return  -1;
 	}
 
-	fcntl(*master, F_SETFL, O_NDELAY);
-
 	if( ( *slave = open( ttydev, O_RDWR | O_NOCTTY, 0)) < 0)
 	{
 		return -1;
 	}
 
+	if ((*slave_name = strdup(ttydev)) == NULL) {
+		close(*master);
+		close(*slave);
+		return -1;
+	}
+
+	pid = fork();
+	if (pid == -1) {
+		free(*slave_name);
+		return -1;
+	}
+	else if(pid == 0) {
+		close(*master);
+		login_tty(*slave);
+		return 0;
+	}
+
+	fcntl(*master, F_SETFL, O_NDELAY);
+
 	/*
 	 * cygwin doesn't have isastream.
 	 */
@@ -204,78 +225,13 @@
 		}
 	}
 
-	if( ( *slave_name = strdup( ttydev)) == NULL)
-	{
-		close( *master) ;
-		close( *slave) ;
-
-		return  -1 ;
-	}
-
-	pid = fork() ;
-
-	if( pid == -1)
-	{
-		/* fork failed */
-
-		free( *slave_name) ;
-
-		return  -1 ;
-	}
-	else if( pid == 0)
-	{
-		/* child */
-
-		close(*master) ;
-#ifdef HAVE_SETSID
-		setsid() ;
-#else /*HAVE_SETSID*/
-#ifdef TIOCNOTTY
-		fd = open("/dev/tty", O_RDWR | O_NOCTTY);
-		if (fd >= 0)
-		{
-			ioctl(fd, TIOCNOTTY, NULL);
-			close(fd);
-		}
-#endif /*TIOCNOTTY*/
-#endif /*HAVE_SETSID*/
-		fd = open("/dev/tty", O_RDWR | O_NOCTTY);
-		if (fd >= 0)
-		{
-			close(fd);
-		}
-		fd = open(ttydev, O_RDWR);
-		if (fd >= 0)
-		{
-			close(fd);
-		}
-		fd = open("/dev/tty", O_WRONLY);
-		if (fd < 0)
-		{
-			return -1;
-		}
-		close(fd);
-
-		dup2( *slave , 0) ;
-		dup2( *slave , 1) ;
-		dup2( *slave , 2) ;
-
-		if( *slave > STDERR_FILENO)
-		{
-			close(*slave) ;
-		}
-
-		cfsetispeed( &tio , B9600) ;
-		cfsetospeed( &tio , B9600) ;
+	cfsetispeed(&tio, B9600);
+	cfsetospeed(&tio, B9600);
 
-		if( tcsetattr(STDIN_FILENO, TCSANOW , &tio) < 0)
-		{
-		#ifdef  DEBUG
-			kik_warn_printf( KIK_DEBUG_TAG " tcsetattr() failed.\n") ;
-		#endif
-		}
-
-		return  0 ;
+	if(tcsetattr(STDIN_FILENO, TCSANOW , &tio) < 0) {
+	#ifdef  DEBUG
+		kik_warn_printf( KIK_DEBUG_TAG " tcsetattr() failed.\n") ;
+	#endif
 	}
 
 	return  pid ;