tty.c (41ba7e9b13c4c50e6110d72e5a9eb9b91fe981fd) tty.c (c3328b2ab87a66753fdb4651e98e26f735f70093)
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

--- 277 unchanged lines hidden (view full) ---

286 (tp->t_termios.c_cflag & CLOCAL) == 0) {
287 while ((ttydevsw_modem(tp, 0, 0) & SER_DCD) == 0) {
288 error = tty_wait(tp, &tp->t_dcdwait);
289 if (error != 0)
290 goto done;
291 }
292 }
293
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

--- 277 unchanged lines hidden (view full) ---

286 (tp->t_termios.c_cflag & CLOCAL) == 0) {
287 while ((ttydevsw_modem(tp, 0, 0) & SER_DCD) == 0) {
288 error = tty_wait(tp, &tp->t_dcdwait);
289 if (error != 0)
290 goto done;
291 }
292 }
293
294 if (TTY_CALLOUT(tp, dev)) {
294 if (dev == dev_console)
295 tp->t_flags |= TF_OPENED_CONS;
296 else if (TTY_CALLOUT(tp, dev))
295 tp->t_flags |= TF_OPENED_OUT;
297 tp->t_flags |= TF_OPENED_OUT;
296 } else {
298 else
297 tp->t_flags |= TF_OPENED_IN;
299 tp->t_flags |= TF_OPENED_IN;
298 }
299
300done: tp->t_flags &= ~TF_OPENCLOSE;
301 ttydev_leave(tp);
302
303 return (error);
304}
305
306static int
307ttydev_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
308{
309 struct tty *tp = dev->si_drv1;
310
300
301done: tp->t_flags &= ~TF_OPENCLOSE;
302 ttydev_leave(tp);
303
304 return (error);
305}
306
307static int
308ttydev_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
309{
310 struct tty *tp = dev->si_drv1;
311
312 tty_lock(tp);
313
311 /*
312 * Don't actually close the device if it is being used as the
313 * console.
314 */
314 /*
315 * Don't actually close the device if it is being used as the
316 * console.
317 */
315 if (dev_console_filename != NULL &&
316 strcmp(dev_console_filename, tty_devname(tp)) == 0)
318 MPASS((tp->t_flags & TF_OPENED) != TF_OPENED);
319 if (dev == dev_console)
320 tp->t_flags &= ~TF_OPENED_CONS;
321 else
322 tp->t_flags &= ~(TF_OPENED_IN|TF_OPENED_OUT);
323
324 if (tp->t_flags & TF_OPENED) {
325 tty_unlock(tp);
317 return (0);
326 return (0);
327 }
318
328
319 tty_lock(tp);
320
321 /*
322 * This can only be called once. The callin and the callout
323 * devices cannot be opened at the same time.
324 */
329 /*
330 * This can only be called once. The callin and the callout
331 * devices cannot be opened at the same time.
332 */
325 MPASS((tp->t_flags & TF_OPENED) != TF_OPENED);
326 tp->t_flags &= ~(TF_OPENED|TF_EXCLUDE|TF_STOPPED);
333 tp->t_flags &= ~(TF_EXCLUDE|TF_STOPPED);
327
328 /* Properly wake up threads that are stuck - revoke(). */
329 tp->t_revokecnt++;
330 tty_wakeup(tp, FREAD|FWRITE);
331 cv_broadcast(&tp->t_bgwait);
332
333 ttydev_leave(tp);
334

--- 1457 unchanged lines hidden (view full) ---

1792{
1793
1794 log_console(uio);
1795
1796 return (ttydev_write(dev, uio, ioflag));
1797}
1798
1799/*
334
335 /* Properly wake up threads that are stuck - revoke(). */
336 tp->t_revokecnt++;
337 tty_wakeup(tp, FREAD|FWRITE);
338 cv_broadcast(&tp->t_bgwait);
339
340 ttydev_leave(tp);
341

--- 1457 unchanged lines hidden (view full) ---

1799{
1800
1801 log_console(uio);
1802
1803 return (ttydev_write(dev, uio, ioflag));
1804}
1805
1806/*
1800 * /dev/console is a little different than normal TTY's. Unlike regular
1801 * TTY device nodes, this device node will not revoke the entire TTY
1802 * upon closure and all data written to it will be logged.
1807 * /dev/console is a little different than normal TTY's. When opened,
1808 * it determines which TTY to use. When data gets written to it, it
1809 * will be logged in the kernel message buffer.
1803 */
1804static struct cdevsw ttyconsdev_cdevsw = {
1805 .d_version = D_VERSION,
1806 .d_open = ttyconsdev_open,
1810 */
1811static struct cdevsw ttyconsdev_cdevsw = {
1812 .d_version = D_VERSION,
1813 .d_open = ttyconsdev_open,
1814 .d_close = ttydev_close,
1807 .d_read = ttydev_read,
1808 .d_write = ttyconsdev_write,
1809 .d_ioctl = ttydev_ioctl,
1810 .d_kqfilter = ttydev_kqfilter,
1811 .d_poll = ttydev_poll,
1812 .d_mmap = ttydev_mmap,
1813 .d_name = "ttyconsdev",
1814 .d_flags = D_TTY,

--- 25 unchanged lines hidden (view full) ---

1840#include <ddb/ddb.h>
1841#include <ddb/db_sym.h>
1842
1843static struct {
1844 int flag;
1845 char val;
1846} ttystates[] = {
1847#if 0
1815 .d_read = ttydev_read,
1816 .d_write = ttyconsdev_write,
1817 .d_ioctl = ttydev_ioctl,
1818 .d_kqfilter = ttydev_kqfilter,
1819 .d_poll = ttydev_poll,
1820 .d_mmap = ttydev_mmap,
1821 .d_name = "ttyconsdev",
1822 .d_flags = D_TTY,

--- 25 unchanged lines hidden (view full) ---

1848#include <ddb/ddb.h>
1849#include <ddb/db_sym.h>
1850
1851static struct {
1852 int flag;
1853 char val;
1854} ttystates[] = {
1855#if 0
1848 { TF_NOPREFIX, 'N' },
1856 { TF_NOPREFIX, 'N' },
1849#endif
1857#endif
1850 { TF_INITLOCK, 'I' },
1851 { TF_CALLOUT, 'C' },
1858 { TF_INITLOCK, 'I' },
1859 { TF_CALLOUT, 'C' },
1852
1853 /* Keep these together -> 'Oi' and 'Oo'. */
1860
1861 /* Keep these together -> 'Oi' and 'Oo'. */
1854 { TF_OPENED, 'O' },
1855 { TF_OPENED_IN, 'i' },
1856 { TF_OPENED_OUT,'o' },
1862 { TF_OPENED, 'O' },
1863 { TF_OPENED_IN, 'i' },
1864 { TF_OPENED_OUT, 'o' },
1865 { TF_OPENED_CONS, 'c' },
1857
1866
1858 { TF_GONE, 'G' },
1859 { TF_OPENCLOSE, 'B' },
1860 { TF_ASYNC, 'Y' },
1861 { TF_LITERAL, 'L' },
1867 { TF_GONE, 'G' },
1868 { TF_OPENCLOSE, 'B' },
1869 { TF_ASYNC, 'Y' },
1870 { TF_LITERAL, 'L' },
1862
1863 /* Keep these together -> 'Hi' and 'Ho'. */
1871
1872 /* Keep these together -> 'Hi' and 'Ho'. */
1864 { TF_HIWAT, 'H' },
1865 { TF_HIWAT_IN, 'i' },
1866 { TF_HIWAT_OUT, 'o' },
1873 { TF_HIWAT, 'H' },
1874 { TF_HIWAT_IN, 'i' },
1875 { TF_HIWAT_OUT, 'o' },
1867
1876
1868 { TF_STOPPED, 'S' },
1869 { TF_EXCLUDE, 'X' },
1870 { TF_BYPASS, 'l' },
1871 { TF_ZOMBIE, 'Z' },
1872 { TF_HOOK, 's' },
1877 { TF_STOPPED, 'S' },
1878 { TF_EXCLUDE, 'X' },
1879 { TF_BYPASS, 'l' },
1880 { TF_ZOMBIE, 'Z' },
1881 { TF_HOOK, 's' },
1873
1882
1874 { 0, '\0' },
1883 { 0, '\0'},
1875};
1876
1877#define TTY_FLAG_BITS \
1878 "\20\1NOPREFIX\2INITLOCK\3CALLOUT\4OPENED_IN\5OPENED_OUT\6GONE" \
1879 "\7OPENCLOSE\10ASYNC\11LITERAL\12HIWAT_IN\13HIWAT_OUT\14STOPPED" \
1880 "\15EXCLUDE\16BYPASS\17ZOMBIE\20HOOK"
1881
1882#define DB_PRINTSYM(name, addr) \

--- 155 unchanged lines hidden ---
1884};
1885
1886#define TTY_FLAG_BITS \
1887 "\20\1NOPREFIX\2INITLOCK\3CALLOUT\4OPENED_IN\5OPENED_OUT\6GONE" \
1888 "\7OPENCLOSE\10ASYNC\11LITERAL\12HIWAT_IN\13HIWAT_OUT\14STOPPED" \
1889 "\15EXCLUDE\16BYPASS\17ZOMBIE\20HOOK"
1890
1891#define DB_PRINTSYM(name, addr) \

--- 155 unchanged lines hidden ---