17c478bd9Sstevel@tonic-gate /* 2*89b43686SBayard Bell * Copyright (c) 2011 Bayard G. Bell. All rights reserved. 319397407SSherry Moore * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 47c478bd9Sstevel@tonic-gate * Use is subject to license terms. 57c478bd9Sstevel@tonic-gate */ 67c478bd9Sstevel@tonic-gate 77c478bd9Sstevel@tonic-gate /* 87c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 97c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 107c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 117c478bd9Sstevel@tonic-gate */ 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate /* 147c478bd9Sstevel@tonic-gate * PTY - Stream "pseudo-tty" device. 157c478bd9Sstevel@tonic-gate * This is the "slave" side. 167c478bd9Sstevel@tonic-gate */ 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate 197c478bd9Sstevel@tonic-gate #include <sys/param.h> 207c478bd9Sstevel@tonic-gate #include <sys/systm.h> 217c478bd9Sstevel@tonic-gate #include <sys/filio.h> 227c478bd9Sstevel@tonic-gate #include <sys/ioccom.h> 237c478bd9Sstevel@tonic-gate #include <sys/termios.h> 247c478bd9Sstevel@tonic-gate #include <sys/termio.h> 257c478bd9Sstevel@tonic-gate #include <sys/ttold.h> 267c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 277c478bd9Sstevel@tonic-gate #include <sys/stream.h> 287c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 297c478bd9Sstevel@tonic-gate #include <sys/tty.h> 307c478bd9Sstevel@tonic-gate #include <sys/user.h> 317c478bd9Sstevel@tonic-gate #include <sys/conf.h> 327c478bd9Sstevel@tonic-gate #include <sys/file.h> 337c478bd9Sstevel@tonic-gate #include <sys/vnode.h> /* 1/0 on the vomit meter */ 347c478bd9Sstevel@tonic-gate #include <sys/proc.h> 357c478bd9Sstevel@tonic-gate #include <sys/uio.h> 367c478bd9Sstevel@tonic-gate #include <sys/errno.h> 377c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 387c478bd9Sstevel@tonic-gate #include <sys/poll.h> 397c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate #include <sys/procset.h> 427c478bd9Sstevel@tonic-gate #include <sys/cred.h> 437c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h> 447c478bd9Sstevel@tonic-gate #include <sys/suntty.h> 457c478bd9Sstevel@tonic-gate #include <sys/stat.h> 467c478bd9Sstevel@tonic-gate #include <sys/policy.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #include <sys/conf.h> 497c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 507c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate extern void gsignal(int pid, int sig); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate extern int npty; /* number of pseudo-ttys configured in */ 557c478bd9Sstevel@tonic-gate extern struct pty *pty_softc; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate extern struct pollhead ptcph; /* poll head for ptcpoll() use */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #define IFLAGS (CS7|CREAD|PARENB) 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Most of these should be "void", but the people who defined the "streams" 647c478bd9Sstevel@tonic-gate * data structure for S5 didn't understand data types. 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Slave side. This is a streams device. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate static int ptslopen(queue_t *, dev_t *, int flag, int, cred_t *); 717c478bd9Sstevel@tonic-gate static int ptslclose(queue_t *, int, cred_t *); 727c478bd9Sstevel@tonic-gate static int ptslrserv(queue_t *); 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * To save instructions, since STREAMS ignores the return value 767c478bd9Sstevel@tonic-gate * from this function, it is defined as void here. Kind of icky, but... 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate static void ptslwput(queue_t *q, mblk_t *mp); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate static struct module_info ptslm_info = { 827c478bd9Sstevel@tonic-gate 0, 837c478bd9Sstevel@tonic-gate "ptys", 847c478bd9Sstevel@tonic-gate 0, 857c478bd9Sstevel@tonic-gate INFPSZ, 867c478bd9Sstevel@tonic-gate 2048, 877c478bd9Sstevel@tonic-gate 200 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static struct qinit ptslrinit = { 917c478bd9Sstevel@tonic-gate putq, 927c478bd9Sstevel@tonic-gate ptslrserv, 937c478bd9Sstevel@tonic-gate ptslopen, 947c478bd9Sstevel@tonic-gate ptslclose, 957c478bd9Sstevel@tonic-gate NULL, 967c478bd9Sstevel@tonic-gate &ptslm_info, 977c478bd9Sstevel@tonic-gate NULL 987c478bd9Sstevel@tonic-gate }; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate static struct qinit ptslwinit = { 1017c478bd9Sstevel@tonic-gate (int (*)())ptslwput, 1027c478bd9Sstevel@tonic-gate NULL, 1037c478bd9Sstevel@tonic-gate NULL, 1047c478bd9Sstevel@tonic-gate NULL, 1057c478bd9Sstevel@tonic-gate NULL, 1067c478bd9Sstevel@tonic-gate &ptslm_info, 1077c478bd9Sstevel@tonic-gate NULL 1087c478bd9Sstevel@tonic-gate }; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate struct streamtab ptysinfo = { 1117c478bd9Sstevel@tonic-gate &ptslrinit, 1127c478bd9Sstevel@tonic-gate &ptslwinit, 1137c478bd9Sstevel@tonic-gate NULL, 1147c478bd9Sstevel@tonic-gate NULL 1157c478bd9Sstevel@tonic-gate }; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate static void ptslreioctl(void *); 1187c478bd9Sstevel@tonic-gate static void ptslioctl(struct pty *, queue_t *, mblk_t *); 1197c478bd9Sstevel@tonic-gate static void pt_sendstop(struct pty *); 1207c478bd9Sstevel@tonic-gate static void ptcpollwakeup(struct pty *, int); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate static int ptsl_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 1247c478bd9Sstevel@tonic-gate static int ptsl_attach(dev_info_t *, ddi_attach_cmd_t); 1257c478bd9Sstevel@tonic-gate static dev_info_t *ptsl_dip; /* for dev-to-dip conversions */ 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(ptsl_ops, nulldev, nulldev, 12819397407SSherry Moore ptsl_attach, nodev, nodev, ptsl_info, D_MP, &ptysinfo, 12919397407SSherry Moore ddi_quiesce_not_supported); 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #include <sys/types.h> 1327c478bd9Sstevel@tonic-gate #include <sys/conf.h> 1337c478bd9Sstevel@tonic-gate #include <sys/param.h> 1347c478bd9Sstevel@tonic-gate #include <sys/systm.h> 1357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 1367c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1437c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 14419397407SSherry Moore "tty pseudo driver slave 'ptsl'", 1457c478bd9Sstevel@tonic-gate &ptsl_ops, /* driver ops */ 1467c478bd9Sstevel@tonic-gate }; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1497c478bd9Sstevel@tonic-gate MODREV_1, 1507c478bd9Sstevel@tonic-gate &modldrv, 1517c478bd9Sstevel@tonic-gate NULL 1527c478bd9Sstevel@tonic-gate }; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate int 1557c478bd9Sstevel@tonic-gate _init(void) 1567c478bd9Sstevel@tonic-gate { 1577c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate int 1617c478bd9Sstevel@tonic-gate _fini(void) 1627c478bd9Sstevel@tonic-gate { 1637c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate int 1677c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate static char *tty_banks = PTY_BANKS; 1737c478bd9Sstevel@tonic-gate static char *tty_digits = PTY_DIGITS; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1767c478bd9Sstevel@tonic-gate static int 1777c478bd9Sstevel@tonic-gate ptsl_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 1787c478bd9Sstevel@tonic-gate { 1797c478bd9Sstevel@tonic-gate char name[8]; 1807c478bd9Sstevel@tonic-gate int tty_num; 1817c478bd9Sstevel@tonic-gate char *tty_digit = tty_digits; 1827c478bd9Sstevel@tonic-gate char *tty_bank = tty_banks; 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate for (tty_num = 0; tty_num < npty; tty_num++) { 1857c478bd9Sstevel@tonic-gate (void) sprintf(name, "tty%c%c", *tty_bank, *tty_digit); 1867c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, name, S_IFCHR, 1877c478bd9Sstevel@tonic-gate tty_num, DDI_PSEUDO, NULL) == DDI_FAILURE) { 1887c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 1897c478bd9Sstevel@tonic-gate return (-1); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate if (*(++tty_digit) == '\0') { 1927c478bd9Sstevel@tonic-gate tty_digit = tty_digits; 1937c478bd9Sstevel@tonic-gate if (*(++tty_bank) == '\0') 1947c478bd9Sstevel@tonic-gate break; 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate ptsl_dip = devi; 1987c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2027c478bd9Sstevel@tonic-gate static int 2037c478bd9Sstevel@tonic-gate ptsl_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 2047c478bd9Sstevel@tonic-gate void **result) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate int error; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate switch (infocmd) { 2097c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2107c478bd9Sstevel@tonic-gate if (ptsl_dip == NULL) { 2117c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 2127c478bd9Sstevel@tonic-gate } else { 2137c478bd9Sstevel@tonic-gate *result = (void *)ptsl_dip; 2147c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate break; 2177c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 2187c478bd9Sstevel@tonic-gate *result = (void *)0; 2197c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 2207c478bd9Sstevel@tonic-gate break; 2217c478bd9Sstevel@tonic-gate default: 2227c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate return (error); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate /* 2297c478bd9Sstevel@tonic-gate * Open the slave side of a pty. 2307c478bd9Sstevel@tonic-gate */ 2317c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2327c478bd9Sstevel@tonic-gate static int 2337c478bd9Sstevel@tonic-gate ptslopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cred) 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate minor_t unit; 2367c478bd9Sstevel@tonic-gate dev_t dev = *devp; 2377c478bd9Sstevel@tonic-gate struct pty *pty; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate unit = getminor(dev); 2407c478bd9Sstevel@tonic-gate if (unit >= npty) 2417c478bd9Sstevel@tonic-gate return (ENXIO); 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate pty = &pty_softc[unit]; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * Block waiting for controller to open, unless this is a no-delay 2487c478bd9Sstevel@tonic-gate * open. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate again: 2517c478bd9Sstevel@tonic-gate if (pty->pt_ttycommon.t_writeq == NULL) { 2527c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iflag = 0; 2537c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_cflag = (B38400 << IBSHIFT)|B38400|IFLAGS; 2547c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = NULL; 2557c478bd9Sstevel@tonic-gate pty->pt_wbufcid = 0; 2567c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_size.ws_row = 0; 2577c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_size.ws_col = 0; 2587c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_size.ws_xpixel = 0; 2597c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_size.ws_ypixel = 0; 2607c478bd9Sstevel@tonic-gate } else if ((pty->pt_ttycommon.t_flags & TS_XCLUDE) && 2617c478bd9Sstevel@tonic-gate secpolicy_excl_open(cred) != 0) { 2627c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 2637c478bd9Sstevel@tonic-gate return (EBUSY); 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate if (!(flag & (FNONBLOCK|FNDELAY)) && 2667c478bd9Sstevel@tonic-gate !(pty->pt_ttycommon.t_cflag & CLOCAL)) { 2677c478bd9Sstevel@tonic-gate if (!(pty->pt_flags & PF_CARR_ON)) { 2687c478bd9Sstevel@tonic-gate pty->pt_flags |= PF_WOPEN; 2697c478bd9Sstevel@tonic-gate if (!cv_wait_sig(&pty->pt_cv_flags, &pty->ptc_lock)) { 2707c478bd9Sstevel@tonic-gate pty->pt_flags &= ~PF_WOPEN; 2717c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 2727c478bd9Sstevel@tonic-gate return (EINTR); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate goto again; 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate pty->pt_sdev = dev; 2797c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = pty; 2807c478bd9Sstevel@tonic-gate pty->pt_flags &= ~PF_SLAVEGONE; 2817c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_readq = pty->pt_ttycommon.t_writeq = NULL; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * Slave is ready to accept messages but master still can't send 2857c478bd9Sstevel@tonic-gate * messages to the slave queue since it is not plumbed 2867c478bd9Sstevel@tonic-gate * yet. So do qprocson() and finish slave initialization. 2877c478bd9Sstevel@tonic-gate */ 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate qprocson(q); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * Now it is safe to send messages to q, so wakeup master possibly 2957c478bd9Sstevel@tonic-gate * waiting for slave queue to finish open. 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 2983f7d78f0SAnil udupa /* 2993f7d78f0SAnil udupa * queue has already been setup with a pointer to 3003f7d78f0SAnil udupa * the stream head that is being referenced 3013f7d78f0SAnil udupa */ 3023f7d78f0SAnil udupa pty->pt_vnode = strq2vp(q); 3033f7d78f0SAnil udupa VN_RELE(pty->pt_vnode); 3047c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_readq = q; 3057c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_writeq = WR(q); 3067c478bd9Sstevel@tonic-gate /* tell master device that slave is ready for writing */ 3077c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_CARR_ON) 3087c478bd9Sstevel@tonic-gate cv_broadcast(&pty->pt_cv_readq); 3097c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate return (0); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate static int 3157c478bd9Sstevel@tonic-gate ptslclose(queue_t *q, int flag, cred_t *cred) 3167c478bd9Sstevel@tonic-gate { 3177c478bd9Sstevel@tonic-gate struct pty *pty; 3187c478bd9Sstevel@tonic-gate bufcall_id_t pt_wbufcid = 0; 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate #ifdef lint 3217c478bd9Sstevel@tonic-gate flag = flag; 3227c478bd9Sstevel@tonic-gate cred = cred; 3237c478bd9Sstevel@tonic-gate #endif 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate if ((pty = (struct pty *)q->q_ptr) == NULL) 3267c478bd9Sstevel@tonic-gate return (ENODEV); /* already been closed once */ 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate /* 3297c478bd9Sstevel@tonic-gate * Prevent the queues from being uses by master device. 3307c478bd9Sstevel@tonic-gate * This should be done before qprocsoff or writer may attempt 3317c478bd9Sstevel@tonic-gate * to use the slave queue after qprocsoff removed it from the stream and 3327c478bd9Sstevel@tonic-gate * before entering mutex_enter(). 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 3357c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_readq = NULL; 3367c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_writeq = NULL; 3373f7d78f0SAnil udupa while (pty->pt_flags & PF_IOCTL) { 3383f7d78f0SAnil udupa pty->pt_flags |= PF_WAIT; 3393f7d78f0SAnil udupa cv_wait(&pty->pt_cv_flags, &pty->ptc_lock); 3403f7d78f0SAnil udupa } 3413f7d78f0SAnil udupa pty->pt_vnode = NULL; 3427c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate qprocsoff(q); 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 3477c478bd9Sstevel@tonic-gate /* 3487c478bd9Sstevel@tonic-gate * ptc_lock mutex is not dropped across 3497c478bd9Sstevel@tonic-gate * the call to the routine ttycommon_close 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate ttycommon_close(&pty->pt_ttycommon); 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate /* 3547c478bd9Sstevel@tonic-gate * Cancel outstanding "bufcall" request. 3557c478bd9Sstevel@tonic-gate */ 3567c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid) { 3577c478bd9Sstevel@tonic-gate pt_wbufcid = pty->pt_wbufcid; 3587c478bd9Sstevel@tonic-gate pty->pt_wbufcid = 0; 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate /* 3627c478bd9Sstevel@tonic-gate * Clear out all the slave-side state. 3637c478bd9Sstevel@tonic-gate */ 3647c478bd9Sstevel@tonic-gate pty->pt_flags &= ~(PF_WOPEN|PF_STOPPED|PF_NOSTOP); 3657c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_CARR_ON) { 3667c478bd9Sstevel@tonic-gate pty->pt_flags |= PF_SLAVEGONE; /* let the controller know */ 3677c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); /* wake up readers/selectors */ 3687c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FWRITE); /* wake up writers/selectors */ 3697c478bd9Sstevel@tonic-gate cv_broadcast(&pty->pt_cv_flags); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate pty->pt_sdev = 0; 3727c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = NULL; 3737c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate if (pt_wbufcid) 3767c478bd9Sstevel@tonic-gate unbufcall(pt_wbufcid); 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate return (0); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate /* 3827c478bd9Sstevel@tonic-gate * Put procedure for write queue. 3837c478bd9Sstevel@tonic-gate * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here; 3847c478bd9Sstevel@tonic-gate * queue up M_DATA messages for processing by the controller "read" 3857c478bd9Sstevel@tonic-gate * routine; discard everything else. 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate static void 3887c478bd9Sstevel@tonic-gate ptslwput(queue_t *q, mblk_t *mp) 3897c478bd9Sstevel@tonic-gate { 3907c478bd9Sstevel@tonic-gate struct pty *pty; 3917c478bd9Sstevel@tonic-gate mblk_t *bp; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate pty = (struct pty *)q->q_ptr; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate case M_STOP: 4007c478bd9Sstevel@tonic-gate if (!(pty->pt_flags & PF_STOPPED)) { 4017c478bd9Sstevel@tonic-gate pty->pt_flags |= PF_STOPPED; 4027c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_STOP; 4037c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate freemsg(mp); 4067c478bd9Sstevel@tonic-gate break; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate case M_START: 4097c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_STOPPED) { 4107c478bd9Sstevel@tonic-gate pty->pt_flags &= ~PF_STOPPED; 4117c478bd9Sstevel@tonic-gate pty->pt_send = TIOCPKT_START; 4127c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FREAD); /* permit controller to read */ 4157c478bd9Sstevel@tonic-gate freemsg(mp); 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate case M_IOCTL: 4197c478bd9Sstevel@tonic-gate ptslioctl(pty, q, mp); 4207c478bd9Sstevel@tonic-gate break; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate case M_FLUSH: 4237c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 4247c478bd9Sstevel@tonic-gate /* 4257c478bd9Sstevel@tonic-gate * Set the "flush write" flag, so that we 4267c478bd9Sstevel@tonic-gate * notify the controller if they're in packet 4277c478bd9Sstevel@tonic-gate * or user control mode. 4287c478bd9Sstevel@tonic-gate */ 4297c478bd9Sstevel@tonic-gate if (!(pty->pt_send & TIOCPKT_FLUSHWRITE)) { 4307c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_FLUSHWRITE; 4317c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Flush our write queue. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */ 4377c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; /* it has been flushed */ 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * Set the "flush read" flag, so that we 4427c478bd9Sstevel@tonic-gate * notify the controller if they're in packet 4437c478bd9Sstevel@tonic-gate * mode. 4447c478bd9Sstevel@tonic-gate */ 4457c478bd9Sstevel@tonic-gate if (!(pty->pt_send & TIOCPKT_FLUSHREAD)) { 4467c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_FLUSHREAD; 4477c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 4507c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 4517c478bd9Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 4527c478bd9Sstevel@tonic-gate return; 4537c478bd9Sstevel@tonic-gate } else 4547c478bd9Sstevel@tonic-gate freemsg(mp); 4557c478bd9Sstevel@tonic-gate break; 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate case M_DATA: 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * Throw away any leading zero-length blocks, and queue it up 4607c478bd9Sstevel@tonic-gate * for the controller to read. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_CARR_ON) { 4637c478bd9Sstevel@tonic-gate bp = mp; 4647c478bd9Sstevel@tonic-gate while ((bp->b_wptr - bp->b_rptr) == 0) { 4657c478bd9Sstevel@tonic-gate mp = bp->b_cont; 4667c478bd9Sstevel@tonic-gate freeb(bp); 4677c478bd9Sstevel@tonic-gate if (mp == NULL) { 4687c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 4697c478bd9Sstevel@tonic-gate return; /* damp squib of a message */ 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate bp = mp; 4727c478bd9Sstevel@tonic-gate } 4737c478bd9Sstevel@tonic-gate (void) putq(q, mp); 4747c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FREAD); /* soup's on! */ 4757c478bd9Sstevel@tonic-gate } else 4767c478bd9Sstevel@tonic-gate freemsg(mp); /* nobody listening */ 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate case M_CTL: 4807c478bd9Sstevel@tonic-gate if ((*(int *)mp->b_rptr) == MC_CANONQUERY) { 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * We're being asked whether we do canonicalization 4837c478bd9Sstevel@tonic-gate * or not. Send a reply back up indicating whether 4847c478bd9Sstevel@tonic-gate * we do or not. 4857c478bd9Sstevel@tonic-gate */ 4867c478bd9Sstevel@tonic-gate (void) putctl1(RD(q), M_CTL, 4877c478bd9Sstevel@tonic-gate (pty->pt_flags & PF_REMOTE) ? 4887c478bd9Sstevel@tonic-gate MC_NOCANON : MC_DOCANON); 4897c478bd9Sstevel@tonic-gate } 4907c478bd9Sstevel@tonic-gate freemsg(mp); 4917c478bd9Sstevel@tonic-gate break; 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate default: 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age, 4967c478bd9Sstevel@tonic-gate * thank you anyway." 4977c478bd9Sstevel@tonic-gate */ 4987c478bd9Sstevel@tonic-gate freemsg(mp); 4997c478bd9Sstevel@tonic-gate break; 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* 5057c478bd9Sstevel@tonic-gate * Retry an "ioctl", now that "bufcall" claims we may be able to allocate 5067c478bd9Sstevel@tonic-gate * the buffer we need. 5077c478bd9Sstevel@tonic-gate */ 5087c478bd9Sstevel@tonic-gate static void 5097c478bd9Sstevel@tonic-gate ptslreioctl(void *arg) 5107c478bd9Sstevel@tonic-gate { 5117c478bd9Sstevel@tonic-gate struct pty *pty = arg; 5127c478bd9Sstevel@tonic-gate queue_t *q; 5137c478bd9Sstevel@tonic-gate mblk_t *mp; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 5167c478bd9Sstevel@tonic-gate /* 5177c478bd9Sstevel@tonic-gate * The bufcall is no longer pending. 5187c478bd9Sstevel@tonic-gate */ 5197c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid == 0) { 5207c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 5217c478bd9Sstevel@tonic-gate return; 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate pty->pt_wbufcid = 0; 5257c478bd9Sstevel@tonic-gate if ((q = pty->pt_ttycommon.t_writeq) == NULL) { 5267c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 5277c478bd9Sstevel@tonic-gate return; 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate if ((mp = pty->pt_ttycommon.t_iocpending) != NULL) { 5307c478bd9Sstevel@tonic-gate /* It's not pending any more. */ 5317c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = NULL; 5327c478bd9Sstevel@tonic-gate ptslioctl(pty, q, mp); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate /* 5387c478bd9Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 5397c478bd9Sstevel@tonic-gate * Drops pty's ptc_lock mutex and then reacquire 5407c478bd9Sstevel@tonic-gate */ 5417c478bd9Sstevel@tonic-gate static void 5427c478bd9Sstevel@tonic-gate ptslioctl(struct pty *pty, queue_t *q, mblk_t *mp) 5437c478bd9Sstevel@tonic-gate { 5447c478bd9Sstevel@tonic-gate struct iocblk *iocp; 5457c478bd9Sstevel@tonic-gate int cmd; 5467c478bd9Sstevel@tonic-gate size_t datasize; 5477c478bd9Sstevel@tonic-gate int error = 0; 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pty->ptc_lock)); 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 5527c478bd9Sstevel@tonic-gate cmd = iocp->ioc_cmd; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate switch (cmd) { 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate case TIOCSTI: { 5577c478bd9Sstevel@tonic-gate /* 5587c478bd9Sstevel@tonic-gate * The permission checking has already been done at the stream 5597c478bd9Sstevel@tonic-gate * head, since it has to be done in the context of the process 5607c478bd9Sstevel@tonic-gate * doing the call. 5617c478bd9Sstevel@tonic-gate */ 5627c478bd9Sstevel@tonic-gate mblk_t *bp; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (char)); 5657c478bd9Sstevel@tonic-gate if (error != 0) 5667c478bd9Sstevel@tonic-gate goto out; 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * Simulate typing of a character at the terminal. 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate if ((bp = allocb(1, BPRI_MED)) != NULL) { 5727c478bd9Sstevel@tonic-gate *bp->b_wptr++ = *mp->b_cont->b_rptr; 5737c478bd9Sstevel@tonic-gate if (!(pty->pt_flags & PF_REMOTE)) { 5747c478bd9Sstevel@tonic-gate if (!canput(pty->pt_ttycommon.t_readq)) { 5757c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 5767c478bd9Sstevel@tonic-gate ttycommon_qfull(&pty->pt_ttycommon, q); 5777c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 5787c478bd9Sstevel@tonic-gate freemsg(bp); 5797c478bd9Sstevel@tonic-gate error = EAGAIN; 5807c478bd9Sstevel@tonic-gate goto out; 5817c478bd9Sstevel@tonic-gate } else 5827c478bd9Sstevel@tonic-gate (void) putq( 5837c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_readq, bp); 5847c478bd9Sstevel@tonic-gate } else { 5857c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_UCNTL) { 5867c478bd9Sstevel@tonic-gate /* 5877c478bd9Sstevel@tonic-gate * XXX - flow control; don't overflow 5887c478bd9Sstevel@tonic-gate * this "queue". 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate if (pty->pt_stuffqfirst != NULL) { 5917c478bd9Sstevel@tonic-gate pty->pt_stuffqlast->b_next = bp; 5927c478bd9Sstevel@tonic-gate bp->b_prev = pty->pt_stuffqlast; 5937c478bd9Sstevel@tonic-gate } else { 5947c478bd9Sstevel@tonic-gate pty->pt_stuffqfirst = bp; 5957c478bd9Sstevel@tonic-gate bp->b_prev = NULL; 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate bp->b_next = NULL; 5987c478bd9Sstevel@tonic-gate pty->pt_stuffqlast = bp; 5997c478bd9Sstevel@tonic-gate pty->pt_stuffqlen++; 6007c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate } else { 6047c478bd9Sstevel@tonic-gate error = EAGAIN; 6057c478bd9Sstevel@tonic-gate goto out; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate /* 6097c478bd9Sstevel@tonic-gate * Turn the ioctl message into an ioctl ACK message. 6107c478bd9Sstevel@tonic-gate */ 6117c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 6127c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 6137c478bd9Sstevel@tonic-gate goto out; 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate case TIOCSSIZE: { 6177c478bd9Sstevel@tonic-gate tty_common_t *tc = &pty->pt_ttycommon; 6187c478bd9Sstevel@tonic-gate struct ttysize *tp; 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct ttysize)); 6217c478bd9Sstevel@tonic-gate if (error != 0) 6227c478bd9Sstevel@tonic-gate goto out; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate /* 6257c478bd9Sstevel@tonic-gate * Set the window size, but don't send a SIGWINCH. 6267c478bd9Sstevel@tonic-gate */ 6277c478bd9Sstevel@tonic-gate tp = (struct ttysize *)mp->b_cont->b_rptr; 6287c478bd9Sstevel@tonic-gate tc->t_size.ws_row = tp->ts_lines; 6297c478bd9Sstevel@tonic-gate tc->t_size.ws_col = tp->ts_cols; 6307c478bd9Sstevel@tonic-gate tc->t_size.ws_xpixel = 0; 6317c478bd9Sstevel@tonic-gate tc->t_size.ws_ypixel = 0; 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate /* 6347c478bd9Sstevel@tonic-gate * Send an ACK back. 6357c478bd9Sstevel@tonic-gate */ 6367c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 6377c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 6387c478bd9Sstevel@tonic-gate goto out; 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate case TIOCGSIZE: { 6427c478bd9Sstevel@tonic-gate tty_common_t *tc = &pty->pt_ttycommon; 6437c478bd9Sstevel@tonic-gate mblk_t *datap; 6447c478bd9Sstevel@tonic-gate struct ttysize *tp; 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate if ((datap = allocb(sizeof (struct ttysize), 6477c478bd9Sstevel@tonic-gate BPRI_HI)) == NULL) { 6487c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid) { 6497c478bd9Sstevel@tonic-gate if (pty->pt_ttycommon.t_iocpending) 6507c478bd9Sstevel@tonic-gate freemsg(pty->pt_ttycommon.t_iocpending); 6517c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = mp; 6527c478bd9Sstevel@tonic-gate return; 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate pty->pt_wbufcid = bufcall(sizeof (struct ttysize), 6557c478bd9Sstevel@tonic-gate BPRI_HI, ptslreioctl, pty); 6567c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid == 0) { 6577c478bd9Sstevel@tonic-gate error = ENOMEM; 6587c478bd9Sstevel@tonic-gate goto out; 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = mp; 6617c478bd9Sstevel@tonic-gate return; 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * Return the current size. 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate tp = (struct ttysize *)datap->b_wptr; 6677c478bd9Sstevel@tonic-gate tp->ts_lines = tc->t_size.ws_row; 6687c478bd9Sstevel@tonic-gate tp->ts_cols = tc->t_size.ws_col; 6697c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (struct ttysize); 6707c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (struct ttysize); 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) 6737c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 6747c478bd9Sstevel@tonic-gate mp->b_cont = datap; 6757c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 6767c478bd9Sstevel@tonic-gate goto out; 6777c478bd9Sstevel@tonic-gate } 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate /* 6807c478bd9Sstevel@tonic-gate * Imported from ttycommon_ioctl routine 6817c478bd9Sstevel@tonic-gate */ 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate case TCSETSF: { 6847c478bd9Sstevel@tonic-gate tty_common_t *tc = &pty->pt_ttycommon; 6857c478bd9Sstevel@tonic-gate struct termios *cb; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct termios)); 6887c478bd9Sstevel@tonic-gate if (error != 0) 6897c478bd9Sstevel@tonic-gate goto out; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate cb = (struct termios *)mp->b_cont->b_rptr; 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 6947c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 6957c478bd9Sstevel@tonic-gate (void) putnextctl1(RD(q), M_FLUSH, FLUSHR); 6967c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 6977c478bd9Sstevel@tonic-gate mutex_enter(&tc->t_excl); 6987c478bd9Sstevel@tonic-gate tc->t_iflag = cb->c_iflag; 6997c478bd9Sstevel@tonic-gate tc->t_cflag = cb->c_cflag; 7007c478bd9Sstevel@tonic-gate tc->t_stopc = cb->c_cc[VSTOP]; 7017c478bd9Sstevel@tonic-gate tc->t_startc = cb->c_cc[VSTART]; 7027c478bd9Sstevel@tonic-gate mutex_exit(&tc->t_excl); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate /* 7057c478bd9Sstevel@tonic-gate * Turn the ioctl message into an ioctl ACK message. 7067c478bd9Sstevel@tonic-gate */ 7077c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7087c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7097c478bd9Sstevel@tonic-gate goto ioctldone; 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate case TCSETAF: { 7137c478bd9Sstevel@tonic-gate tty_common_t *tc = &pty->pt_ttycommon; 7147c478bd9Sstevel@tonic-gate struct termios *cb; 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct termios)); 7177c478bd9Sstevel@tonic-gate if (error != 0) 7187c478bd9Sstevel@tonic-gate goto out; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate cb = (struct termios *)mp->b_cont->b_rptr; 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 7237c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 7247c478bd9Sstevel@tonic-gate (void) putnextctl1(RD(q), M_FLUSH, FLUSHR); 7257c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 7267c478bd9Sstevel@tonic-gate mutex_enter(&tc->t_excl); 7277c478bd9Sstevel@tonic-gate tc->t_iflag = (tc->t_iflag & 0xffff0000 | cb->c_iflag); 7287c478bd9Sstevel@tonic-gate tc->t_cflag = (tc->t_cflag & 0xffff0000 | cb->c_cflag); 7297c478bd9Sstevel@tonic-gate mutex_exit(&tc->t_excl); 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * Turn the ioctl message into an ioctl ACK message. 7337c478bd9Sstevel@tonic-gate */ 7347c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7357c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7367c478bd9Sstevel@tonic-gate goto ioctldone; 7377c478bd9Sstevel@tonic-gate } 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate case TIOCSWINSZ: { 7407c478bd9Sstevel@tonic-gate tty_common_t *tc = &pty->pt_ttycommon; 7417c478bd9Sstevel@tonic-gate struct winsize *ws; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct winsize)); 7447c478bd9Sstevel@tonic-gate if (error != 0) 7457c478bd9Sstevel@tonic-gate goto out; 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate ws = (struct winsize *)mp->b_cont->b_rptr; 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * If the window size changed, send a SIGWINCH. 7507c478bd9Sstevel@tonic-gate */ 7517c478bd9Sstevel@tonic-gate mutex_enter(&tc->t_excl); 7527c478bd9Sstevel@tonic-gate if (bcmp(&tc->t_size, ws, sizeof (struct winsize))) { 7537c478bd9Sstevel@tonic-gate tc->t_size = *ws; 7547c478bd9Sstevel@tonic-gate mutex_exit(&tc->t_excl); 7557c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 7567c478bd9Sstevel@tonic-gate (void) putnextctl1(RD(q), M_PCSIG, SIGWINCH); 7577c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 7587c478bd9Sstevel@tonic-gate } else 7597c478bd9Sstevel@tonic-gate mutex_exit(&tc->t_excl); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate * Turn the ioctl message into an ioctl ACK message. 7637c478bd9Sstevel@tonic-gate */ 7647c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7657c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7667c478bd9Sstevel@tonic-gate goto ioctldone; 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate /* 7707c478bd9Sstevel@tonic-gate * If they were just trying to drain output, that's OK. 7717c478bd9Sstevel@tonic-gate * If they are actually trying to send a break it's an error. 7727c478bd9Sstevel@tonic-gate */ 7737c478bd9Sstevel@tonic-gate case TCSBRK: 7747c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (int)); 7757c478bd9Sstevel@tonic-gate if (error != 0) 7767c478bd9Sstevel@tonic-gate goto out; 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate if (*(int *)mp->b_cont->b_rptr != 0) { 7797c478bd9Sstevel@tonic-gate /* 7807c478bd9Sstevel@tonic-gate * Turn the ioctl message into an ioctl ACK message. 7817c478bd9Sstevel@tonic-gate */ 7827c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7837c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7847c478bd9Sstevel@tonic-gate } else { 7857c478bd9Sstevel@tonic-gate error = ENOTTY; 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate goto out; 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate /* 7917c478bd9Sstevel@tonic-gate * The only way in which "ttycommon_ioctl" can fail is if the "ioctl" 7927c478bd9Sstevel@tonic-gate * requires a response containing data to be returned to the user, 7937c478bd9Sstevel@tonic-gate * and no mblk could be allocated for the data. 7947c478bd9Sstevel@tonic-gate * No such "ioctl" alters our state. Thus, we always go ahead and 7957c478bd9Sstevel@tonic-gate * do any state-changes the "ioctl" calls for. If we couldn't allocate 7967c478bd9Sstevel@tonic-gate * the data, "ttycommon_ioctl" has stashed the "ioctl" away safely, so 7977c478bd9Sstevel@tonic-gate * we just call "bufcall" to request that we be called back when we 7987c478bd9Sstevel@tonic-gate * stand a better chance of allocating the data. 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate if ((datasize = 8017c478bd9Sstevel@tonic-gate ttycommon_ioctl(&pty->pt_ttycommon, q, mp, &error)) != 0) { 8027c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid) { 8037c478bd9Sstevel@tonic-gate if (pty->pt_ttycommon.t_iocpending) 8047c478bd9Sstevel@tonic-gate freemsg(pty->pt_ttycommon.t_iocpending); 8057c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = mp; 8067c478bd9Sstevel@tonic-gate return; 8077c478bd9Sstevel@tonic-gate } 8087c478bd9Sstevel@tonic-gate pty->pt_wbufcid = bufcall(datasize, BPRI_HI, ptslreioctl, pty); 8097c478bd9Sstevel@tonic-gate if (pty->pt_wbufcid == 0) { 8107c478bd9Sstevel@tonic-gate error = ENOMEM; 8117c478bd9Sstevel@tonic-gate goto out; 8127c478bd9Sstevel@tonic-gate } 8137c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_iocpending = mp; 8147c478bd9Sstevel@tonic-gate return; 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate ioctldone: 8187c478bd9Sstevel@tonic-gate if (error == 0) { 8197c478bd9Sstevel@tonic-gate /* 8207c478bd9Sstevel@tonic-gate * "ttycommon_ioctl" did most of the work; we just use the 8217c478bd9Sstevel@tonic-gate * data it set up. 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate switch (cmd) { 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate case TCSETSF: 8267c478bd9Sstevel@tonic-gate case TCSETAF: 8277c478bd9Sstevel@tonic-gate /* 8287c478bd9Sstevel@tonic-gate * Set the "flush read" flag, so that we 8297c478bd9Sstevel@tonic-gate * notify the controller if they're in packet 8307c478bd9Sstevel@tonic-gate * mode. 8317c478bd9Sstevel@tonic-gate */ 8327c478bd9Sstevel@tonic-gate if (!(pty->pt_send & TIOCPKT_FLUSHREAD)) { 8337c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_FLUSHREAD; 8347c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate case TCSETSW: 8397c478bd9Sstevel@tonic-gate case TCSETAW: 8407c478bd9Sstevel@tonic-gate cmd = TIOCSETP; /* map backwards to old codes */ 8417c478bd9Sstevel@tonic-gate pt_sendstop(pty); 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate case TCSETS: 8457c478bd9Sstevel@tonic-gate case TCSETA: 8467c478bd9Sstevel@tonic-gate cmd = TIOCSETN; /* map backwards to old codes */ 8477c478bd9Sstevel@tonic-gate pt_sendstop(pty); 8487c478bd9Sstevel@tonic-gate break; 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate } 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_43UCNTL) { 8537c478bd9Sstevel@tonic-gate if (error < 0) { 8547c478bd9Sstevel@tonic-gate if ((cmd & ~0xff) == _IO('u', 0)) { 8557c478bd9Sstevel@tonic-gate if (cmd & 0xff) { 8567c478bd9Sstevel@tonic-gate pty->pt_ucntl = (uchar_t)cmd & 0xff; 8577c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FREAD); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate error = 0; /* XXX */ 8607c478bd9Sstevel@tonic-gate goto out; 8617c478bd9Sstevel@tonic-gate } 8627c478bd9Sstevel@tonic-gate error = ENOTTY; 8637c478bd9Sstevel@tonic-gate } 8647c478bd9Sstevel@tonic-gate } else { 8657c478bd9Sstevel@tonic-gate if ((pty->pt_flags & PF_UCNTL) && 8667c478bd9Sstevel@tonic-gate (cmd & (IOC_INOUT | 0xff00)) == (IOC_IN|('t'<<8)) && 8677c478bd9Sstevel@tonic-gate (cmd & 0xff)) { 8687c478bd9Sstevel@tonic-gate pty->pt_ucntl = (uchar_t)cmd & 0xff; 8697c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FREAD); 8707c478bd9Sstevel@tonic-gate goto out; 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate if (error < 0) 8737c478bd9Sstevel@tonic-gate error = ENOTTY; 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate out: 8777c478bd9Sstevel@tonic-gate if (error != 0) { 8787c478bd9Sstevel@tonic-gate ((struct iocblk *)mp->b_rptr)->ioc_error = error; 8797c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 8807c478bd9Sstevel@tonic-gate } 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 8837c478bd9Sstevel@tonic-gate qreply(q, mp); 8847c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate /* 8887c478bd9Sstevel@tonic-gate * Service routine for read queue. 8897c478bd9Sstevel@tonic-gate * Just wakes the controller side up so it can write some more data 8907c478bd9Sstevel@tonic-gate * to that queue. 8917c478bd9Sstevel@tonic-gate */ 8927c478bd9Sstevel@tonic-gate static int 8937c478bd9Sstevel@tonic-gate ptslrserv(queue_t *q) 8947c478bd9Sstevel@tonic-gate { 8957c478bd9Sstevel@tonic-gate struct pty *pty = (struct pty *)q->q_ptr; 8967c478bd9Sstevel@tonic-gate mblk_t *mp; 8977c478bd9Sstevel@tonic-gate mblk_t *head = NULL, *tail = NULL; 8987c478bd9Sstevel@tonic-gate /* 8997c478bd9Sstevel@tonic-gate * Build up the link list of messages, then drop 9007c478bd9Sstevel@tonic-gate * drop the lock and do putnext() 9017c478bd9Sstevel@tonic-gate */ 9027c478bd9Sstevel@tonic-gate mutex_enter(&pty->ptc_lock); 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate while ((mp = getq(q)) != NULL) { 9057c478bd9Sstevel@tonic-gate if ((mp->b_datap->db_type < QPCTL) && !canputnext(q)) { 9067c478bd9Sstevel@tonic-gate (void) putbq(q, mp); 9077c478bd9Sstevel@tonic-gate break; 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate if (!head) { 9107c478bd9Sstevel@tonic-gate head = mp; 9117c478bd9Sstevel@tonic-gate tail = mp; 9127c478bd9Sstevel@tonic-gate } else { 9137c478bd9Sstevel@tonic-gate tail->b_next = mp; 9147c478bd9Sstevel@tonic-gate tail = mp; 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate } 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate if (q->q_count <= q->q_lowat) 9197c478bd9Sstevel@tonic-gate ptcpollwakeup((struct pty *)q->q_ptr, FWRITE); 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate mutex_exit(&pty->ptc_lock); 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate while (head) { 9247c478bd9Sstevel@tonic-gate mp = head; 9257c478bd9Sstevel@tonic-gate head = mp->b_next; 9267c478bd9Sstevel@tonic-gate mp->b_next = NULL; 9277c478bd9Sstevel@tonic-gate putnext(q, mp); 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate return (0); 9317c478bd9Sstevel@tonic-gate } 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate static void 9347c478bd9Sstevel@tonic-gate pt_sendstop(struct pty *pty) 9357c478bd9Sstevel@tonic-gate { 9367c478bd9Sstevel@tonic-gate int stop; 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pty->ptc_lock)); 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate if ((pty->pt_ttycommon.t_cflag&CBAUD) == 0) { 9417c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_CARR_ON) { 9427c478bd9Sstevel@tonic-gate /* 9437c478bd9Sstevel@tonic-gate * Let the controller know, then wake up 9447c478bd9Sstevel@tonic-gate * readers/selectors and writers/selectors. 9457c478bd9Sstevel@tonic-gate */ 9467c478bd9Sstevel@tonic-gate pty->pt_flags |= PF_SLAVEGONE; 9477c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 9487c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, FWRITE); 9497c478bd9Sstevel@tonic-gate } 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate stop = (pty->pt_ttycommon.t_iflag & IXON) && 9537c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_stopc == CTRL('s') && 9547c478bd9Sstevel@tonic-gate pty->pt_ttycommon.t_startc == CTRL('q'); 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_NOSTOP) { 9577c478bd9Sstevel@tonic-gate if (stop) { 9587c478bd9Sstevel@tonic-gate pty->pt_send &= ~TIOCPKT_NOSTOP; 9597c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_DOSTOP; 9607c478bd9Sstevel@tonic-gate pty->pt_flags &= ~PF_NOSTOP; 9617c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 9627c478bd9Sstevel@tonic-gate } 9637c478bd9Sstevel@tonic-gate } else { 9647c478bd9Sstevel@tonic-gate if (!stop) { 9657c478bd9Sstevel@tonic-gate pty->pt_send &= ~TIOCPKT_DOSTOP; 9667c478bd9Sstevel@tonic-gate pty->pt_send |= TIOCPKT_NOSTOP; 9677c478bd9Sstevel@tonic-gate pty->pt_flags |= PF_NOSTOP; 9687c478bd9Sstevel@tonic-gate ptcpollwakeup(pty, 0); 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate } 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * Wake up controller side. "flag" is 0 if a special packet or 9757c478bd9Sstevel@tonic-gate * user control mode message has been queued up (this data is readable, 9767c478bd9Sstevel@tonic-gate * so we also treat it as a regular data event; should we send SIGIO, 9777c478bd9Sstevel@tonic-gate * though?), FREAD if regular data has been queued up, or FWRITE if 9787c478bd9Sstevel@tonic-gate * the slave's read queue has drained sufficiently to allow writing. 9797c478bd9Sstevel@tonic-gate */ 9807c478bd9Sstevel@tonic-gate static void 9817c478bd9Sstevel@tonic-gate ptcpollwakeup(struct pty *pty, int flag) 9827c478bd9Sstevel@tonic-gate { 9837c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pty->ptc_lock)); 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate if (flag == 0) { 9867c478bd9Sstevel@tonic-gate /* 9877c478bd9Sstevel@tonic-gate * "Exceptional condition" occurred. This means that 9887c478bd9Sstevel@tonic-gate * a "read" is now possible, so do a "read" wakeup. 9897c478bd9Sstevel@tonic-gate */ 9907c478bd9Sstevel@tonic-gate flag = FREAD; 9917c478bd9Sstevel@tonic-gate pollwakeup(&ptcph, POLLIN | POLLRDBAND); 9927c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_ASYNC) 9937c478bd9Sstevel@tonic-gate gsignal(pty->pt_pgrp, SIGURG); 9947c478bd9Sstevel@tonic-gate } 9957c478bd9Sstevel@tonic-gate if (flag & FREAD) { 9967c478bd9Sstevel@tonic-gate /* 9977c478bd9Sstevel@tonic-gate * Wake up the parent process as there is regular 9987c478bd9Sstevel@tonic-gate * data to read from slave's write queue 9997c478bd9Sstevel@tonic-gate */ 10007c478bd9Sstevel@tonic-gate pollwakeup(&ptcph, POLLIN | POLLRDNORM); 10017c478bd9Sstevel@tonic-gate cv_broadcast(&pty->pt_cv_writeq); 10027c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_ASYNC) 10037c478bd9Sstevel@tonic-gate gsignal(pty->pt_pgrp, SIGIO); 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate if (flag & FWRITE) { 10067c478bd9Sstevel@tonic-gate /* 10077c478bd9Sstevel@tonic-gate * Wake up the parent process to write 10087c478bd9Sstevel@tonic-gate * data into slave's read queue as the 10097c478bd9Sstevel@tonic-gate * read queue has drained enough 10107c478bd9Sstevel@tonic-gate */ 10117c478bd9Sstevel@tonic-gate pollwakeup(&ptcph, POLLOUT | POLLWRNORM); 10127c478bd9Sstevel@tonic-gate cv_broadcast(&pty->pt_cv_readq); 10137c478bd9Sstevel@tonic-gate if (pty->pt_flags & PF_ASYNC) 10147c478bd9Sstevel@tonic-gate gsignal(pty->pt_pgrp, SIGIO); 10157c478bd9Sstevel@tonic-gate } 10167c478bd9Sstevel@tonic-gate } 1017