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

Comparing rxvt-unicode/src/ptytty.C (file contents):
Revision 1.63 by root, Tue Oct 3 11:21:33 2006 UTC vs.
Revision 1.68 by ayin, Tue Dec 11 21:49:12 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
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)
206 209
207#endif 210#endif
208 211
209/*----------------------------------------------------------------------*/ 212/*----------------------------------------------------------------------*/
210/* 213/*
211 * Returns tty file descriptor, or -1 on failure 214 * Returns tty file descriptor, or -1 on failure
212 */ 215 */
213static int 216static int
214get_tty (char *ttydev) 217get_tty (char *ttydev)
215{ 218{
216 return open (ttydev, O_RDWR | O_NOCTTY, 0); 219 return open (ttydev, O_RDWR | O_NOCTTY, 0);
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 */
223static int 226static int
224control_tty (int fd_tty) 227control_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:
251 ioctl (fd_tty, I_PUSH, "ldterm"); 256 ioctl (fd_tty, I_PUSH, "ldterm");
252 ioctl (fd_tty, I_PUSH, "ttcompat"); 257 ioctl (fd_tty, I_PUSH, "ttcompat");
253 } 258 }
254#endif 259#endif
255 260
261#ifdef TIOCSCTTY
256 ioctl (fd_tty, TIOCSCTTY, NULL); 262 ioctl (fd_tty, TIOCSCTTY, NULL);
263#else
264 fd = open (ttyname (fd_tty), O_RDWR);
265 if (fd >= 0)
266 close (fd);
267#endif
257 268
258 int fd = open ("/dev/tty", O_WRONLY); 269 fd = open ("/dev/tty", O_WRONLY);
259 if (fd < 0) 270 if (fd < 0)
260 return -1; /* fatal */ 271 return -1; /* fatal */
261 272
262 close (fd); 273 close (fd);
263 274
315 { 326 {
316#ifdef TTY_GID_SUPPORT 327#ifdef TTY_GID_SUPPORT
317 struct group *gr = getgrnam ("tty"); 328 struct group *gr = getgrnam ("tty");
318 329
319 if (gr) 330 if (gr)
331 {
320 { /* change group ownership of tty to "tty" */ 332 /* change group ownership of tty to "tty" */
321 mode = S_IRUSR | S_IWUSR | S_IWGRP; 333 mode = S_IRUSR | S_IWUSR | S_IWGRP;
322 gid = gr->gr_gid; 334 gid = gr->gr_gid;
323 } 335 }
324 else 336 else
325#endif /* TTY_GID_SUPPORT */ 337#endif /* TTY_GID_SUPPORT */
326 { 338 {
327 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 339 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
328 gid = 0; 340 gid = 0;
329 } 341 }
330 } 342 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines