1 /* Copyright (c) 1993-2002
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Copyright (c) 1987 Oliver Laumann
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file COPYING); if not, write to the
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 ****************************************************************
25 #include <sys/types.h>
35 # include <sys/ioctl.h>
38 /* for solaris 2.1, Unixware (SVR4.2) and possibly others */
39 #if defined (HAVE_SVR4_PTYS) && defined (HAVE_SYS_STROPTS_H)
40 # include <sys/stropts.h>
43 #if defined(sun) && defined(LOCKPTY) && !defined(TIOCEXCL)
44 # include <sys/ttold.h>
49 # include <sys/sioctl.h>
54 # include <sys/sysmacros.h>
60 * if no PTYRANGE[01] is in the config file, we pick a default
63 # define PTYRANGE0 "qpr"
66 # define PTYRANGE1 "0123456789abcdef"
69 /* SVR4 pseudo ttys don't seem to work with SCO-5 */
71 # undef HAVE_SVR4_PTYS
76 /* used for opening a new pty-pair: */
77 static char PtyName
[32], TtyName
[32];
79 #if !(defined(sequent) || defined(_SEQUENT_) || defined(HAVE_SVR4_PTYS))
81 static char PtyProto
[] = "/dev/ptym/ptyXY";
82 static char TtyProto
[] = "/dev/pty/ttyXY";
85 static char PtyProto
[] = "/dev/ptypXY";
86 static char TtyProto
[] = "/dev/ttypXY";
88 static char PtyProto
[] = "/dev/ptyXY";
89 static char TtyProto
[] = "/dev/ttyXY";
94 static void initmaster
__P((int));
97 /* sun's utmp_update program opens the salve side, thus corrupting
105 * Open all ptys with O_NOCTTY, just to be on the safe side
106 * (RISCos mips breaks otherwise)
112 /***************************************************************/
119 tcflush(f
, TCIOFLUSH
);
122 (void) ioctl(f
, TIOCFLUSH
, (char *) 0);
126 (void) ioctl(f
, TIOCEXCL
, (char *) 0);
136 #if defined(I_PUSH) && defined(HAVE_SVR4_PTYS) && !defined(sgi) && !defined(linux) && !defined(__osf__) && !defined(M_UNIX)
137 if (ioctl(f
, I_PUSH
, "ptem"))
138 Panic(errno
, "InitPTY: cannot I_PUSH ptem");
139 if (ioctl(f
, I_PUSH
, "ldterm"))
140 Panic(errno
, "InitPTY: cannot I_PUSH ldterm");
142 if (ioctl(f
, I_PUSH
, "ttcompat"))
143 Panic(errno
, "InitPTY: cannot I_PUSH ttcompat");
148 /***************************************************************/
150 #if defined(OSX) && !defined(PTY_DONE)
157 if ((f
= open_controlling_pty(TtyName
)) < 0)
165 /***************************************************************/
167 #if (defined(sequent) || defined(_SEQUENT_)) && !defined(PTY_DONE)
176 if ((f
= getpseudotty(&s
, &m
)) < 0)
181 strncpy(PtyName
, m
, sizeof(PtyName
));
182 strncpy(TtyName
, s
, sizeof(TtyName
));
189 /***************************************************************/
191 #if defined(__sgi) && !defined(PTY_DONE)
198 char *name
, *_getpty();
199 sigret_t (*sigcld
)__P(SIGPROTOARG
);
202 * SIGCHLD set to SIG_DFL for _getpty() because it may fork() and
203 * exec() /usr/adm/mkpts
205 sigcld
= signal(SIGCHLD
, SIG_DFL
);
206 name
= _getpty(&f
, O_RDWR
| O_NONBLOCK
, 0600, 0);
207 signal(SIGCHLD
, sigcld
);
217 /***************************************************************/
219 #if defined(MIPS) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
228 strcpy(PtyName
, "/dev/ptc");
229 if ((f
= open(PtyName
, O_RDWR
| O_NOCTTY
| O_NONBLOCK
)) < 0)
231 if (fstat(f
, &buf
) < 0)
236 sprintf(TtyName
, "/dev/ttyq%d", minor(buf
.st_rdev
));
243 /***************************************************************/
245 #if defined(HAVE_SVR4_PTYS) && !defined(PTY_DONE)
253 int unlockpt
__P((int)), grantpt
__P((int));
254 #if defined(HAVE_GETPT) && defined(linux)
255 int getpt
__P((void));
257 sigret_t (*sigcld
)__P(SIGPROTOARG
);
259 strcpy(PtyName
, "/dev/ptmx");
260 #if defined(HAVE_GETPT) && defined(linux)
261 if ((f
= getpt()) == -1)
263 if ((f
= open(PtyName
, O_RDWR
| O_NOCTTY
)) == -1)
268 * SIGCHLD set to SIG_DFL for grantpt() because it fork()s and
271 sigcld
= signal(SIGCHLD
, SIG_DFL
);
272 if ((m
= ptsname(f
)) == NULL
|| grantpt(f
) || unlockpt(f
))
274 signal(SIGCHLD
, sigcld
);
278 signal(SIGCHLD
, sigcld
);
279 strncpy(TtyName
, m
, sizeof(TtyName
));
286 /***************************************************************/
288 #if defined(_AIX) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
297 /* a dumb looking loop replaced by mycrofts code: */
298 strcpy (PtyName
, "/dev/ptc");
299 if ((f
= open (PtyName
, O_RDWR
| O_NOCTTY
)) < 0)
301 strncpy(TtyName
, ttyname(f
), sizeof(TtyName
));
302 if (eff_uid
&& access(TtyName
, R_OK
| W_OK
))
316 /***************************************************************/
318 #if defined(HAVE_OPENPTY) && !defined(PTY_DONE)
325 if (openpty(&f
, &s
, TtyName
, NULL
, NULL
) != 0)
335 /***************************************************************/
342 register char *p
, *q
, *l
, *d
;
345 debug("OpenPTY: Using BSD style ptys.\n");
346 strcpy(PtyName
, PtyProto
);
347 strcpy(TtyName
, TtyProto
);
348 for (p
= PtyName
; *p
!= 'X'; p
++)
350 for (q
= TtyName
; *q
!= 'X'; q
++)
352 for (l
= PTYRANGE0
; (*p
= *l
) != '\0'; l
++)
354 for (d
= PTYRANGE1
; (p
[1] = *d
) != '\0'; d
++)
356 debug1("OpenPTY tries '%s'\n", PtyName
);
357 if ((f
= open(PtyName
, O_RDWR
| O_NOCTTY
)) == -1)
361 if (eff_uid
&& access(TtyName
, R_OK
| W_OK
))
366 #if defined(sun) && defined(TIOCGPGRP) && !defined(SUNOS3)
367 /* Hack to ensure that the slave side of the pty is
368 * unused. May not work in anything other than SunOS4.1
373 /* tcgetpgrp does not work (uses TIOCGETPGRP)! */
374 if (ioctl(f
, TIOCGPGRP
, (char *)&pgrp
) != -1 || errno
!= EIO
)
This page took 0.040338 seconds and 4 git commands to generate.