PTYs with V.4
Ian Donaldson
iand at hamster.labtam.oz
Wed Jan 30 14:18:18 AEST 1991
igb at fulcrum.bt.co.uk (Ian G Batten) writes:
>The call TIOCGETP then fails EINVAL.
>Outline of the code:
> p = open ("/dev/ptmx", 2);
> cp = ptsname (p);
grantpt(p); <---- add this
> unlockpt (p);
> t = open(cp, 2);
if(t == -1) { <---- add this
perror(cp); <---- add this
exit(1); <---- add this
} <---- add this
> if ((ioctl (t, I_PUSH, "ptem") < 0) ||
> (ioctl (t, I_PUSH, "ldterm") < 0) ||
> (ioctl (t, I_PUSH, "ttcompat") < 0))
> fatalperror (f, "stream push", errno);
> if (ioctl(t, TIOCGETP, (char*)&b) == -1) {
> perror("ioctl (TIOCGETP)");
> adios(NULLCP, "ioctl failed (TIOCGETP)");
> } <== fails here
The program may have worked depending on the previous permissions of the
pty returned by ptsname(). On our system the mode before grantpt()
is called was 666 and so the program succeeded. However, the mode may have
been anything, causing the 2nd open to fail.
For an example of streams-pty usage, look in the freely available X11R4 xterm
sources.
Ian D
More information about the Comp.unix.questions
mailing list