ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/ptytty.C
(Generate patch)

Comparing libptytty/src/ptytty.C (file contents):
Revision 1.25 by root, Tue Oct 3 11:19:49 2006 UTC vs.
Revision 1.28 by ayin, Tue Jun 26 21:29:30 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines