igb@fulcrum.bt.co.uk (Ian G Batten) (01/25/91)
I'm trying to port a program which uses the BSD pty mechanism in a
fashion akin to telnet to V.4. [[ The application is the ISODE 6.0 VT
daemon ]]
I get a master side by opening /dev/ptmx, call unlockpt on the result,
ptsname on the result and finally open the result of the ptsopen.
That's my slave. Then I push (in order) ptem, ldterm and ttcompat
streams modules.
The call TIOCGETP then fails EINVAL.
Bearing in mind I know precious little about streams, can anyone suggest
if I've made an obvious boob or if there are any places I would be
adviced to start looking for the problem?
Outline of the code:
p = open ("/dev/ptmx", 2);
cp = ptsname (p);
unlockpt (p);
t = open(cp, 2);
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
ian
iand@hamster.labtam.oz (Ian Donaldson) (01/30/91)
igb@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