… | |
… | |
63 | |
63 | |
64 | /* ------------------------------------------------------------------------- * |
64 | /* ------------------------------------------------------------------------- * |
65 | * GET PSEUDO TELETYPE - MASTER AND SLAVE * |
65 | * GET PSEUDO TELETYPE - MASTER AND SLAVE * |
66 | * ------------------------------------------------------------------------- */ |
66 | * ------------------------------------------------------------------------- */ |
67 | /* |
67 | /* |
68 | * Returns pty file descriptor, or -1 on failure |
68 | * Returns pty file descriptor, or -1 on failure |
69 | * If successful, ttydev is set to the name of the slave device. |
69 | * If successful, ttydev is set to the name of the slave device. |
70 | * fd_tty _may_ also be set to an open fd to the slave device |
70 | * fd_tty _may_ also be set to an open fd to the slave device |
71 | */ |
71 | */ |
72 | #if defined(UNIX98_PTY) |
72 | #if defined(UNIX98_PTY) |
73 | |
73 | |
… | |
… | |
104 | static int |
104 | static int |
105 | get_pty (int *fd_tty, char **ttydev) |
105 | get_pty (int *fd_tty, char **ttydev) |
106 | { |
106 | { |
107 | int pfd; |
107 | int pfd; |
108 | int res; |
108 | int res; |
109 | char tty_name[32]; |
109 | |
110 | |
|
|
111 | res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
110 | res = openpty (&pfd, fd_tty, NULL, NULL, NULL); |
112 | |
111 | |
113 | if (res != -1) |
112 | if (res != -1) |
114 | { |
113 | { |
115 | *ttydev = strdup (tty_name); |
114 | *ttydev = strdup (ttyname (*fd_tty)); |
116 | return pfd; |
115 | return pfd; |
117 | } |
116 | } |
118 | |
117 | |
119 | return -1; |
118 | return -1; |
120 | } |
119 | } |
… | |
… | |
123 | |
122 | |
124 | static int |
123 | static int |
125 | get_pty (int *fd_tty, char **ttydev) |
124 | get_pty (int *fd_tty, char **ttydev) |
126 | { |
125 | { |
127 | int pfd; |
126 | int pfd; |
|
|
127 | char *slave; |
128 | |
128 | |
129 | *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); |
129 | slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); |
130 | |
130 | |
131 | if (*ttydev != NULL) |
131 | if (slave != NULL) { |
|
|
132 | *ttydev = strdup (slave); |
132 | return pfd; |
133 | return pfd; |
|
|
134 | } |
133 | |
135 | |
134 | return -1; |
136 | return -1; |
135 | } |
137 | } |
136 | |
138 | |
137 | #elif defined(HAVE_DEV_PTC) |
139 | #elif defined(HAVE_DEV_PTC) |
… | |
… | |
206 | |
208 | |
207 | #endif |
209 | #endif |
208 | |
210 | |
209 | /*----------------------------------------------------------------------*/ |
211 | /*----------------------------------------------------------------------*/ |
210 | /* |
212 | /* |
211 | * Returns tty file descriptor, or -1 on failure |
213 | * Returns tty file descriptor, or -1 on failure |
212 | */ |
214 | */ |
213 | static int |
215 | static int |
214 | get_tty (char *ttydev) |
216 | get_tty (char *ttydev) |
215 | { |
217 | { |
216 | return open (ttydev, O_RDWR | O_NOCTTY, 0); |
218 | return open (ttydev, O_RDWR | O_NOCTTY, 0); |
… | |
… | |
221 | * Make our tty a controlling tty so that /dev/tty points to us |
223 | * Make our tty a controlling tty so that /dev/tty points to us |
222 | */ |
224 | */ |
223 | static int |
225 | static int |
224 | control_tty (int fd_tty) |
226 | control_tty (int fd_tty) |
225 | { |
227 | { |
|
|
228 | int fd; |
|
|
229 | |
226 | setsid (); |
230 | setsid (); |
227 | |
231 | |
228 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
232 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
229 | /* |
233 | /* |
230 | * Push STREAMS modules: |
234 | * Push STREAMS modules: |
… | |
… | |
251 | ioctl (fd_tty, I_PUSH, "ldterm"); |
255 | ioctl (fd_tty, I_PUSH, "ldterm"); |
252 | ioctl (fd_tty, I_PUSH, "ttcompat"); |
256 | ioctl (fd_tty, I_PUSH, "ttcompat"); |
253 | } |
257 | } |
254 | #endif |
258 | #endif |
255 | |
259 | |
|
|
260 | #ifdef TIOCSCTTY |
256 | ioctl (fd_tty, TIOCSCTTY, NULL); |
261 | ioctl (fd_tty, TIOCSCTTY, NULL); |
|
|
262 | #else |
|
|
263 | fd = open (ttyname (fd_tty), O_RDWR); |
|
|
264 | if (fd >= 0) |
|
|
265 | close (fd); |
|
|
266 | #endif |
257 | |
267 | |
258 | int fd = open ("/dev/tty", O_WRONLY); |
268 | fd = open ("/dev/tty", O_WRONLY); |
259 | if (fd < 0) |
269 | if (fd < 0) |
260 | return -1; /* fatal */ |
270 | return -1; /* fatal */ |
261 | |
271 | |
262 | close (fd); |
272 | close (fd); |
263 | |
273 | |
… | |
… | |
320 | { /* change group ownership of tty to "tty" */ |
330 | { /* change group ownership of tty to "tty" */ |
321 | mode = S_IRUSR | S_IWUSR | S_IWGRP; |
331 | mode = S_IRUSR | S_IWUSR | S_IWGRP; |
322 | gid = gr->gr_gid; |
332 | gid = gr->gr_gid; |
323 | } |
333 | } |
324 | else |
334 | else |
325 | #endif /* TTY_GID_SUPPORT */ |
335 | #endif /* TTY_GID_SUPPORT */ |
326 | { |
336 | { |
327 | mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
337 | mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
328 | gid = 0; |
338 | gid = 0; |
329 | } |
339 | } |
330 | } |
340 | } |