Lines Matching refs:tty
114 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) argument
116 # define tty_debug_hangup(tty, f, args...) do { } while (0) argument
157 static void release_tty(struct tty_struct *tty, int idx);
168 static void free_tty_struct(struct tty_struct *tty) in free_tty_struct() argument
170 tty_ldisc_deinit(tty); in free_tty_struct()
171 put_device(tty->dev); in free_tty_struct()
172 kfree(tty->write_buf); in free_tty_struct()
173 tty->magic = 0xDEADDEAD; in free_tty_struct()
174 kfree(tty); in free_tty_struct()
179 return ((struct tty_file_private *)file->private_data)->tty; in file_tty()
196 void tty_add_file(struct tty_struct *tty, struct file *file) in tty_add_file() argument
200 priv->tty = tty; in tty_add_file()
203 spin_lock(&tty->files_lock); in tty_add_file()
204 list_add(&priv->list, &tty->tty_files); in tty_add_file()
205 spin_unlock(&tty->files_lock); in tty_add_file()
226 struct tty_struct *tty = priv->tty; in tty_del_file() local
228 spin_lock(&tty->files_lock); in tty_del_file()
230 spin_unlock(&tty->files_lock); in tty_del_file()
244 const char *tty_name(const struct tty_struct *tty) in tty_name() argument
246 if (!tty) /* Hmm. NULL pointer. That's fun. */ in tty_name()
248 return tty->name; in tty_name()
253 const char *tty_driver_name(const struct tty_struct *tty) in tty_driver_name() argument
255 if (!tty || !tty->driver) in tty_driver_name()
257 return tty->driver->name; in tty_driver_name()
260 static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, in tty_paranoia_check() argument
264 if (!tty) { in tty_paranoia_check()
269 if (tty->magic != TTY_MAGIC) { in tty_paranoia_check()
279 static int check_tty_count(struct tty_struct *tty, const char *routine) in check_tty_count() argument
285 spin_lock(&tty->files_lock); in check_tty_count()
286 list_for_each(p, &tty->tty_files) { in check_tty_count()
289 spin_unlock(&tty->files_lock); in check_tty_count()
290 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in check_tty_count()
291 tty->driver->subtype == PTY_TYPE_SLAVE && in check_tty_count()
292 tty->link && tty->link->count) in check_tty_count()
294 if (tty_port_kopened(tty->port)) in check_tty_count()
296 if (tty->count != (count + kopen_count)) { in check_tty_count()
297 tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", in check_tty_count()
298 routine, tty->count, count, kopen_count); in check_tty_count()
467 struct tty_struct *tty = file_tty(file); in tty_show_fdinfo() local
469 if (tty && tty->ops && tty->ops->show_fdinfo) in tty_show_fdinfo()
470 tty->ops->show_fdinfo(tty, m); in tty_show_fdinfo()
527 void tty_wakeup(struct tty_struct *tty) in tty_wakeup() argument
531 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { in tty_wakeup()
532 ld = tty_ldisc_ref(tty); in tty_wakeup()
535 ld->ops->write_wakeup(tty); in tty_wakeup()
539 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_wakeup()
566 static void __tty_hangup(struct tty_struct *tty, int exit_session) in __tty_hangup() argument
574 if (!tty) in __tty_hangup()
579 if (redirect && file_tty(redirect) == tty) { in __tty_hangup()
585 tty_lock(tty); in __tty_hangup()
587 if (test_bit(TTY_HUPPED, &tty->flags)) { in __tty_hangup()
588 tty_unlock(tty); in __tty_hangup()
598 set_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
603 check_tty_count(tty, "tty_hangup"); in __tty_hangup()
605 spin_lock(&tty->files_lock); in __tty_hangup()
607 list_for_each_entry(priv, &tty->tty_files, list) { in __tty_hangup()
617 spin_unlock(&tty->files_lock); in __tty_hangup()
619 refs = tty_signal_session_leader(tty, exit_session); in __tty_hangup()
622 tty_kref_put(tty); in __tty_hangup()
624 tty_ldisc_hangup(tty, cons_filp != NULL); in __tty_hangup()
626 spin_lock_irq(&tty->ctrl_lock); in __tty_hangup()
627 clear_bit(TTY_THROTTLED, &tty->flags); in __tty_hangup()
628 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in __tty_hangup()
629 put_pid(tty->session); in __tty_hangup()
630 put_pid(tty->pgrp); in __tty_hangup()
631 tty->session = NULL; in __tty_hangup()
632 tty->pgrp = NULL; in __tty_hangup()
633 tty->ctrl_status = 0; in __tty_hangup()
634 spin_unlock_irq(&tty->ctrl_lock); in __tty_hangup()
643 if (tty->ops->close) in __tty_hangup()
645 tty->ops->close(tty, cons_filp); in __tty_hangup()
646 } else if (tty->ops->hangup) in __tty_hangup()
647 tty->ops->hangup(tty); in __tty_hangup()
653 set_bit(TTY_HUPPED, &tty->flags); in __tty_hangup()
654 clear_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
655 tty_unlock(tty); in __tty_hangup()
663 struct tty_struct *tty = in do_tty_hangup() local
666 __tty_hangup(tty, 0); in do_tty_hangup()
677 void tty_hangup(struct tty_struct *tty) in tty_hangup() argument
679 tty_debug_hangup(tty, "hangup\n"); in tty_hangup()
680 schedule_work(&tty->hangup_work); in tty_hangup()
694 void tty_vhangup(struct tty_struct *tty) in tty_vhangup() argument
696 tty_debug_hangup(tty, "vhangup\n"); in tty_vhangup()
697 __tty_hangup(tty, 0); in tty_vhangup()
711 struct tty_struct *tty; in tty_vhangup_self() local
713 tty = get_current_tty(); in tty_vhangup_self()
714 if (tty) { in tty_vhangup_self()
715 tty_vhangup(tty); in tty_vhangup_self()
716 tty_kref_put(tty); in tty_vhangup_self()
731 void tty_vhangup_session(struct tty_struct *tty) in tty_vhangup_session() argument
733 tty_debug_hangup(tty, "session hangup\n"); in tty_vhangup_session()
734 __tty_hangup(tty, 1); in tty_vhangup_session()
769 void __stop_tty(struct tty_struct *tty) in __stop_tty() argument
771 if (tty->stopped) in __stop_tty()
773 tty->stopped = 1; in __stop_tty()
774 if (tty->ops->stop) in __stop_tty()
775 tty->ops->stop(tty); in __stop_tty()
778 void stop_tty(struct tty_struct *tty) in stop_tty() argument
782 spin_lock_irqsave(&tty->flow_lock, flags); in stop_tty()
783 __stop_tty(tty); in stop_tty()
784 spin_unlock_irqrestore(&tty->flow_lock, flags); in stop_tty()
800 void __start_tty(struct tty_struct *tty) in __start_tty() argument
802 if (!tty->stopped || tty->flow_stopped) in __start_tty()
804 tty->stopped = 0; in __start_tty()
805 if (tty->ops->start) in __start_tty()
806 tty->ops->start(tty); in __start_tty()
807 tty_wakeup(tty); in __start_tty()
810 void start_tty(struct tty_struct *tty) in start_tty() argument
814 spin_lock_irqsave(&tty->flow_lock, flags); in start_tty()
815 __start_tty(tty); in start_tty()
816 spin_unlock_irqrestore(&tty->flow_lock, flags); in start_tty()
845 static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, in iterate_tty_read() argument
858 size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); in iterate_tty_read()
920 struct tty_struct *tty = file_tty(file); in tty_read() local
923 if (tty_paranoia_check(tty, inode, "tty_read")) in tty_read()
925 if (!tty || tty_io_error(tty)) in tty_read()
930 ld = tty_ldisc_ref_wait(tty); in tty_read()
935 i = iterate_tty_read(ld, tty, file, to); in tty_read()
944 static void tty_write_unlock(struct tty_struct *tty) in tty_write_unlock() argument
946 mutex_unlock(&tty->atomic_write_lock); in tty_write_unlock()
947 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_write_unlock()
950 static int tty_write_lock(struct tty_struct *tty, int ndelay) in tty_write_lock() argument
952 if (!mutex_trylock(&tty->atomic_write_lock)) { in tty_write_lock()
955 if (mutex_lock_interruptible(&tty->atomic_write_lock)) in tty_write_lock()
967 struct tty_struct *tty, in do_tty_write() argument
975 ret = tty_write_lock(tty, file->f_flags & O_NDELAY); in do_tty_write()
996 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) in do_tty_write()
1002 if (tty->write_cnt < chunk) { in do_tty_write()
1013 kfree(tty->write_buf); in do_tty_write()
1014 tty->write_cnt = chunk; in do_tty_write()
1015 tty->write_buf = buf_chunk; in do_tty_write()
1025 if (copy_from_iter(tty->write_buf, size, from) != size) in do_tty_write()
1028 ret = write(tty, file, tty->write_buf, size); in do_tty_write()
1053 tty_write_unlock(tty); in do_tty_write()
1069 void tty_write_message(struct tty_struct *tty, char *msg) in tty_write_message() argument
1071 if (tty) { in tty_write_message()
1072 mutex_lock(&tty->atomic_write_lock); in tty_write_message()
1073 tty_lock(tty); in tty_write_message()
1074 if (tty->ops->write && tty->count > 0) in tty_write_message()
1075 tty->ops->write(tty, msg, strlen(msg)); in tty_write_message()
1076 tty_unlock(tty); in tty_write_message()
1077 tty_write_unlock(tty); in tty_write_message()
1101 struct tty_struct *tty = file_tty(file); in file_tty_write() local
1105 if (tty_paranoia_check(tty, file_inode(file), "tty_write")) in file_tty_write()
1107 if (!tty || !tty->ops->write || tty_io_error(tty)) in file_tty_write()
1110 if (tty->ops->write_room == NULL) in file_tty_write()
1111 tty_err(tty, "missing write_room method\n"); in file_tty_write()
1112 ld = tty_ldisc_ref_wait(tty); in file_tty_write()
1118 ret = do_tty_write(ld->ops->write, tty, file, from); in file_tty_write()
1158 int tty_send_xchar(struct tty_struct *tty, char ch) in tty_send_xchar() argument
1160 int was_stopped = tty->stopped; in tty_send_xchar()
1162 if (tty->ops->send_xchar) { in tty_send_xchar()
1163 down_read(&tty->termios_rwsem); in tty_send_xchar()
1164 tty->ops->send_xchar(tty, ch); in tty_send_xchar()
1165 up_read(&tty->termios_rwsem); in tty_send_xchar()
1169 if (tty_write_lock(tty, 0) < 0) in tty_send_xchar()
1172 down_read(&tty->termios_rwsem); in tty_send_xchar()
1174 start_tty(tty); in tty_send_xchar()
1175 tty->ops->write(tty, &ch, 1); in tty_send_xchar()
1177 stop_tty(tty); in tty_send_xchar()
1178 up_read(&tty->termios_rwsem); in tty_send_xchar()
1179 tty_write_unlock(tty); in tty_send_xchar()
1238 struct tty_struct *tty; in tty_driver_lookup_tty() local
1242 tty = ERR_PTR(-EIO); in tty_driver_lookup_tty()
1244 tty = driver->ops->lookup(driver, file, idx); in tty_driver_lookup_tty()
1246 tty = driver->ttys[idx]; in tty_driver_lookup_tty()
1248 if (!IS_ERR(tty)) in tty_driver_lookup_tty()
1249 tty_kref_get(tty); in tty_driver_lookup_tty()
1250 return tty; in tty_driver_lookup_tty()
1261 void tty_init_termios(struct tty_struct *tty) in tty_init_termios() argument
1264 int idx = tty->index; in tty_init_termios()
1266 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_init_termios()
1267 tty->termios = tty->driver->init_termios; in tty_init_termios()
1270 tp = tty->driver->termios[idx]; in tty_init_termios()
1272 tty->termios = *tp; in tty_init_termios()
1273 tty->termios.c_line = tty->driver->init_termios.c_line; in tty_init_termios()
1275 tty->termios = tty->driver->init_termios; in tty_init_termios()
1278 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); in tty_init_termios()
1279 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); in tty_init_termios()
1283 int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty) in tty_standard_install() argument
1285 tty_init_termios(tty); in tty_standard_install()
1287 tty->count++; in tty_standard_install()
1288 driver->ttys[tty->index] = tty; in tty_standard_install()
1306 struct tty_struct *tty) in tty_driver_install_tty() argument
1308 return driver->ops->install ? driver->ops->install(driver, tty) : in tty_driver_install_tty()
1309 tty_standard_install(driver, tty); in tty_driver_install_tty()
1322 static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) in tty_driver_remove_tty() argument
1325 driver->ops->remove(driver, tty); in tty_driver_remove_tty()
1327 driver->ttys[tty->index] = NULL; in tty_driver_remove_tty()
1339 static int tty_reopen(struct tty_struct *tty) in tty_reopen() argument
1341 struct tty_driver *driver = tty->driver; in tty_reopen()
1349 if (!tty->count) in tty_reopen()
1352 if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) in tty_reopen()
1355 ld = tty_ldisc_ref_wait(tty); in tty_reopen()
1359 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_reopen()
1363 if (!tty->ldisc) in tty_reopen()
1364 retval = tty_ldisc_reinit(tty, tty->termios.c_line); in tty_reopen()
1365 tty_ldisc_unlock(tty); in tty_reopen()
1369 tty->count++; in tty_reopen()
1401 struct tty_struct *tty; in tty_init_dev() local
1415 tty = alloc_tty_struct(driver, idx); in tty_init_dev()
1416 if (!tty) { in tty_init_dev()
1421 tty_lock(tty); in tty_init_dev()
1422 retval = tty_driver_install_tty(driver, tty); in tty_init_dev()
1426 if (!tty->port) in tty_init_dev()
1427 tty->port = driver->ports[idx]; in tty_init_dev()
1429 if (WARN_RATELIMIT(!tty->port, in tty_init_dev()
1431 __func__, tty->driver->name)) { in tty_init_dev()
1436 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_init_dev()
1439 tty->port->itty = tty; in tty_init_dev()
1446 retval = tty_ldisc_setup(tty, tty->link); in tty_init_dev()
1449 tty_ldisc_unlock(tty); in tty_init_dev()
1451 return tty; in tty_init_dev()
1454 tty_unlock(tty); in tty_init_dev()
1455 free_tty_struct(tty); in tty_init_dev()
1462 tty_ldisc_unlock(tty); in tty_init_dev()
1463 tty_info_ratelimited(tty, "ldisc open failed (%d), clearing slot %d\n", in tty_init_dev()
1466 tty_unlock(tty); in tty_init_dev()
1467 release_tty(tty, idx); in tty_init_dev()
1477 void tty_save_termios(struct tty_struct *tty) in tty_save_termios() argument
1480 int idx = tty->index; in tty_save_termios()
1483 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_save_termios()
1487 tp = tty->driver->termios[idx]; in tty_save_termios()
1492 tty->driver->termios[idx] = tp; in tty_save_termios()
1494 *tp = tty->termios; in tty_save_termios()
1504 static void tty_flush_works(struct tty_struct *tty) in tty_flush_works() argument
1506 flush_work(&tty->SAK_work); in tty_flush_works()
1507 flush_work(&tty->hangup_work); in tty_flush_works()
1508 if (tty->link) { in tty_flush_works()
1509 flush_work(&tty->link->SAK_work); in tty_flush_works()
1510 flush_work(&tty->link->hangup_work); in tty_flush_works()
1531 struct tty_struct *tty = in release_one_tty() local
1533 struct tty_driver *driver = tty->driver; in release_one_tty()
1536 if (tty->ops->cleanup) in release_one_tty()
1537 tty->ops->cleanup(tty); in release_one_tty()
1539 tty->magic = 0; in release_one_tty()
1543 spin_lock(&tty->files_lock); in release_one_tty()
1544 list_del_init(&tty->tty_files); in release_one_tty()
1545 spin_unlock(&tty->files_lock); in release_one_tty()
1547 put_pid(tty->pgrp); in release_one_tty()
1548 put_pid(tty->session); in release_one_tty()
1549 free_tty_struct(tty); in release_one_tty()
1554 struct tty_struct *tty = container_of(kref, struct tty_struct, kref); in queue_release_one_tty() local
1558 INIT_WORK(&tty->hangup_work, release_one_tty); in queue_release_one_tty()
1559 schedule_work(&tty->hangup_work); in queue_release_one_tty()
1570 void tty_kref_put(struct tty_struct *tty) in tty_kref_put() argument
1572 if (tty) in tty_kref_put()
1573 kref_put(&tty->kref, queue_release_one_tty); in tty_kref_put()
1589 static void release_tty(struct tty_struct *tty, int idx) in release_tty() argument
1592 WARN_ON(tty->index != idx); in release_tty()
1594 if (tty->ops->shutdown) in release_tty()
1595 tty->ops->shutdown(tty); in release_tty()
1596 tty_save_termios(tty); in release_tty()
1597 tty_driver_remove_tty(tty->driver, tty); in release_tty()
1598 if (tty->port) in release_tty()
1599 tty->port->itty = NULL; in release_tty()
1600 if (tty->link) in release_tty()
1601 tty->link->port->itty = NULL; in release_tty()
1602 if (tty->port) in release_tty()
1603 tty_buffer_cancel_work(tty->port); in release_tty()
1604 if (tty->link) in release_tty()
1605 tty_buffer_cancel_work(tty->link->port); in release_tty()
1607 tty_kref_put(tty->link); in release_tty()
1608 tty_kref_put(tty); in release_tty()
1619 static int tty_release_checks(struct tty_struct *tty, int idx) in tty_release_checks() argument
1622 if (idx < 0 || idx >= tty->driver->num) { in tty_release_checks()
1623 tty_debug(tty, "bad idx %d\n", idx); in tty_release_checks()
1628 if (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) in tty_release_checks()
1631 if (tty != tty->driver->ttys[idx]) { in tty_release_checks()
1632 tty_debug(tty, "bad driver table[%d] = %p\n", in tty_release_checks()
1633 idx, tty->driver->ttys[idx]); in tty_release_checks()
1636 if (tty->driver->other) { in tty_release_checks()
1637 struct tty_struct *o_tty = tty->link; in tty_release_checks()
1639 if (o_tty != tty->driver->other->ttys[idx]) { in tty_release_checks()
1640 tty_debug(tty, "bad other table[%d] = %p\n", in tty_release_checks()
1641 idx, tty->driver->other->ttys[idx]); in tty_release_checks()
1644 if (o_tty->link != tty) { in tty_release_checks()
1645 tty_debug(tty, "bad link = %p\n", o_tty->link); in tty_release_checks()
1661 void tty_kclose(struct tty_struct *tty) in tty_kclose() argument
1666 tty_ldisc_release(tty); in tty_kclose()
1669 tty_flush_works(tty); in tty_kclose()
1671 tty_debug_hangup(tty, "freeing structure\n"); in tty_kclose()
1677 tty_port_set_kopened(tty->port, 0); in tty_kclose()
1678 release_tty(tty, tty->index); in tty_kclose()
1691 void tty_release_struct(struct tty_struct *tty, int idx) in tty_release_struct() argument
1696 tty_ldisc_release(tty); in tty_release_struct()
1699 tty_flush_works(tty); in tty_release_struct()
1701 tty_debug_hangup(tty, "freeing structure\n"); in tty_release_struct()
1707 release_tty(tty, idx); in tty_release_struct()
1733 struct tty_struct *tty = file_tty(filp); in tty_release() local
1740 if (tty_paranoia_check(tty, inode, __func__)) in tty_release()
1743 tty_lock(tty); in tty_release()
1744 check_tty_count(tty, __func__); in tty_release()
1748 idx = tty->index; in tty_release()
1749 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_release()
1750 tty->driver->subtype == PTY_TYPE_MASTER) in tty_release()
1751 o_tty = tty->link; in tty_release()
1753 if (tty_release_checks(tty, idx)) { in tty_release()
1754 tty_unlock(tty); in tty_release()
1758 tty_debug_hangup(tty, "releasing (count=%d)\n", tty->count); in tty_release()
1760 if (tty->ops->close) in tty_release()
1761 tty->ops->close(tty, filp); in tty_release()
1782 if (tty->count <= 1) { in tty_release()
1783 if (waitqueue_active(&tty->read_wait)) { in tty_release()
1784 wake_up_poll(&tty->read_wait, EPOLLIN); in tty_release()
1787 if (waitqueue_active(&tty->write_wait)) { in tty_release()
1788 wake_up_poll(&tty->write_wait, EPOLLOUT); in tty_release()
1807 tty_warn(tty, "read/write wait queue active!\n"); in tty_release()
1818 tty_warn(tty, "bad slave count (%d)\n", o_tty->count); in tty_release()
1822 if (--tty->count < 0) { in tty_release()
1823 tty_warn(tty, "bad tty->count (%d)\n", tty->count); in tty_release()
1824 tty->count = 0; in tty_release()
1845 if (!tty->count) { in tty_release()
1847 session_clear_tty(tty->session); in tty_release()
1854 final = !tty->count && !(o_tty && o_tty->count); in tty_release()
1857 tty_unlock(tty); in tty_release()
1865 tty_debug_hangup(tty, "final close\n"); in tty_release()
1867 tty_release_struct(tty, idx); in tty_release()
1884 struct tty_struct *tty; in tty_open_current_tty() local
1890 tty = get_current_tty(); in tty_open_current_tty()
1891 if (!tty) in tty_open_current_tty()
1896 tty_lock(tty); in tty_open_current_tty()
1897 tty_kref_put(tty); /* safe to drop the kref now */ in tty_open_current_tty()
1899 retval = tty_reopen(tty); in tty_open_current_tty()
1901 tty_unlock(tty); in tty_open_current_tty()
1902 tty = ERR_PTR(retval); in tty_open_current_tty()
1904 return tty; in tty_open_current_tty()
1973 struct tty_struct *tty; in tty_kopen() local
1985 tty = tty_driver_lookup_tty(driver, NULL, index); in tty_kopen()
1986 if (IS_ERR(tty)) in tty_kopen()
1989 if (tty) { in tty_kopen()
1991 tty_kref_put(tty); in tty_kopen()
1992 tty = ERR_PTR(-EBUSY); in tty_kopen()
1994 tty = tty_init_dev(driver, index); in tty_kopen()
1995 if (IS_ERR(tty)) in tty_kopen()
1997 tty_port_set_kopened(tty->port, 1); in tty_kopen()
2002 return tty; in tty_kopen()
2024 struct tty_struct *tty; in tty_open_by_driver() local
2037 tty = tty_driver_lookup_tty(driver, filp, index); in tty_open_by_driver()
2038 if (IS_ERR(tty)) { in tty_open_by_driver()
2043 if (tty) { in tty_open_by_driver()
2044 if (tty_port_kopened(tty->port)) { in tty_open_by_driver()
2045 tty_kref_put(tty); in tty_open_by_driver()
2047 tty = ERR_PTR(-EBUSY); in tty_open_by_driver()
2051 retval = tty_lock_interruptible(tty); in tty_open_by_driver()
2052 tty_kref_put(tty); /* drop kref from tty_driver_lookup_tty() */ in tty_open_by_driver()
2056 tty = ERR_PTR(retval); in tty_open_by_driver()
2059 retval = tty_reopen(tty); in tty_open_by_driver()
2061 tty_unlock(tty); in tty_open_by_driver()
2062 tty = ERR_PTR(retval); in tty_open_by_driver()
2065 tty = tty_init_dev(driver, index); in tty_open_by_driver()
2070 return tty; in tty_open_by_driver()
2099 struct tty_struct *tty; in tty_open() local
2111 tty = tty_open_current_tty(device, filp); in tty_open()
2112 if (!tty) in tty_open()
2113 tty = tty_open_by_driver(device, filp); in tty_open()
2115 if (IS_ERR(tty)) { in tty_open()
2117 retval = PTR_ERR(tty); in tty_open()
2124 tty_add_file(tty, filp); in tty_open()
2126 check_tty_count(tty, __func__); in tty_open()
2127 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in tty_open()
2129 if (tty->ops->open) in tty_open()
2130 retval = tty->ops->open(tty, filp); in tty_open()
2136 tty_debug_hangup(tty, "open error %d, releasing\n", retval); in tty_open()
2138 tty_unlock(tty); /* need to call tty_release without BTM */ in tty_open()
2154 clear_bit(TTY_HUPPED, &tty->flags); in tty_open()
2159 (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_open()
2160 tty->driver->subtype == PTY_TYPE_MASTER); in tty_open()
2162 tty_open_proc_set_tty(filp, tty); in tty_open()
2163 tty_unlock(tty); in tty_open()
2183 struct tty_struct *tty = file_tty(filp); in tty_poll() local
2187 if (tty_paranoia_check(tty, file_inode(filp), "tty_poll")) in tty_poll()
2190 ld = tty_ldisc_ref_wait(tty); in tty_poll()
2194 ret = ld->ops->poll(tty, filp, wait); in tty_poll()
2201 struct tty_struct *tty = file_tty(filp); in __tty_fasync() local
2205 if (tty_paranoia_check(tty, file_inode(filp), "tty_fasync")) in __tty_fasync()
2208 retval = fasync_helper(fd, filp, on, &tty->fasync); in __tty_fasync()
2216 spin_lock_irqsave(&tty->ctrl_lock, flags); in __tty_fasync()
2217 if (tty->pgrp) { in __tty_fasync()
2218 pid = tty->pgrp; in __tty_fasync()
2225 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __tty_fasync()
2236 struct tty_struct *tty = file_tty(filp); in tty_fasync() local
2239 tty_lock(tty); in tty_fasync()
2242 tty_unlock(tty); in tty_fasync()
2262 static int tiocsti(struct tty_struct *tty, char __user *p) in tiocsti() argument
2267 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) in tiocsti()
2271 tty_audit_tiocsti(tty, ch); in tiocsti()
2272 ld = tty_ldisc_ref_wait(tty); in tiocsti()
2275 tty_buffer_lock_exclusive(tty->port); in tiocsti()
2277 ld->ops->receive_buf(tty, &ch, &mbz, 1); in tiocsti()
2278 tty_buffer_unlock_exclusive(tty->port); in tiocsti()
2294 static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocgwinsz() argument
2298 mutex_lock(&tty->winsize_mutex); in tiocgwinsz()
2299 err = copy_to_user(arg, &tty->winsize, sizeof(*arg)); in tiocgwinsz()
2300 mutex_unlock(&tty->winsize_mutex); in tiocgwinsz()
2314 int tty_do_resize(struct tty_struct *tty, struct winsize *ws) in tty_do_resize() argument
2319 mutex_lock(&tty->winsize_mutex); in tty_do_resize()
2320 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in tty_do_resize()
2324 pgrp = tty_get_pgrp(tty); in tty_do_resize()
2329 tty->winsize = *ws; in tty_do_resize()
2331 mutex_unlock(&tty->winsize_mutex); in tty_do_resize()
2351 static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocswinsz() argument
2357 if (tty->ops->resize) in tiocswinsz()
2358 return tty->ops->resize(tty, &tmp_ws); in tiocswinsz()
2360 return tty_do_resize(tty, &tmp_ws); in tiocswinsz()
2412 static int tiocsetd(struct tty_struct *tty, int __user *p) in tiocsetd() argument
2420 ret = tty_set_ldisc(tty, disc); in tiocsetd()
2436 static int tiocgetd(struct tty_struct *tty, int __user *p) in tiocgetd() argument
2441 ld = tty_ldisc_ref_wait(tty); in tiocgetd()
2462 static int send_break(struct tty_struct *tty, unsigned int duration) in send_break() argument
2466 if (tty->ops->break_ctl == NULL) in send_break()
2469 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK) in send_break()
2470 retval = tty->ops->break_ctl(tty, duration); in send_break()
2473 if (tty_write_lock(tty, 0) < 0) in send_break()
2475 retval = tty->ops->break_ctl(tty, -1); in send_break()
2480 retval = tty->ops->break_ctl(tty, 0); in send_break()
2482 tty_write_unlock(tty); in send_break()
2500 static int tty_tiocmget(struct tty_struct *tty, int __user *p) in tty_tiocmget() argument
2504 if (tty->ops->tiocmget) { in tty_tiocmget()
2505 retval = tty->ops->tiocmget(tty); in tty_tiocmget()
2525 static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd, in tty_tiocmset() argument
2531 if (tty->ops->tiocmset == NULL) in tty_tiocmset()
2552 return tty->ops->tiocmset(tty, set, clear); in tty_tiocmset()
2555 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) in tty_tiocgicount() argument
2560 if (tty->ops->get_icount) in tty_tiocgicount()
2561 retval = tty->ops->get_icount(tty, &icount); in tty_tiocgicount()
2569 static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocsserial() argument
2586 if (!tty->ops->set_serial) in tty_tiocsserial()
2588 return tty->ops->set_serial(tty, &v); in tty_tiocsserial()
2591 static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocgserial() argument
2597 if (!tty->ops->get_serial) in tty_tiocgserial()
2599 err = tty->ops->get_serial(tty, &v); in tty_tiocgserial()
2609 static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) in tty_pair_get_tty() argument
2611 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_pair_get_tty()
2612 tty->driver->subtype == PTY_TYPE_MASTER) in tty_pair_get_tty()
2613 tty = tty->link; in tty_pair_get_tty()
2614 return tty; in tty_pair_get_tty()
2622 struct tty_struct *tty = file_tty(file); in tty_ioctl() local
2628 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_ioctl()
2631 real_tty = tty_pair_get_tty(tty); in tty_ioctl()
2642 retval = tty_check_change(tty); in tty_ioctl()
2646 tty_wait_until_sent(tty, 0); in tty_ioctl()
2658 return tiocsti(tty, p); in tty_ioctl()
2664 return real_tty != tty ? -EINVAL : tioccons(file); in tty_ioctl()
2666 set_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2669 clear_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2673 int excl = test_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2677 return tiocgetd(tty, p); in tty_ioctl()
2679 return tiocsetd(tty, p); in tty_ioctl()
2683 tty_vhangup(tty); in tty_ioctl()
2694 if (tty->ops->break_ctl) in tty_ioctl()
2695 return tty->ops->break_ctl(tty, -1); in tty_ioctl()
2698 if (tty->ops->break_ctl) in tty_ioctl()
2699 return tty->ops->break_ctl(tty, 0); in tty_ioctl()
2707 return send_break(tty, 250); in tty_ioctl()
2710 return send_break(tty, arg ? arg*100 : 250); in tty_ioctl()
2713 return tty_tiocmget(tty, p); in tty_ioctl()
2717 return tty_tiocmset(tty, cmd, p); in tty_ioctl()
2719 return tty_tiocgicount(tty, p); in tty_ioctl()
2725 tty_buffer_flush(tty, NULL); in tty_ioctl()
2730 return tty_tiocsserial(tty, p); in tty_ioctl()
2732 return tty_tiocgserial(tty, p); in tty_ioctl()
2735 return ptm_open_peer(file, tty, (int)arg); in tty_ioctl()
2737 retval = tty_jobctrl_ioctl(tty, real_tty, file, cmd, arg); in tty_ioctl()
2741 if (tty->ops->ioctl) { in tty_ioctl()
2742 retval = tty->ops->ioctl(tty, cmd, arg); in tty_ioctl()
2746 ld = tty_ldisc_ref_wait(tty); in tty_ioctl()
2751 retval = ld->ops->ioctl(tty, file, cmd, arg); in tty_ioctl()
2783 static int compat_tty_tiocsserial(struct tty_struct *tty, in compat_tty_tiocsserial() argument
2808 if (!tty->ops->set_serial) in compat_tty_tiocsserial()
2810 return tty->ops->set_serial(tty, &v); in compat_tty_tiocsserial()
2813 static int compat_tty_tiocgserial(struct tty_struct *tty, in compat_tty_tiocgserial() argument
2823 if (!tty->ops->get_serial) in compat_tty_tiocgserial()
2825 err = tty->ops->get_serial(tty, &v); in compat_tty_tiocgserial()
2840 struct tty_struct *tty = file_tty(file); in tty_compat_ioctl() local
2923 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_compat_ioctl()
2928 return compat_tty_tiocsserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2930 return compat_tty_tiocgserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2932 if (tty->ops->compat_ioctl) { in tty_compat_ioctl()
2933 retval = tty->ops->compat_ioctl(tty, cmd, arg); in tty_compat_ioctl()
2938 ld = tty_ldisc_ref_wait(tty); in tty_compat_ioctl()
2942 retval = ld->ops->compat_ioctl(tty, file, cmd, arg); in tty_compat_ioctl()
2944 retval = ld->ops->ioctl(tty, file, in tty_compat_ioctl()
2978 void __do_SAK(struct tty_struct *tty) in __do_SAK() argument
2981 tty_hangup(tty); in __do_SAK()
2988 if (!tty) in __do_SAK()
2991 spin_lock_irqsave(&tty->ctrl_lock, flags); in __do_SAK()
2992 session = get_pid(tty->session); in __do_SAK()
2993 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __do_SAK()
2995 tty_ldisc_flush(tty); in __do_SAK()
2997 tty_driver_flush_buffer(tty); in __do_SAK()
3002 tty_notice(tty, "SAK: killed process %d (%s): by session\n", in __do_SAK()
3009 if (p->signal->tty == tty) { in __do_SAK()
3010 tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", in __do_SAK()
3016 i = iterate_fd(p->files, 0, this_tty, tty); in __do_SAK()
3018 tty_notice(tty, "SAK: killed process %d (%s): by fd#%d\n", in __do_SAK()
3031 struct tty_struct *tty = in do_SAK_work() local
3033 __do_SAK(tty); in do_SAK_work()
3042 void do_SAK(struct tty_struct *tty) in do_SAK() argument
3044 if (!tty) in do_SAK()
3046 schedule_work(&tty->SAK_work); in do_SAK()
3052 static struct device *tty_get_device(struct tty_struct *tty) in tty_get_device() argument
3054 dev_t devt = tty_devnum(tty); in tty_get_device()
3069 struct tty_struct *tty; in alloc_tty_struct() local
3071 tty = kzalloc(sizeof(*tty), GFP_KERNEL); in alloc_tty_struct()
3072 if (!tty) in alloc_tty_struct()
3075 kref_init(&tty->kref); in alloc_tty_struct()
3076 tty->magic = TTY_MAGIC; in alloc_tty_struct()
3077 if (tty_ldisc_init(tty)) { in alloc_tty_struct()
3078 kfree(tty); in alloc_tty_struct()
3081 tty->session = NULL; in alloc_tty_struct()
3082 tty->pgrp = NULL; in alloc_tty_struct()
3083 mutex_init(&tty->legacy_mutex); in alloc_tty_struct()
3084 mutex_init(&tty->throttle_mutex); in alloc_tty_struct()
3085 init_rwsem(&tty->termios_rwsem); in alloc_tty_struct()
3086 mutex_init(&tty->winsize_mutex); in alloc_tty_struct()
3087 init_ldsem(&tty->ldisc_sem); in alloc_tty_struct()
3088 init_waitqueue_head(&tty->write_wait); in alloc_tty_struct()
3089 init_waitqueue_head(&tty->read_wait); in alloc_tty_struct()
3090 INIT_WORK(&tty->hangup_work, do_tty_hangup); in alloc_tty_struct()
3091 mutex_init(&tty->atomic_write_lock); in alloc_tty_struct()
3092 spin_lock_init(&tty->ctrl_lock); in alloc_tty_struct()
3093 spin_lock_init(&tty->flow_lock); in alloc_tty_struct()
3094 spin_lock_init(&tty->files_lock); in alloc_tty_struct()
3095 INIT_LIST_HEAD(&tty->tty_files); in alloc_tty_struct()
3096 INIT_WORK(&tty->SAK_work, do_SAK_work); in alloc_tty_struct()
3098 tty->driver = driver; in alloc_tty_struct()
3099 tty->ops = driver->ops; in alloc_tty_struct()
3100 tty->index = idx; in alloc_tty_struct()
3101 tty_line_name(driver, idx, tty->name); in alloc_tty_struct()
3102 tty->dev = tty_get_device(tty); in alloc_tty_struct()
3104 return tty; in alloc_tty_struct()
3119 int tty_put_char(struct tty_struct *tty, unsigned char ch) in tty_put_char() argument
3121 if (tty->ops->put_char) in tty_put_char()
3122 return tty->ops->put_char(tty, ch); in tty_put_char()
3123 return tty->ops->write(tty, &ch, 1); in tty_put_char()
3485 dev_t tty_devnum(struct tty_struct *tty) in tty_devnum() argument
3487 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; in tty_devnum()