Print this page
14249 pseudo-terminal nomenclature should reflect POSIX
Change-Id: Ib4a3cef899ff4c71b09cb0dc6878863c5e8357bc

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/tty_pts.c
          +++ new/usr/src/uts/common/io/tty_pts.c
↓ open down ↓ 4 lines elided ↑ open up ↑
   5    5   */
   6    6  
   7    7  /*
   8    8   * Copyright (c) 1983 Regents of the University of California.
   9    9   * All rights reserved. The Berkeley software License Agreement
  10   10   * specifies the terms and conditions for redistribution.
  11   11   */
  12   12  
  13   13  /*
  14   14   * PTY - Stream "pseudo-tty" device.
  15      - * This is the "slave" side.
       15 + * This is the "subsidiary" side.
  16   16   */
  17   17  
  18   18  
  19   19  #include <sys/param.h>
  20   20  #include <sys/systm.h>
  21   21  #include <sys/filio.h>
  22   22  #include <sys/ioccom.h>
  23   23  #include <sys/termios.h>
  24   24  #include <sys/termio.h>
  25   25  #include <sys/ttold.h>
  26   26  #include <sys/stropts.h>
  27   27  #include <sys/stream.h>
  28   28  #include <sys/strsun.h>
  29   29  #include <sys/tty.h>
  30   30  #include <sys/user.h>
  31   31  #include <sys/conf.h>
  32   32  #include <sys/file.h>
  33      -#include <sys/vnode.h>  /* 1/0 on the vomit meter */
       33 +#include <sys/vnode.h>
  34   34  #include <sys/proc.h>
  35   35  #include <sys/uio.h>
  36   36  #include <sys/errno.h>
  37   37  #include <sys/strsubr.h>
  38   38  #include <sys/poll.h>
  39   39  #include <sys/sysmacros.h>
  40   40  #include <sys/debug.h>
  41   41  #include <sys/procset.h>
  42   42  #include <sys/cred.h>
  43   43  #include <sys/ptyvar.h>
↓ open down ↓ 14 lines elided ↑ open up ↑
  58   58  
  59   59  #define IFLAGS  (CS7|CREAD|PARENB)
  60   60  
  61   61  
  62   62  /*
  63   63   * Most of these should be "void", but the people who defined the "streams"
  64   64   * data structure for S5 didn't understand data types.
  65   65   */
  66   66  
  67   67  /*
  68      - * Slave side.  This is a streams device.
       68 + * Subsidiary side.  This is a streams device.
  69   69   */
  70   70  static int ptslopen(queue_t *, dev_t *, int flag, int, cred_t *);
  71   71  static int ptslclose(queue_t *, int, cred_t *);
  72   72  static int ptslrserv(queue_t *);
  73   73  
  74   74  /*
  75   75   * To save instructions, since STREAMS ignores the return value
  76   76   * from this function, it is defined as void here. Kind of icky, but...
  77   77   */
  78   78  
↓ open down ↓ 55 lines elided ↑ open up ↑
 134  134  #include <sys/systm.h>
 135  135  #include <sys/errno.h>
 136  136  #include <sys/modctl.h>
 137  137  
 138  138  /*
 139  139   * Module linkage information for the kernel.
 140  140   */
 141  141  
 142  142  static struct modldrv modldrv = {
 143  143          &mod_driverops, /* Type of module.  This one is a pseudo driver */
 144      -        "tty pseudo driver slave 'ptsl'",
      144 +        "tty pseudo driver subsidiary 'ptsl'",
 145  145          &ptsl_ops,      /* driver ops */
 146  146  };
 147  147  
 148  148  static struct modlinkage modlinkage = {
 149  149          MODREV_1,
 150  150          &modldrv,
 151  151          NULL
 152  152  };
 153  153  
 154  154  int
↓ open down ↓ 64 lines elided ↑ open up ↑
 219  219                  error = DDI_SUCCESS;
 220  220                  break;
 221  221          default:
 222  222                  error = DDI_FAILURE;
 223  223          }
 224  224          return (error);
 225  225  }
 226  226  
 227  227  
 228  228  /*
 229      - * Open the slave side of a pty.
      229 + * Open the subsidiary side of a pty.
 230  230   */
 231  231  /*ARGSUSED*/
 232  232  static int
 233  233  ptslopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cred)
 234  234  {
 235  235          minor_t unit;
 236  236          dev_t dev = *devp;
 237  237          struct pty *pty;
 238  238  
 239  239          unit = getminor(dev);
↓ open down ↓ 30 lines elided ↑ open up ↑
 270  270                                  pty->pt_flags &= ~PF_WOPEN;
 271  271                                  mutex_exit(&pty->ptc_lock);
 272  272                                  return (EINTR);
 273  273                          }
 274  274                          goto again;
 275  275                  }
 276  276          }
 277  277  
 278  278          pty->pt_sdev = dev;
 279  279          q->q_ptr = WR(q)->q_ptr = pty;
 280      -        pty->pt_flags &= ~PF_SLAVEGONE;
      280 +        pty->pt_flags &= ~PF_SUBSIDGONE;
 281  281          pty->pt_ttycommon.t_readq = pty->pt_ttycommon.t_writeq = NULL;
 282  282  
 283  283          /*
 284      -         * Slave is ready to accept messages but master still can't send
 285      -         * messages to the slave queue since it is not plumbed
 286      -         * yet. So do qprocson() and finish slave initialization.
      284 +         * Subsidiary is ready to accept messages but manager still can't send
      285 +         * messages to the subsidiary queue since it is not plumbed
      286 +         * yet. So do qprocson() and finish subsidiary initialization.
 287  287           */
 288  288  
 289  289          mutex_exit(&pty->ptc_lock);
 290  290  
 291  291          qprocson(q);
 292  292  
 293  293          /*
 294      -         * Now it is safe to send messages to q, so wakeup master possibly
 295      -         * waiting for slave queue to finish open.
      294 +         * Now it is safe to send messages to q, so wakeup manager possibly
      295 +         * waiting for subsidiary queue to finish open.
 296  296           */
 297  297          mutex_enter(&pty->ptc_lock);
 298  298          /*
 299  299           * queue has already been setup with a pointer to
 300  300           * the stream head that is being referenced
 301  301           */
 302  302          pty->pt_vnode = strq2vp(q);
 303  303          VN_RELE(pty->pt_vnode);
 304  304          pty->pt_ttycommon.t_readq = q;
 305  305          pty->pt_ttycommon.t_writeq = WR(q);
 306      -        /* tell master device that slave is ready for writing */
      306 +        /* tell manager device that subsidiary is ready for writing */
 307  307          if (pty->pt_flags & PF_CARR_ON)
 308  308                  cv_broadcast(&pty->pt_cv_readq);
 309  309          mutex_exit(&pty->ptc_lock);
 310  310  
 311  311          return (0);
 312  312  }
 313  313  
 314  314  static int
 315  315  ptslclose(queue_t *q, int flag, cred_t *cred)
 316  316  {
↓ open down ↓ 2 lines elided ↑ open up ↑
 319  319  
 320  320  #ifdef lint
 321  321          flag = flag;
 322  322          cred = cred;
 323  323  #endif
 324  324  
 325  325          if ((pty = (struct pty *)q->q_ptr) == NULL)
 326  326                  return (ENODEV);        /* already been closed once */
 327  327  
 328  328          /*
 329      -         * Prevent the queues from being uses by master device.
 330      -         * This should be done before qprocsoff or writer may attempt
 331      -         * to use the slave queue after qprocsoff removed it from the stream and
 332      -         * before entering mutex_enter().
      329 +         * Prevent the queues from being uses by manager device.  This should
      330 +         * be done before qprocsoff or writer may attempt to use the subsidiary
      331 +         * queue after qprocsoff removed it from the stream and before entering
      332 +         * mutex_enter().
 333  333           */
 334  334          mutex_enter(&pty->ptc_lock);
 335  335          pty->pt_ttycommon.t_readq = NULL;
 336  336          pty->pt_ttycommon.t_writeq = NULL;
 337  337          while (pty->pt_flags & PF_IOCTL) {
 338  338                  pty->pt_flags |= PF_WAIT;
 339  339                  cv_wait(&pty->pt_cv_flags, &pty->ptc_lock);
 340  340          }
 341  341          pty->pt_vnode = NULL;
 342  342          mutex_exit(&pty->ptc_lock);
↓ open down ↓ 9 lines elided ↑ open up ↑
 352  352  
 353  353          /*
 354  354           * Cancel outstanding "bufcall" request.
 355  355           */
 356  356          if (pty->pt_wbufcid) {
 357  357                  pt_wbufcid = pty->pt_wbufcid;
 358  358                  pty->pt_wbufcid = 0;
 359  359          }
 360  360  
 361  361          /*
 362      -         * Clear out all the slave-side state.
      362 +         * Clear out all the subsidiary-side state.
 363  363           */
 364  364          pty->pt_flags &= ~(PF_WOPEN|PF_STOPPED|PF_NOSTOP);
 365  365          if (pty->pt_flags & PF_CARR_ON) {
 366      -                pty->pt_flags |= PF_SLAVEGONE;  /* let the controller know */
      366 +                pty->pt_flags |= PF_SUBSIDGONE; /* let the controller know */
 367  367                  ptcpollwakeup(pty, 0);  /* wake up readers/selectors */
 368  368                  ptcpollwakeup(pty, FWRITE);     /* wake up writers/selectors */
 369  369                  cv_broadcast(&pty->pt_cv_flags);
 370  370          }
 371  371          pty->pt_sdev = 0;
 372  372          q->q_ptr = WR(q)->q_ptr = NULL;
 373  373          mutex_exit(&pty->ptc_lock);
 374  374  
 375  375          if (pt_wbufcid)
 376  376                  unbufcall(pt_wbufcid);
↓ open down ↓ 558 lines elided ↑ open up ↑
 935  935  static void
 936  936  pt_sendstop(struct pty *pty)
 937  937  {
 938  938          int stop;
 939  939  
 940  940          ASSERT(MUTEX_HELD(&pty->ptc_lock));
 941  941  
 942  942          if ((pty->pt_ttycommon.t_cflag&CBAUD) == 0) {
 943  943                  if (pty->pt_flags & PF_CARR_ON) {
 944  944                          /*
 945      -                         * Let the controller know, then wake up
      945 +                         * Let the manager know, then wake up
 946  946                           * readers/selectors and writers/selectors.
 947  947                           */
 948      -                        pty->pt_flags |= PF_SLAVEGONE;
      948 +                        pty->pt_flags |= PF_SUBSIDGONE;
 949  949                          ptcpollwakeup(pty, 0);
 950  950                          ptcpollwakeup(pty, FWRITE);
 951  951                  }
 952  952          }
 953  953  
 954  954          stop = (pty->pt_ttycommon.t_iflag & IXON) &&
 955  955              pty->pt_ttycommon.t_stopc == CTRL('s') &&
 956  956              pty->pt_ttycommon.t_startc == CTRL('q');
 957  957  
 958  958          if (pty->pt_flags & PF_NOSTOP) {
↓ open down ↓ 11 lines elided ↑ open up ↑
 970  970                          ptcpollwakeup(pty, 0);
 971  971                  }
 972  972          }
 973  973  }
 974  974  
 975  975  /*
 976  976   * Wake up controller side.  "flag" is 0 if a special packet or
 977  977   * user control mode message has been queued up (this data is readable,
 978  978   * so we also treat it as a regular data event; should we send SIGIO,
 979  979   * though?), FREAD if regular data has been queued up, or FWRITE if
 980      - * the slave's read queue has drained sufficiently to allow writing.
      980 + * the subsidiary's read queue has drained sufficiently to allow writing.
 981  981   */
 982  982  static void
 983  983  ptcpollwakeup(struct pty *pty, int flag)
 984  984  {
 985  985          ASSERT(MUTEX_HELD(&pty->ptc_lock));
 986  986  
 987  987          if (flag == 0) {
 988  988                  /*
 989  989                   * "Exceptional condition" occurred.  This means that
 990  990                   * a "read" is now possible, so do a "read" wakeup.
 991  991                   */
 992  992                  flag = FREAD;
 993  993                  pollwakeup(&ptcph, POLLIN | POLLRDBAND);
 994  994                  if (pty->pt_flags & PF_ASYNC)
 995  995                          gsignal(pty->pt_pgrp, SIGURG);
 996  996          }
 997  997          if (flag & FREAD) {
 998  998                  /*
 999  999                   * Wake up the parent process as there is regular
1000      -                 * data to read from slave's write queue
     1000 +                 * data to read from subsidiary's write queue
1001 1001                   */
1002 1002                  pollwakeup(&ptcph, POLLIN | POLLRDNORM);
1003 1003                  cv_broadcast(&pty->pt_cv_writeq);
1004 1004                  if (pty->pt_flags & PF_ASYNC)
1005 1005                          gsignal(pty->pt_pgrp, SIGIO);
1006 1006          }
1007 1007          if (flag & FWRITE) {
1008 1008                  /*
1009 1009                   * Wake up the parent process to write
1010      -                 * data into slave's read queue as the
     1010 +                 * data into subsidiary's read queue as the
1011 1011                   * read queue has drained enough
1012 1012                   */
1013 1013                  pollwakeup(&ptcph, POLLOUT | POLLWRNORM);
1014 1014                  cv_broadcast(&pty->pt_cv_readq);
1015 1015                  if (pty->pt_flags & PF_ASYNC)
1016 1016                          gsignal(pty->pt_pgrp, SIGIO);
1017 1017          }
1018 1018  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX