1 PTY(3)                 Introduction to Library Functions                PTY(3)
   2 
   3 NAME
   4      openpty, forkpty  auxiliary functions to obtain a pseudo-terminal
   5 
   6 SYNOPSIS
   7      #include <pty.h>
   8 
   9      int
  10      openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
  11          const struct winsize *winp);
  12 
  13      int
  14      forkpty(int *amaster, char *name, const struct termios *termp,
  15          const struct winsize *winp);
  16 
  17 DESCRIPTION
  18      The function openpty() attempts to obtain the next available pseudo-
  19      terminal from the system. If it successfully finds one, it subsequently
  20      changes the ownership of the slave device to the real UID of the current
  21      process, the group membership to the group tty (if such a group exists in
  22      the system), the access permissions for reading and writing by the owner,
  23      and for writing by the group.
  24 
  25      If the argument name is not NULL, the filename of the slave is returned
  26      in name.
  27 
  28      If the arguments termp or winp are not NULL, openpty() initializes the
  29      termios and window size settings from the structures these arguments
  30      point to, respectively.
  31 
  32      Upon return, the open file descriptors for the master and slave side of
  33      the pty are returned in the locations pointed to by amaster and aslave,
  34      respectively.
  35 
  36      The forkpty() function first calls openpty() to obtain the next available
  37      pseudo-terminal from the system.  Upon success, it forks off a new
  38      process.  In the child process, it closes the descriptor for the master
  39      side of the pty, and calls login_tty(3) for the slave pty.  In the parent
  40      process, it closes the descriptor for the slave side of the pty.  The
  41      arguments amaster, name, termp, and winp have the same meaning as
  42      described for openpty().
  43 
  44 RETURN VALUES
  45      If a call to openpty() or forkpty() is not successful, -1 is returned and
  46      errno is set to indicate the error.  Otherwise, openpty() and the child
  47      process of forkpty() return 0, and the parent process of forkpty()
  48      returns the process ID of the child process.
  49 
  50 ERRORS
  51      The openpty() function may fail and set the global variable errno for any
  52      of the errors specified for the open(2,) grantpt(3), unlockpt(3,)
  53      ptsname(3), ioctl(2), and tcsetattr(3) functions.
  54 
  55      In addition to this, forkpty() may set it to any value as described for
  56      fork(2).
  57 
  58 INTERFACE STABILITY
  59      Comitted
  60 
  61 MT-LEVEL
  62      MT-Safe
  63 
  64 SEE ALSO
  65      chmod(2), chown(2), fork(2), getuid(2), open(2), login_tty(3),
  66      termios(3), group(4)
  67 
  68 NexentaStor                    October 10, 2015                    NexentaStor