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.44 by ayin, Tue Jan 17 17:59:31 2006 UTC vs.
Revision 1.45 by root, Tue Jan 17 18:06:14 2006 UTC

70get_pty_streams (int *fd_tty, char **ttydev) 70get_pty_streams (int *fd_tty, char **ttydev)
71{ 71{
72#ifdef NO_SETOWNER_TTYDEV 72#ifdef NO_SETOWNER_TTYDEV
73 int pfd; 73 int pfd;
74 74
75# ifdef PTYS_ARE_GETPT 75# if defined(PTYS_ARE_GETPT)
76 pfd = getpt(); 76 pfd = getpt();
77# else
78# ifdef PTYS_ARE_POSIX 77# elif defined(PTYS_ARE_POSIX)
79 pfd = posix_openpt (O_RDWR); 78 pfd = posix_openpt (O_RDWR);
80# else 79# else
81 pfd = open ("/dev/ptmx", O_RDWR | O_NOCTTY, 0); 80 pfd = open ("/dev/ptmx", O_RDWR | O_NOCTTY, 0);
82# endif
83# endif 81# endif
84 if (pfd >= 0) 82 if (pfd >= 0)
85 { 83 {
86 if (grantpt (pfd) == 0 /* change slave permissions */ 84 if (grantpt (pfd) == 0 /* change slave permissions */
87 && unlockpt (pfd) == 0) 85 && unlockpt (pfd) == 0)
88 { /* slave now unlocked */ 86 { /* slave now unlocked */
89 *ttydev = strdup (ptsname (pfd)); /* get slave's name */ 87 *ttydev = strdup (ptsname (pfd)); /* get slave's name */
90 return pfd; 88 return pfd;
91 } 89 }
90
92 close (pfd); 91 close (pfd);
93 } 92 }
94#endif 93#endif
94
95 return -1; 95 return -1;
96} 96}
97 97
98static inline int 98static inline int
99get_pty_openpty (int *fd_tty, char **ttydev) 99get_pty_openpty (int *fd_tty, char **ttydev)
108 { 108 {
109 *ttydev = strdup (tty_name); 109 *ttydev = strdup (tty_name);
110 return pfd; 110 return pfd;
111 } 111 }
112#endif 112#endif
113
113 return -1; 114 return -1;
114} 115}
115 116
116static inline int 117static inline int
117get_pty__getpty (int *fd_tty, char **ttydev) 118get_pty__getpty (int *fd_tty, char **ttydev)
121 122
122 *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); 123 *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0);
123 if (*ttydev != NULL) 124 if (*ttydev != NULL)
124 return pfd; 125 return pfd;
125#endif 126#endif
127
126 return -1; 128 return -1;
127} 129}
128 130
129static inline int 131static inline int
130get_pty_ptc (int *fd_tty, char **ttydev) 132get_pty_ptc (int *fd_tty, char **ttydev)
136 { 138 {
137 *ttydev = strdup (ttyname (pfd)); 139 *ttydev = strdup (ttyname (pfd));
138 return pfd; 140 return pfd;
139 } 141 }
140#endif 142#endif
143
141 return -1; 144 return -1;
142} 145}
143 146
144static inline int 147static inline int
145get_pty_clone (int *fd_tty, char **ttydev) 148get_pty_clone (int *fd_tty, char **ttydev)
151 { 154 {
152 *ttydev = strdup (ptsname (pfd)); 155 *ttydev = strdup (ptsname (pfd));
153 return pfd; 156 return pfd;
154 } 157 }
155#endif 158#endif
159
156 return -1; 160 return -1;
157} 161}
158 162
159static inline int 163static inline int
160get_pty_numeric (int *fd_tty, char **ttydev) 164get_pty_numeric (int *fd_tty, char **ttydev)
161{ 165{
162#ifdef PTYS_ARE_NUMERIC 166#ifdef PTYS_ARE_NUMERIC
163 int pfd; 167 int pfd;
164 int idx; 168 int idx;
165 char *c1, *c2; 169 char *c1, *c2;
166 char pty_name[] = "/dev/ptyp???"; 170 char pty_name[] = "/dev/ptyp???";
167 char tty_name[] = "/dev/ttyp???"; 171 char tty_name[] = "/dev/ttyp???";
168 172
169 c1 = &(pty_name[sizeof (pty_name) - 4]); 173 c1 = &(pty_name[sizeof (pty_name) - 4]);
170 c2 = &(tty_name[sizeof (tty_name) - 4]); 174 c2 = &(tty_name[sizeof (tty_name) - 4]);
175
171 for (idx = 0; idx < 256; idx++) 176 for (idx = 0; idx < 256; idx++)
172 { 177 {
173 sprintf (c1, "%d", idx); 178 sprintf (c1, "%d", idx);
174 sprintf (c2, "%d", idx); 179 sprintf (c2, "%d", idx);
180
175 if (access (tty_name, F_OK) < 0) 181 if (access (tty_name, F_OK) < 0)
176 { 182 {
177 idx = 256; 183 idx = 256;
178 break; 184 break;
179 } 185 }
180 186
181 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) >= 0) 187 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) >= 0)
182 { 188 {
183 if (access (tty_name, R_OK | W_OK) == 0) 189 if (access (tty_name, R_OK | W_OK) == 0)
184 { 190 {
185 *ttydev = strdup (tty_name); 191 *ttydev = strdup (tty_name);
186 return pfd; 192 return pfd;
187 } 193 }
188 194
189 close (pfd); 195 close (pfd);
190 } 196 }
191 } 197 }
192#endif 198#endif
199
193 return -1; 200 return -1;
194} 201}
195 202
196static inline int 203static inline int
197get_pty_searched (int *fd_tty, char **ttydev) 204get_pty_searched (int *fd_tty, char **ttydev)
198{ 205{
201# define PTYCHAR1 "pqrstuvwxyz" 208# define PTYCHAR1 "pqrstuvwxyz"
202# endif 209# endif
203# ifndef PTYCHAR2 210# ifndef PTYCHAR2
204# define PTYCHAR2 "0123456789abcdef" 211# define PTYCHAR2 "0123456789abcdef"
205# endif 212# endif
206 int pfd; 213 int pfd;
207 const char *c1, *c2; 214 const char *c1, *c2;
208 char pty_name[] = "/dev/pty??"; 215 char pty_name[] = "/dev/pty??";
209 char tty_name[] = "/dev/tty??"; 216 char tty_name[] = "/dev/tty??";
210 217
211 for (c1 = PTYCHAR1; *c1; c1++) 218 for (c1 = PTYCHAR1; *c1; c1++)
212 { 219 {
213 pty_name[ (sizeof (pty_name) - 3)] = 220 pty_name[ (sizeof (pty_name) - 3)] =
214 tty_name[ (sizeof (pty_name) - 3)] = *c1; 221 tty_name[ (sizeof (pty_name) - 3)] = *c1;
222
215 for (c2 = PTYCHAR2; *c2; c2++) 223 for (c2 = PTYCHAR2; *c2; c2++)
216 { 224 {
217 pty_name[ (sizeof (pty_name) - 2)] = 225 pty_name[ (sizeof (pty_name) - 2)] =
218 tty_name[ (sizeof (pty_name) - 2)] = *c2; 226 tty_name[ (sizeof (pty_name) - 2)] = *c2;
227
219 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) >= 0) 228 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) >= 0)
220 { 229 {
221 if (access (tty_name, R_OK | W_OK) == 0) 230 if (access (tty_name, R_OK | W_OK) == 0)
222 { 231 {
223 *ttydev = strdup (tty_name); 232 *ttydev = strdup (tty_name);
224 return pfd; 233 return pfd;
225 } 234 }
226 235
227 close (pfd); 236 close (pfd);
228 } 237 }
229 } 238 }
230 } 239 }
231#endif 240#endif
241
232 return -1; 242 return -1;
233} 243}
234 244
235static int 245static int
236get_pty (int *fd_tty, char **ttydev) 246get_pty (int *fd_tty, char **ttydev)
237{ 247{
243 || (pfd = get_pty_ptc (fd_tty, ttydev)) != -1 253 || (pfd = get_pty_ptc (fd_tty, ttydev)) != -1
244 || (pfd = get_pty_clone (fd_tty, ttydev)) != -1 254 || (pfd = get_pty_clone (fd_tty, ttydev)) != -1
245 || (pfd = get_pty_numeric (fd_tty, ttydev)) != -1 255 || (pfd = get_pty_numeric (fd_tty, ttydev)) != -1
246 || (pfd = get_pty_searched (fd_tty, ttydev)) != -1) 256 || (pfd = get_pty_searched (fd_tty, ttydev)) != -1)
247 return pfd; 257 return pfd;
258
248 return -1; 259 return -1;
249} 260}
250 261
251/*----------------------------------------------------------------------*/ 262/*----------------------------------------------------------------------*/
252/* 263/*
263 * Make our tty a controlling tty so that /dev/tty points to us 274 * Make our tty a controlling tty so that /dev/tty points to us
264 */ 275 */
265static int 276static int
266control_tty (int fd_tty) 277control_tty (int fd_tty)
267{ 278{
268 int fd;
269
270 /* ---------------------------------------- */
271 setsid (); 279 setsid ();
272 280
273 /* ---------------------------------------- */
274# if defined(PTYS_ARE_PTMX) && defined(I_PUSH) 281# if defined(PTYS_ARE_PTMX) && defined(I_PUSH)
275 /* 282 /*
276 * Push STREAMS modules: 283 * Push STREAMS modules:
277 * ptem: pseudo-terminal hardware emulation module. 284 * ptem: pseudo-terminal hardware emulation module.
278 * ldterm: standard terminal line discipline. 285 * ldterm: standard terminal line discipline.
296 ioctl (fd_tty, I_PUSH, "ptem"); 303 ioctl (fd_tty, I_PUSH, "ptem");
297 ioctl (fd_tty, I_PUSH, "ldterm"); 304 ioctl (fd_tty, I_PUSH, "ldterm");
298 ioctl (fd_tty, I_PUSH, "ttcompat"); 305 ioctl (fd_tty, I_PUSH, "ttcompat");
299 } 306 }
300# endif 307# endif
301 /* ---------------------------------------- */ 308
302 fd = ioctl (fd_tty, TIOCSCTTY, NULL); 309 ioctl (fd_tty, TIOCSCTTY, NULL);
303 /* ---------------------------------------- */ 310
304 fd = open ("/dev/tty", O_WRONLY); 311 int fd = open ("/dev/tty", O_WRONLY);
305 if (fd < 0) 312 if (fd < 0)
306 return -1; /* fatal */ 313 return -1; /* fatal */
314
307 close (fd); 315 close (fd);
308 /* ---------------------------------------- */
309 316
310 return 0; 317 return 0;
311} 318}
312 319
313void 320void
414 } 421 }
415# else 422# else
416 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 423 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
417 chown (name, 0, 0); 424 chown (name, 0, 0);
418# endif 425# endif
419
420 } 426 }
421} 427}
422#endif 428#endif
423 429
424rxvt_ptytty_unix::rxvt_ptytty_unix () 430rxvt_ptytty_unix::rxvt_ptytty_unix ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines