… | |
… | |
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 | } |
… | |
… | |
206 | |
205 | |
207 | #endif |
206 | #endif |
208 | |
207 | |
209 | /*----------------------------------------------------------------------*/ |
208 | /*----------------------------------------------------------------------*/ |
210 | /* |
209 | /* |
211 | * Returns tty file descriptor, or -1 on failure |
210 | * Returns tty file descriptor, or -1 on failure |
212 | */ |
211 | */ |
213 | static int |
212 | static int |
214 | get_tty (char *ttydev) |
213 | get_tty (char *ttydev) |
215 | { |
214 | { |
216 | return open (ttydev, O_RDWR | O_NOCTTY, 0); |
215 | return open (ttydev, O_RDWR | O_NOCTTY, 0); |
… | |
… | |
221 | * Make our tty a controlling tty so that /dev/tty points to us |
220 | * Make our tty a controlling tty so that /dev/tty points to us |
222 | */ |
221 | */ |
223 | static int |
222 | static int |
224 | control_tty (int fd_tty) |
223 | control_tty (int fd_tty) |
225 | { |
224 | { |
|
|
225 | int fd; |
|
|
226 | |
226 | setsid (); |
227 | setsid (); |
227 | |
228 | |
228 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
229 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
229 | /* |
230 | /* |
230 | * Push STREAMS modules: |
231 | * Push STREAMS modules: |
… | |
… | |
251 | ioctl (fd_tty, I_PUSH, "ldterm"); |
252 | ioctl (fd_tty, I_PUSH, "ldterm"); |
252 | ioctl (fd_tty, I_PUSH, "ttcompat"); |
253 | ioctl (fd_tty, I_PUSH, "ttcompat"); |
253 | } |
254 | } |
254 | #endif |
255 | #endif |
255 | |
256 | |
|
|
257 | #ifdef TIOCSCTTY |
256 | ioctl (fd_tty, TIOCSCTTY, NULL); |
258 | ioctl (fd_tty, TIOCSCTTY, NULL); |
|
|
259 | #else |
|
|
260 | fd = open (ttyname (fd_tty), O_RDWR); |
|
|
261 | if (fd >= 0) |
|
|
262 | close (fd); |
|
|
263 | #endif |
257 | |
264 | |
258 | int fd = open ("/dev/tty", O_WRONLY); |
265 | fd = open ("/dev/tty", O_WRONLY); |
259 | if (fd < 0) |
266 | if (fd < 0) |
260 | return -1; /* fatal */ |
267 | return -1; /* fatal */ |
261 | |
268 | |
262 | close (fd); |
269 | close (fd); |
263 | |
270 | |