… | |
… | |
86 | |
86 | |
87 | if (pfd >= 0) |
87 | if (pfd >= 0) |
88 | { |
88 | { |
89 | if (grantpt (pfd) == 0 /* change slave permissions */ |
89 | if (grantpt (pfd) == 0 /* change slave permissions */ |
90 | && unlockpt (pfd) == 0) |
90 | && unlockpt (pfd) == 0) |
|
|
91 | { |
91 | { /* slave now unlocked */ |
92 | /* slave now unlocked */ |
92 | *ttydev = strdup (ptsname (pfd)); /* get slave's name */ |
93 | *ttydev = strdup (ptsname (pfd)); /* get slave's name */ |
93 | return pfd; |
94 | return pfd; |
94 | } |
95 | } |
95 | |
96 | |
96 | close (pfd); |
97 | close (pfd); |
… | |
… | |
104 | static int |
105 | static int |
105 | get_pty (int *fd_tty, char **ttydev) |
106 | get_pty (int *fd_tty, char **ttydev) |
106 | { |
107 | { |
107 | int pfd; |
108 | int pfd; |
108 | int res; |
109 | int res; |
109 | char tty_name[32]; |
|
|
110 | |
110 | |
111 | res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
111 | res = openpty (&pfd, fd_tty, NULL, NULL, NULL); |
112 | |
112 | |
113 | if (res != -1) |
113 | if (res != -1) |
114 | { |
114 | { |
115 | *ttydev = strdup (tty_name); |
115 | *ttydev = strdup (ttyname (*fd_tty)); |
116 | return pfd; |
116 | return pfd; |
117 | } |
117 | } |
118 | |
118 | |
119 | return -1; |
119 | return -1; |
120 | } |
120 | } |
… | |
… | |
123 | |
123 | |
124 | static int |
124 | static int |
125 | get_pty (int *fd_tty, char **ttydev) |
125 | get_pty (int *fd_tty, char **ttydev) |
126 | { |
126 | { |
127 | int pfd; |
127 | int pfd; |
|
|
128 | char *slave; |
128 | |
129 | |
129 | *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); |
130 | slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); |
130 | |
131 | |
131 | if (*ttydev != NULL) |
132 | if (slave != NULL) { |
|
|
133 | *ttydev = strdup (slave); |
132 | return pfd; |
134 | return pfd; |
|
|
135 | } |
133 | |
136 | |
134 | return -1; |
137 | return -1; |
135 | } |
138 | } |
136 | |
139 | |
137 | #elif defined(HAVE_DEV_PTC) |
140 | #elif defined(HAVE_DEV_PTC) |
… | |
… | |
221 | * Make our tty a controlling tty so that /dev/tty points to us |
224 | * Make our tty a controlling tty so that /dev/tty points to us |
222 | */ |
225 | */ |
223 | static int |
226 | static int |
224 | control_tty (int fd_tty) |
227 | control_tty (int fd_tty) |
225 | { |
228 | { |
|
|
229 | int fd; |
|
|
230 | |
226 | setsid (); |
231 | setsid (); |
227 | |
232 | |
228 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
233 | #if defined(HAVE_DEV_PTMX) && defined(I_PUSH) |
229 | /* |
234 | /* |
230 | * Push STREAMS modules: |
235 | * Push STREAMS modules: |
… | |
… | |
254 | #endif |
259 | #endif |
255 | |
260 | |
256 | #ifdef TIOCSCTTY |
261 | #ifdef TIOCSCTTY |
257 | ioctl (fd_tty, TIOCSCTTY, NULL); |
262 | ioctl (fd_tty, TIOCSCTTY, NULL); |
258 | #else |
263 | #else |
259 | fd = open (name, O_RDWR); |
264 | fd = open (ttyname (fd_tty), O_RDWR); |
260 | if (fd >= 0) |
265 | if (fd >= 0) |
261 | close (fd); |
266 | close (fd); |
262 | #endif |
267 | #endif |
263 | |
268 | |
264 | int fd = open ("/dev/tty", O_WRONLY); |
269 | fd = open ("/dev/tty", O_WRONLY); |
265 | if (fd < 0) |
270 | if (fd < 0) |
266 | return -1; /* fatal */ |
271 | return -1; /* fatal */ |
267 | |
272 | |
268 | close (fd); |
273 | close (fd); |
269 | |
274 | |
… | |
… | |
321 | { |
326 | { |
322 | #ifdef TTY_GID_SUPPORT |
327 | #ifdef TTY_GID_SUPPORT |
323 | struct group *gr = getgrnam ("tty"); |
328 | struct group *gr = getgrnam ("tty"); |
324 | |
329 | |
325 | if (gr) |
330 | if (gr) |
|
|
331 | { |
326 | { /* change group ownership of tty to "tty" */ |
332 | /* change group ownership of tty to "tty" */ |
327 | mode = S_IRUSR | S_IWUSR | S_IWGRP; |
333 | mode = S_IRUSR | S_IWUSR | S_IWGRP; |
328 | gid = gr->gr_gid; |
334 | gid = gr->gr_gid; |
329 | } |
335 | } |
330 | else |
336 | else |
331 | #endif /* TTY_GID_SUPPORT */ |
337 | #endif /* TTY_GID_SUPPORT */ |
332 | { |
338 | { |
333 | mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
339 | mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; |
334 | gid = 0; |
340 | gid = 0; |
335 | } |
341 | } |
336 | } |
342 | } |