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.27 by ayin, Mon Jun 25 17:22:40 2007 UTC vs.
Revision 1.33 by ayin, Thu Dec 13 14:42:33 2007 UTC

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 {
134 *ttydev = strdup (slave);
132 return pfd; 135 return pfd;
136 }
133 137
134 return -1; 138 return -1;
135 } 139 }
136 140
137#elif defined(HAVE_DEV_PTC) 141#elif defined(HAVE_DEV_PTC)
221 * Make our tty a controlling tty so that /dev/tty points to us 225 * Make our tty a controlling tty so that /dev/tty points to us
222 */ 226 */
223static int 227static int
224control_tty (int fd_tty) 228control_tty (int fd_tty)
225{ 229{
230 int fd;
231
226 setsid (); 232 setsid ();
227 233
228#if defined(HAVE_DEV_PTMX) && defined(I_PUSH) 234#if defined(HAVE_DEV_PTMX) && defined(I_PUSH)
229 /* 235 /*
230 * Push STREAMS modules: 236 * Push STREAMS modules:
254#endif 260#endif
255 261
256#ifdef TIOCSCTTY 262#ifdef TIOCSCTTY
257 ioctl (fd_tty, TIOCSCTTY, NULL); 263 ioctl (fd_tty, TIOCSCTTY, NULL);
258#else 264#else
259 fd = open (name, O_RDWR); 265 fd = open (ttyname (fd_tty), O_RDWR);
260 if (fd >= 0) 266 if (fd >= 0)
261 close (fd); 267 close (fd);
262#endif 268#endif
263 269
264 int fd = open ("/dev/tty", O_WRONLY); 270 fd = open ("/dev/tty", O_WRONLY);
265 if (fd < 0) 271 if (fd < 0)
266 return -1; /* fatal */ 272 return -1; /* fatal */
267 273
268 close (fd); 274 close (fd);
269 275
321 { 327 {
322#ifdef TTY_GID_SUPPORT 328#ifdef TTY_GID_SUPPORT
323 struct group *gr = getgrnam ("tty"); 329 struct group *gr = getgrnam ("tty");
324 330
325 if (gr) 331 if (gr)
332 {
326 { /* change group ownership of tty to "tty" */ 333 /* change group ownership of tty to "tty" */
327 mode = S_IRUSR | S_IWUSR | S_IWGRP; 334 mode = S_IRUSR | S_IWUSR | S_IWGRP;
328 gid = gr->gr_gid; 335 gid = gr->gr_gid;
329 } 336 }
330 else 337 else
331#endif /* TTY_GID_SUPPORT */ 338#endif /* TTY_GID_SUPPORT */
332 { 339 {
333 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 340 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
334 gid = 0; 341 gid = 0;
335 } 342 }
336 } 343 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines