Print this page
12306 XPG4v2 slave pty behaviour should generally be disabled
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Change-ID: I7ccd399c22866f34dd20c6bb9d28e77ba4e24c67

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/gen/pt.c
          +++ new/usr/src/lib/libc/port/gen/pt.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
       27 +/*
       28 + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
       29 + */
       30 +
  27   31  /*      Copyright (c) 1988 AT&T */
  28      -/*        All Rights Reserved   */
       32 +/*        All Rights Reserved   */
  29   33  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   34  #pragma weak _ptsname = ptsname
  33   35  #pragma weak _grantpt = grantpt
  34   36  #pragma weak _unlockpt = unlockpt
  35   37  
  36   38  #include "lint.h"
  37   39  #include "libc.h"
  38   40  #include "mtlib.h"
  39   41  #include <sys/types.h>
  40   42  #include <signal.h>
  41   43  #include <sys/param.h>
↓ open down ↓ 84 lines elided ↑ open up ↑
 126  128          istr.ic_len = 0;
 127  129          istr.ic_timout = 0;
 128  130          istr.ic_dp = NULL;
 129  131  
 130  132          if (ioctl(fd, I_STR, &istr) < 0)
 131  133                  return (-1);
 132  134  
 133  135          return (0);
 134  136  }
 135  137  
      138 +/*
      139 + * XPG4v2 requires that open of a slave pseudo terminal device
      140 + * provides the process with an interface that is identical to
      141 + * the terminal interface.
      142 + *
      143 + * To satisfy this, in strict XPG4v2 mode, this routine also sends
      144 + * a message down the stream that sets a flag in the kernel module
      145 + * so that additional actions are performed when opening an
      146 + * associated slave PTY device. When this happens, modules are
      147 + * automatically pushed onto the stream to provide terminal
      148 + * semantics and those modules are then informed that they should
      149 + * behave in strict XPG4v2 mode which modifies their behaviour. In
      150 + * particular, in strict XPG4v2 mode, empty blocks will be sent up
      151 + * the master side of the stream rather than being suppressed.
      152 + *
      153 + * Most applications do not expect this behaviour so it is only
      154 + * enabled for programs compiled in strict XPG4v2 mode (see
      155 + * stdlib.h).
      156 + */
      157 +int
      158 +__unlockpt_xpg4(int fd)
      159 +{
      160 +        int ret;
      161 +
      162 +        if ((ret = unlockpt(fd)) == 0) {
      163 +                struct strioctl istr;
      164 +
      165 +                istr.ic_cmd = PTSSTTY;
      166 +                istr.ic_len = 0;
      167 +                istr.ic_timout = 0;
      168 +                istr.ic_dp = NULL;
      169 +
      170 +                if (ioctl(fd, I_STR, &istr) < 0)
      171 +                        ret = -1;
      172 +        }
      173 +
      174 +        return (ret);
      175 +}
      176 +
 136  177  int
 137  178  grantpt(int fd)
 138  179  {
 139  180          struct strioctl istr;
 140  181          pt_own_t pto;
 141  182          struct group *gr_name;
 142  183  
 143  184          /* validate the file descriptor before proceeding */
 144  185          if (ptsdev(fd) == NODEV)
 145  186                  return (-1);
↓ open down ↓ 75 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX