tty.c (216952) | tty.c (223575) |
---|---|
1/*- 2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Portions of this software were developed under sponsorship from Snow 6 * B.V., the Netherlands. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Portions of this software were developed under sponsorship from Snow 6 * B.V., the Netherlands. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/kern/tty.c 216952 2011-01-04 10:59:38Z kib $"); | 31__FBSDID("$FreeBSD: head/sys/kern/tty.c 223575 2011-06-26 18:26:20Z ed $"); |
32 33#include "opt_compat.h" 34 35#include <sys/param.h> 36#include <sys/conf.h> 37#include <sys/cons.h> 38#include <sys/fcntl.h> 39#include <sys/file.h> --- 425 unchanged lines hidden (view full) --- 465 error = ttydisc_write(tp, uio, ioflag); 466 } else { 467 /* Serialize write() calls. */ 468 while (tp->t_flags & TF_BUSY_OUT) { 469 error = tty_wait(tp, &tp->t_outserwait); 470 if (error) 471 goto done; 472 } | 32 33#include "opt_compat.h" 34 35#include <sys/param.h> 36#include <sys/conf.h> 37#include <sys/cons.h> 38#include <sys/fcntl.h> 39#include <sys/file.h> --- 425 unchanged lines hidden (view full) --- 465 error = ttydisc_write(tp, uio, ioflag); 466 } else { 467 /* Serialize write() calls. */ 468 while (tp->t_flags & TF_BUSY_OUT) { 469 error = tty_wait(tp, &tp->t_outserwait); 470 if (error) 471 goto done; 472 } |
473 474 tp->t_flags |= TF_BUSY_OUT; | 473 474 tp->t_flags |= TF_BUSY_OUT; |
475 error = ttydisc_write(tp, uio, ioflag); | 475 error = ttydisc_write(tp, uio, ioflag); |
476 tp->t_flags &= ~TF_BUSY_OUT; | 476 tp->t_flags &= ~TF_BUSY_OUT; |
477 cv_signal(&tp->t_outserwait); 478 } 479 480done: tty_unlock(tp); 481 return (error); 482} 483 484static int --- 564 unchanged lines hidden (view full) --- 1049void 1050tty_rel_pgrp(struct tty *tp, struct pgrp *pg) 1051{ 1052 MPASS(tp->t_sessioncnt > 0); 1053 tty_lock_assert(tp, MA_OWNED); 1054 1055 if (tp->t_pgrp == pg) 1056 tp->t_pgrp = NULL; | 477 cv_signal(&tp->t_outserwait); 478 } 479 480done: tty_unlock(tp); 481 return (error); 482} 483 484static int --- 564 unchanged lines hidden (view full) --- 1049void 1050tty_rel_pgrp(struct tty *tp, struct pgrp *pg) 1051{ 1052 MPASS(tp->t_sessioncnt > 0); 1053 tty_lock_assert(tp, MA_OWNED); 1054 1055 if (tp->t_pgrp == pg) 1056 tp->t_pgrp = NULL; |
1057 | 1057 |
1058 tty_unlock(tp); 1059} 1060 1061void 1062tty_rel_sess(struct tty *tp, struct session *sess) 1063{ 1064 MPASS(tp->t_sessioncnt > 0); 1065 --- 170 unchanged lines hidden (view full) --- 1236{ 1237 struct proc *p; 1238 1239 tty_lock_assert(tp, MA_OWNED); 1240 MPASS(sig >= 1 && sig < NSIG); 1241 1242 /* Make signals start output again. */ 1243 tp->t_flags &= ~TF_STOPPED; | 1058 tty_unlock(tp); 1059} 1060 1061void 1062tty_rel_sess(struct tty *tp, struct session *sess) 1063{ 1064 MPASS(tp->t_sessioncnt > 0); 1065 --- 170 unchanged lines hidden (view full) --- 1236{ 1237 struct proc *p; 1238 1239 tty_lock_assert(tp, MA_OWNED); 1240 MPASS(sig >= 1 && sig < NSIG); 1241 1242 /* Make signals start output again. */ 1243 tp->t_flags &= ~TF_STOPPED; |
1244 | 1244 |
1245 if (tp->t_session != NULL && tp->t_session->s_leader != NULL) { 1246 p = tp->t_session->s_leader; 1247 PROC_LOCK(p); 1248 psignal(p, sig); 1249 PROC_UNLOCK(p); 1250 } 1251} 1252 --- 47 unchanged lines hidden (view full) --- 1300 tty_lock_assert(tp, MA_OWNED|MA_NOTRECURSED); 1301 MPASS(!tty_gone(tp)); 1302 1303 error = cv_wait_sig(cv, tp->t_mtx); 1304 1305 /* Restart the system call when we may have been revoked. */ 1306 if (tp->t_revokecnt != revokecnt) 1307 return (ERESTART); | 1245 if (tp->t_session != NULL && tp->t_session->s_leader != NULL) { 1246 p = tp->t_session->s_leader; 1247 PROC_LOCK(p); 1248 psignal(p, sig); 1249 PROC_UNLOCK(p); 1250 } 1251} 1252 --- 47 unchanged lines hidden (view full) --- 1300 tty_lock_assert(tp, MA_OWNED|MA_NOTRECURSED); 1301 MPASS(!tty_gone(tp)); 1302 1303 error = cv_wait_sig(cv, tp->t_mtx); 1304 1305 /* Restart the system call when we may have been revoked. */ 1306 if (tp->t_revokecnt != revokecnt) 1307 return (ERESTART); |
1308 | 1308 |
1309 /* Bail out when the device slipped away. */ 1310 if (tty_gone(tp)) 1311 return (ENXIO); 1312 1313 return (error); 1314} 1315 1316int --- 5 unchanged lines hidden (view full) --- 1322 tty_lock_assert(tp, MA_OWNED|MA_NOTRECURSED); 1323 MPASS(!tty_gone(tp)); 1324 1325 error = cv_timedwait_sig(cv, tp->t_mtx, hz); 1326 1327 /* Restart the system call when we may have been revoked. */ 1328 if (tp->t_revokecnt != revokecnt) 1329 return (ERESTART); | 1309 /* Bail out when the device slipped away. */ 1310 if (tty_gone(tp)) 1311 return (ENXIO); 1312 1313 return (error); 1314} 1315 1316int --- 5 unchanged lines hidden (view full) --- 1322 tty_lock_assert(tp, MA_OWNED|MA_NOTRECURSED); 1323 MPASS(!tty_gone(tp)); 1324 1325 error = cv_timedwait_sig(cv, tp->t_mtx, hz); 1326 1327 /* Restart the system call when we may have been revoked. */ 1328 if (tp->t_revokecnt != revokecnt) 1329 return (ERESTART); |
1330 | 1330 |
1331 /* Bail out when the device slipped away. */ 1332 if (tty_gone(tp)) 1333 return (ENXIO); 1334 1335 return (error); 1336} 1337 1338void --- 125 unchanged lines hidden (view full) --- 1464 (tp->t_termios.c_cflag != t->c_cflag || 1465 tp->t_termios.c_ispeed != t->c_ispeed || 1466 tp->t_termios.c_ospeed != t->c_ospeed)) { 1467 error = ttydevsw_param(tp, t); 1468 if (error) 1469 return (error); 1470 1471 /* XXX: CLOCAL? */ | 1331 /* Bail out when the device slipped away. */ 1332 if (tty_gone(tp)) 1333 return (ENXIO); 1334 1335 return (error); 1336} 1337 1338void --- 125 unchanged lines hidden (view full) --- 1464 (tp->t_termios.c_cflag != t->c_cflag || 1465 tp->t_termios.c_ispeed != t->c_ispeed || 1466 tp->t_termios.c_ospeed != t->c_ospeed)) { 1467 error = ttydevsw_param(tp, t); 1468 if (error) 1469 return (error); 1470 1471 /* XXX: CLOCAL? */ |
1472 | 1472 |
1473 tp->t_termios.c_cflag = t->c_cflag & ~CIGNORE; 1474 tp->t_termios.c_ispeed = t->c_ispeed; 1475 tp->t_termios.c_ospeed = t->c_ospeed; 1476 1477 /* Baud rate has changed - update watermarks. */ 1478 tty_watermarks(tp); 1479 } 1480 --- 222 unchanged lines hidden (view full) --- 1703tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, struct thread *td) 1704{ 1705 int error; 1706 1707 tty_lock_assert(tp, MA_OWNED); 1708 1709 if (tty_gone(tp)) 1710 return (ENXIO); | 1473 tp->t_termios.c_cflag = t->c_cflag & ~CIGNORE; 1474 tp->t_termios.c_ispeed = t->c_ispeed; 1475 tp->t_termios.c_ospeed = t->c_ospeed; 1476 1477 /* Baud rate has changed - update watermarks. */ 1478 tty_watermarks(tp); 1479 } 1480 --- 222 unchanged lines hidden (view full) --- 1703tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, struct thread *td) 1704{ 1705 int error; 1706 1707 tty_lock_assert(tp, MA_OWNED); 1708 1709 if (tty_gone(tp)) 1710 return (ENXIO); |
1711 | 1711 |
1712 error = ttydevsw_ioctl(tp, cmd, data, td); 1713 if (error == ENOIOCTL) 1714 error = tty_generic_ioctl(tp, cmd, data, fflag, td); 1715 1716 return (error); 1717} 1718 1719dev_t --- 61 unchanged lines hidden (view full) --- 1781 */ 1782 1783static int 1784ttyhook_defrint(struct tty *tp, char c, int flags) 1785{ 1786 1787 if (ttyhook_rint_bypass(tp, &c, 1) != 1) 1788 return (-1); | 1712 error = ttydevsw_ioctl(tp, cmd, data, td); 1713 if (error == ENOIOCTL) 1714 error = tty_generic_ioctl(tp, cmd, data, fflag, td); 1715 1716 return (error); 1717} 1718 1719dev_t --- 61 unchanged lines hidden (view full) --- 1781 */ 1782 1783static int 1784ttyhook_defrint(struct tty *tp, char c, int flags) 1785{ 1786 1787 if (ttyhook_rint_bypass(tp, &c, 1) != 1) 1788 return (-1); |
1789 | 1789 |
1790 return (0); 1791} 1792 1793int 1794ttyhook_register(struct tty **rtp, struct proc *p, int fd, 1795 struct ttyhook *th, void *softc) 1796{ 1797 struct tty *tp; --- 9 unchanged lines hidden (view full) --- 1807 1808 fp = fget_unlocked(fdp, fd); 1809 if (fp == NULL) 1810 return (EBADF); 1811 if (fp->f_ops == &badfileops) { 1812 error = EBADF; 1813 goto done1; 1814 } | 1790 return (0); 1791} 1792 1793int 1794ttyhook_register(struct tty **rtp, struct proc *p, int fd, 1795 struct ttyhook *th, void *softc) 1796{ 1797 struct tty *tp; --- 9 unchanged lines hidden (view full) --- 1807 1808 fp = fget_unlocked(fdp, fd); 1809 if (fp == NULL) 1810 return (EBADF); 1811 if (fp->f_ops == &badfileops) { 1812 error = EBADF; 1813 goto done1; 1814 } |
1815 | 1815 |
1816 /* 1817 * Make sure the vnode is bound to a character device. 1818 * Unlocked check for the vnode type is ok there, because we 1819 * only shall prevent calling devvn_refthread on the file that 1820 * never has been opened over a character device. 1821 */ 1822 if (fp->f_type != DTYPE_VNODE || fp->f_vnode->v_type != VCHR) { 1823 error = EINVAL; --- 81 unchanged lines hidden (view full) --- 1905 break; 1906 } 1907 } 1908 sx_sunlock(&tty_list_sx); 1909 1910 /* System console has no TTY associated. */ 1911 if (dev_console->si_drv1 == NULL) 1912 return (ENXIO); | 1816 /* 1817 * Make sure the vnode is bound to a character device. 1818 * Unlocked check for the vnode type is ok there, because we 1819 * only shall prevent calling devvn_refthread on the file that 1820 * never has been opened over a character device. 1821 */ 1822 if (fp->f_type != DTYPE_VNODE || fp->f_vnode->v_type != VCHR) { 1823 error = EINVAL; --- 81 unchanged lines hidden (view full) --- 1905 break; 1906 } 1907 } 1908 sx_sunlock(&tty_list_sx); 1909 1910 /* System console has no TTY associated. */ 1911 if (dev_console->si_drv1 == NULL) 1912 return (ENXIO); |
1913 | 1913 |
1914 return (ttydev_open(dev, oflags, devtype, td)); 1915} 1916 1917static int 1918ttyconsdev_write(struct cdev *dev, struct uio *uio, int ioflag) 1919{ 1920 1921 log_console(uio); --- 250 unchanged lines hidden --- | 1914 return (ttydev_open(dev, oflags, devtype, td)); 1915} 1916 1917static int 1918ttyconsdev_write(struct cdev *dev, struct uio *uio, int ioflag) 1919{ 1920 1921 log_console(uio); --- 250 unchanged lines hidden --- |