Problem with Pseudo TTY of SunOS 4.1.1 for Sun3

Problem with Pseudo TTY of SunOS 4.1.1 for Sun3

Post by Andrew Ch » Thu, 10 Sep 1992 10:08:47



Hi,

  When I opened a pty pair in SunOS 4.1.1 for Sun3, the master tty
is not recognized as a tty, thus causing standard output buffering
problem.  The result of running the following program is:

Master is not a tty
Slave is a tty

  I tried the same program again under other 4.3BSD dervied Unix'es,
and they give me instead:

Master is a tty
Slave is a tty

  Is this a bug with SunOS, or do I need to do something special
in making the master pty a tty as well?

  Thanks for your help.

XXXXXXXXXXXXXXXXXXXXXXXX CUT HERE XXXXXXXXXXXXXXXXXXXXXXXX

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

#define TTY_NAME                "/dev/TtyXY"
#define TTY_POS_T               5
#define TTY_POS_X               8
#define TTY_POS_Y               9

/* Open a master pty and the corresponding slave tty.  Return 0 if */
/* OK, or -1 if cannot open a valid pty pair */
int
OpenPty(int *master, int *slave)
{
  char                          ttyname[] = TTY_NAME;
  char                          xnames[] = "pqrs";
  char                          ynames[] = "0123456789abcdef";
  int                           x, y;

  for (x = 0; xnames[x]; x++) {
    ttyname[TTY_POS_X] = xnames[x];
    for (y = 0; ynames[y]; y++) {
      ttyname[TTY_POS_Y] = ynames[y];

      /* Open Master (control) PTY */
      ttyname[TTY_POS_T] = 'p';
      if ((*master = open(ttyname, O_WRONLY)) < 0)
        continue;

      /* Open Slave PTY */
      ttyname[TTY_POS_T] = 't';
      if ((*slave = open(ttyname, O_RDONLY)) < 0)
        (void) close(*master);
      else
        return 0;
    }
  }

  return -1;

Quote:}

int
main(int argc, char *argv[])
{
  int                           master, slave;

  if (OpenPty(&master, &slave) < 0) {
    fputs("Failure to open pty\n", stderr);
    exit(-1);
  }

  if (isatty(master))
    puts("Master is a tty");
  else
    puts("Master is not a tty");

  if (isatty(slave))
    puts("Slave is a tty");
  else
    puts("Slave is not a tty");

  exit(0);

Quote:}

 
 
 

Problem with Pseudo TTY of SunOS 4.1.1 for Sun3

Post by Guy Harr » Thu, 10 Sep 1992 15:44:26


Quote:>  Is this a bug with SunOS,

No, it's a botch in the BSD pseudo-tty implementation; the BSD one let
you do certain tty "ioctl"s on the master side.  It shouldn't have done
so; pseudo-tty masters are *NOT* ttys, they're pseudo-tty masters.

The SunOS 4.x pseudo-tty implementation does some old BSD "ioctl"s for
backwards compatibility - and the code to do so is *REALLY GROSS*, as
the STREAMS-based pty implementation doesn't make it at *all* easy to do
that - but it doesn't do the newer "ioctl"s used by "isatty()" and by
the standard I/O library to determine if something is a tty.

Quote:>or do I need to do something special
>in making the master pty a tty as well?

It's *not* a tty.  Explicitly use "setlinebuf()", or "setbuf()", or
"setvbuf()", to control the standard I/O buffering on pseudo-tty
masters.