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.65 by ayin, Tue Jun 26 21:30:10 2007 UTC vs.
Revision 1.71 by root, Mon Feb 21 07:41:02 2011 UTC

5 * File: ptytty.C 5 * File: ptytty.C
6 *----------------------------------------------------------------------* 6 *----------------------------------------------------------------------*
7 * 7 *
8 * All portions of code are copyright by their respective author/s. 8 * All portions of code are copyright by their respective author/s.
9 * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> 9 * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
10 * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> 10 * Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de>
11 * Copyright (c) 2006 Emanuele Giaquinta <e.giaquinta@glauco.it> 11 * Copyright (c) 2006 Emanuele Giaquinta <e.giaquinta@glauco.it>
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *---------------------------------------------------------------------*/ 26 *---------------------------------------------------------------------*/
27 27
28#include "../config.h" 28#include "config.h"
29 29
30#include "ptytty.h" 30#include "ptytty.h"
31 31
32#include <cstdlib> 32#include <cstdlib>
33#include <cstring> 33#include <cstring>
34#include <csignal> 34#include <csignal>
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/stat.h>
37#include <unistd.h> 38#include <unistd.h>
38#include <fcntl.h> 39#include <fcntl.h>
39 40
40#ifdef HAVE_SYS_IOCTL_H 41#ifdef HAVE_SYS_IOCTL_H
41# include <sys/ioctl.h> 42# include <sys/ioctl.h>
42#endif 43#endif
43#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H) 44#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
44# include <sys/stropts.h> /* for I_PUSH */ 45# include <sys/stropts.h> /* for I_PUSH */
45#endif 46#endif
46#ifdef HAVE_ISASTREAM 47#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
47# include <stropts.h> 48# include <stropts.h>
48#endif 49#endif
49#if defined(HAVE_PTY_H) 50#if defined(HAVE_PTY_H)
50# include <pty.h> 51# include <pty.h>
51#elif defined(HAVE_LIBUTIL_H) 52#elif defined(HAVE_LIBUTIL_H)
86 87
87 if (pfd >= 0) 88 if (pfd >= 0)
88 { 89 {
89 if (grantpt (pfd) == 0 /* change slave permissions */ 90 if (grantpt (pfd) == 0 /* change slave permissions */
90 && unlockpt (pfd) == 0) 91 && unlockpt (pfd) == 0)
92 {
91 { /* slave now unlocked */ 93 /* slave now unlocked */
92 *ttydev = strdup (ptsname (pfd)); /* get slave's name */ 94 *ttydev = strdup (ptsname (pfd)); /* get slave's name */
93 return pfd; 95 return pfd;
94 } 96 }
95 97
96 close (pfd); 98 close (pfd);
104 static int 106 static int
105 get_pty (int *fd_tty, char **ttydev) 107 get_pty (int *fd_tty, char **ttydev)
106 { 108 {
107 int pfd; 109 int pfd;
108 int res; 110 int res;
109 char tty_name[32];
110 111
111 res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); 112 res = openpty (&pfd, fd_tty, NULL, NULL, NULL);
112 113
113 if (res != -1) 114 if (res != -1)
114 { 115 {
115 *ttydev = strdup (tty_name); 116 *ttydev = strdup (ttyname (*fd_tty));
116 return pfd; 117 return pfd;
117 } 118 }
118 119
119 return -1; 120 return -1;
120 } 121 }
123 124
124 static int 125 static int
125 get_pty (int *fd_tty, char **ttydev) 126 get_pty (int *fd_tty, char **ttydev)
126 { 127 {
127 int pfd; 128 int pfd;
129 char *slave;
128 130
129 *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); 131 slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0);
130 132
131 if (*ttydev != NULL) 133 if (slave != NULL)
132 return pfd;
133
134 return -1;
135 }
136
137#elif defined(HAVE_DEV_PTC)
138
139 static int
140 get_pty (int *fd_tty, char **ttydev)
141 {
142 int pfd;
143
144 if ((pfd = open ("/dev/ptc", O_RDWR | O_NOCTTY, 0)) >= 0)
145 { 134 {
146 *ttydev = strdup (ttyname (pfd));
147 return pfd;
148 }
149
150 return -1;
151 }
152
153#elif defined(HAVE_DEV_CLONE)
154
155 static int
156 get_pty (int *fd_tty, char **ttydev)
157 {
158 int pfd;
159
160 if ((pfd = open ("/dev/ptym/clone", O_RDWR | O_NOCTTY, 0)) >= 0)
161 {
162 *ttydev = strdup (ptsname (pfd)); 135 *ttydev = strdup (slave);
163 return pfd; 136 return pfd;
164 } 137 }
165 138
166 return -1; 139 return -1;
167 } 140 }
243 * documentation is really unclear about whether it is any close () on 216 * documentation is really unclear about whether it is any close () on
244 * the master side or the last close () - i.e. a proper STREAMS dismantling 217 * the master side or the last close () - i.e. a proper STREAMS dismantling
245 * close () - on the master side which causes a hang up to be sent 218 * close () - on the master side which causes a hang up to be sent
246 * through - Geoff Wing 219 * through - Geoff Wing
247 */ 220 */
248# ifdef HAVE_ISASTREAM 221#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
249 if (isastream (fd_tty) == 1) 222 if (isastream (fd_tty) == 1)
250# endif 223# endif
251 { 224 {
252 ioctl (fd_tty, I_PUSH, "ptem"); 225 ioctl (fd_tty, I_PUSH, "ptem");
253 ioctl (fd_tty, I_PUSH, "ldterm"); 226 ioctl (fd_tty, I_PUSH, "ldterm");
323 { 296 {
324#ifdef TTY_GID_SUPPORT 297#ifdef TTY_GID_SUPPORT
325 struct group *gr = getgrnam ("tty"); 298 struct group *gr = getgrnam ("tty");
326 299
327 if (gr) 300 if (gr)
301 {
328 { /* change group ownership of tty to "tty" */ 302 /* change group ownership of tty to "tty" */
329 mode = S_IRUSR | S_IWUSR | S_IWGRP; 303 mode = S_IRUSR | S_IWUSR | S_IWGRP;
330 gid = gr->gr_gid; 304 gid = gr->gr_gid;
331 } 305 }
332 else 306 else
333#endif /* TTY_GID_SUPPORT */ 307#endif /* TTY_GID_SUPPORT */
334 { 308 {
335 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 309 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
336 gid = 0; 310 gid = 0;
337 } 311 }
338 } 312 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines