• Home
  • Raw
  • Download

Lines Matching refs:tty

110 # define tty_debug_hangup(tty, f, args...)	tty_debug(tty, f, ##args)  argument
112 # define tty_debug_hangup(tty, f, args...) do { } while (0) argument
156 static void release_tty(struct tty_struct *tty, int idx);
167 static void free_tty_struct(struct tty_struct *tty) in free_tty_struct() argument
169 tty_ldisc_deinit(tty); in free_tty_struct()
170 put_device(tty->dev); in free_tty_struct()
171 kfree(tty->write_buf); in free_tty_struct()
172 tty->magic = 0xDEADDEAD; in free_tty_struct()
173 kfree(tty); in free_tty_struct()
178 return ((struct tty_file_private *)file->private_data)->tty; in file_tty()
195 void tty_add_file(struct tty_struct *tty, struct file *file) in tty_add_file() argument
199 priv->tty = tty; in tty_add_file()
202 spin_lock(&tty->files_lock); in tty_add_file()
203 list_add(&priv->list, &tty->tty_files); in tty_add_file()
204 spin_unlock(&tty->files_lock); in tty_add_file()
225 struct tty_struct *tty = priv->tty; in tty_del_file() local
227 spin_lock(&tty->files_lock); in tty_del_file()
229 spin_unlock(&tty->files_lock); in tty_del_file()
243 const char *tty_name(const struct tty_struct *tty) in tty_name() argument
245 if (!tty) /* Hmm. NULL pointer. That's fun. */ in tty_name()
247 return tty->name; in tty_name()
252 const char *tty_driver_name(const struct tty_struct *tty) in tty_driver_name() argument
254 if (!tty || !tty->driver) in tty_driver_name()
256 return tty->driver->name; in tty_driver_name()
259 static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, in tty_paranoia_check() argument
263 if (!tty) { in tty_paranoia_check()
268 if (tty->magic != TTY_MAGIC) { in tty_paranoia_check()
278 static int check_tty_count(struct tty_struct *tty, const char *routine) in check_tty_count() argument
284 spin_lock(&tty->files_lock); in check_tty_count()
285 list_for_each(p, &tty->tty_files) { in check_tty_count()
288 spin_unlock(&tty->files_lock); in check_tty_count()
289 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in check_tty_count()
290 tty->driver->subtype == PTY_TYPE_SLAVE && in check_tty_count()
291 tty->link && tty->link->count) in check_tty_count()
293 if (tty->count != count) { in check_tty_count()
294 tty_warn(tty, "%s: tty->count(%d) != #fd's(%d)\n", in check_tty_count()
295 routine, tty->count, count); in check_tty_count()
396 int __tty_check_change(struct tty_struct *tty, int sig) in __tty_check_change() argument
402 if (current->signal->tty != tty) in __tty_check_change()
408 spin_lock_irqsave(&tty->ctrl_lock, flags); in __tty_check_change()
409 tty_pgrp = tty->pgrp; in __tty_check_change()
410 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __tty_check_change()
412 if (tty_pgrp && pgrp != tty->pgrp) { in __tty_check_change()
427 tty_warn(tty, "sig=%d, tty->pgrp == NULL!\n", sig); in __tty_check_change()
432 int tty_check_change(struct tty_struct *tty) in tty_check_change() argument
434 return __tty_check_change(tty, SIGTTOU); in tty_check_change()
515 struct tty_struct *tty; in proc_clear_tty() local
517 tty = p->signal->tty; in proc_clear_tty()
518 p->signal->tty = NULL; in proc_clear_tty()
520 tty_kref_put(tty); in proc_clear_tty()
533 static void __proc_set_tty(struct tty_struct *tty) in __proc_set_tty() argument
537 spin_lock_irqsave(&tty->ctrl_lock, flags); in __proc_set_tty()
542 put_pid(tty->session); in __proc_set_tty()
543 put_pid(tty->pgrp); in __proc_set_tty()
544 tty->pgrp = get_pid(task_pgrp(current)); in __proc_set_tty()
545 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __proc_set_tty()
546 tty->session = get_pid(task_session(current)); in __proc_set_tty()
547 if (current->signal->tty) { in __proc_set_tty()
548 tty_debug(tty, "current tty %s not NULL!!\n", in __proc_set_tty()
549 current->signal->tty->name); in __proc_set_tty()
550 tty_kref_put(current->signal->tty); in __proc_set_tty()
553 current->signal->tty = tty_kref_get(tty); in __proc_set_tty()
557 static void proc_set_tty(struct tty_struct *tty) in proc_set_tty() argument
560 __proc_set_tty(tty); in proc_set_tty()
566 struct tty_struct *tty; in get_current_tty() local
570 tty = tty_kref_get(current->signal->tty); in get_current_tty()
572 return tty; in get_current_tty()
593 void tty_wakeup(struct tty_struct *tty) in tty_wakeup() argument
597 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { in tty_wakeup()
598 ld = tty_ldisc_ref(tty); in tty_wakeup()
601 ld->ops->write_wakeup(tty); in tty_wakeup()
605 wake_up_interruptible_poll(&tty->write_wait, POLLOUT); in tty_wakeup()
622 static int tty_signal_session_leader(struct tty_struct *tty, int exit_session) in tty_signal_session_leader() argument
629 if (tty->session) { in tty_signal_session_leader()
630 do_each_pid_task(tty->session, PIDTYPE_SID, p) { in tty_signal_session_leader()
632 if (p->signal->tty == tty) { in tty_signal_session_leader()
633 p->signal->tty = NULL; in tty_signal_session_leader()
645 spin_lock(&tty->ctrl_lock); in tty_signal_session_leader()
646 tty_pgrp = get_pid(tty->pgrp); in tty_signal_session_leader()
647 if (tty->pgrp) in tty_signal_session_leader()
648 p->signal->tty_old_pgrp = get_pid(tty->pgrp); in tty_signal_session_leader()
649 spin_unlock(&tty->ctrl_lock); in tty_signal_session_leader()
651 } while_each_pid_task(tty->session, PIDTYPE_SID, p); in tty_signal_session_leader()
686 static void __tty_hangup(struct tty_struct *tty, int exit_session) in __tty_hangup() argument
694 if (!tty) in __tty_hangup()
699 if (redirect && file_tty(redirect) == tty) { in __tty_hangup()
705 tty_lock(tty); in __tty_hangup()
707 if (test_bit(TTY_HUPPED, &tty->flags)) { in __tty_hangup()
708 tty_unlock(tty); in __tty_hangup()
718 set_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
723 check_tty_count(tty, "tty_hangup"); in __tty_hangup()
725 spin_lock(&tty->files_lock); in __tty_hangup()
727 list_for_each_entry(priv, &tty->tty_files, list) { in __tty_hangup()
737 spin_unlock(&tty->files_lock); in __tty_hangup()
739 refs = tty_signal_session_leader(tty, exit_session); in __tty_hangup()
742 tty_kref_put(tty); in __tty_hangup()
744 tty_ldisc_hangup(tty, cons_filp != NULL); in __tty_hangup()
746 spin_lock_irq(&tty->ctrl_lock); in __tty_hangup()
747 clear_bit(TTY_THROTTLED, &tty->flags); in __tty_hangup()
748 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in __tty_hangup()
749 put_pid(tty->session); in __tty_hangup()
750 put_pid(tty->pgrp); in __tty_hangup()
751 tty->session = NULL; in __tty_hangup()
752 tty->pgrp = NULL; in __tty_hangup()
753 tty->ctrl_status = 0; in __tty_hangup()
754 spin_unlock_irq(&tty->ctrl_lock); in __tty_hangup()
763 if (tty->ops->close) in __tty_hangup()
765 tty->ops->close(tty, cons_filp); in __tty_hangup()
766 } else if (tty->ops->hangup) in __tty_hangup()
767 tty->ops->hangup(tty); in __tty_hangup()
773 set_bit(TTY_HUPPED, &tty->flags); in __tty_hangup()
774 clear_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
775 tty_unlock(tty); in __tty_hangup()
783 struct tty_struct *tty = in do_tty_hangup() local
786 __tty_hangup(tty, 0); in do_tty_hangup()
797 void tty_hangup(struct tty_struct *tty) in tty_hangup() argument
799 tty_debug_hangup(tty, "hangup\n"); in tty_hangup()
800 schedule_work(&tty->hangup_work); in tty_hangup()
814 void tty_vhangup(struct tty_struct *tty) in tty_vhangup() argument
816 tty_debug_hangup(tty, "vhangup\n"); in tty_vhangup()
817 __tty_hangup(tty, 0); in tty_vhangup()
831 struct tty_struct *tty; in tty_vhangup_self() local
833 tty = get_current_tty(); in tty_vhangup_self()
834 if (tty) { in tty_vhangup_self()
835 tty_vhangup(tty); in tty_vhangup_self()
836 tty_kref_put(tty); in tty_vhangup_self()
851 static void tty_vhangup_session(struct tty_struct *tty) in tty_vhangup_session() argument
853 tty_debug_hangup(tty, "session hangup\n"); in tty_vhangup_session()
854 __tty_hangup(tty, 1); in tty_vhangup_session()
899 struct tty_struct *tty; in disassociate_ctty() local
904 tty = get_current_tty(); in disassociate_ctty()
905 if (tty) { in disassociate_ctty()
906 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) { in disassociate_ctty()
907 tty_vhangup_session(tty); in disassociate_ctty()
909 struct pid *tty_pgrp = tty_get_pgrp(tty); in disassociate_ctty()
917 tty_kref_put(tty); in disassociate_ctty()
937 tty = tty_kref_get(current->signal->tty); in disassociate_ctty()
938 if (tty) { in disassociate_ctty()
940 spin_lock_irqsave(&tty->ctrl_lock, flags); in disassociate_ctty()
941 put_pid(tty->session); in disassociate_ctty()
942 put_pid(tty->pgrp); in disassociate_ctty()
943 tty->session = NULL; in disassociate_ctty()
944 tty->pgrp = NULL; in disassociate_ctty()
945 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in disassociate_ctty()
946 tty_kref_put(tty); in disassociate_ctty()
948 tty_debug_hangup(tty, "no current tty\n"); in disassociate_ctty()
989 void __stop_tty(struct tty_struct *tty) in __stop_tty() argument
991 if (tty->stopped) in __stop_tty()
993 tty->stopped = 1; in __stop_tty()
994 if (tty->ops->stop) in __stop_tty()
995 tty->ops->stop(tty); in __stop_tty()
998 void stop_tty(struct tty_struct *tty) in stop_tty() argument
1002 spin_lock_irqsave(&tty->flow_lock, flags); in stop_tty()
1003 __stop_tty(tty); in stop_tty()
1004 spin_unlock_irqrestore(&tty->flow_lock, flags); in stop_tty()
1020 void __start_tty(struct tty_struct *tty) in __start_tty() argument
1022 if (!tty->stopped || tty->flow_stopped) in __start_tty()
1024 tty->stopped = 0; in __start_tty()
1025 if (tty->ops->start) in __start_tty()
1026 tty->ops->start(tty); in __start_tty()
1027 tty_wakeup(tty); in __start_tty()
1030 void start_tty(struct tty_struct *tty) in start_tty() argument
1034 spin_lock_irqsave(&tty->flow_lock, flags); in start_tty()
1035 __start_tty(tty); in start_tty()
1036 spin_unlock_irqrestore(&tty->flow_lock, flags); in start_tty()
1074 struct tty_struct *tty = file_tty(file); in tty_read() local
1077 if (tty_paranoia_check(tty, inode, "tty_read")) in tty_read()
1079 if (!tty || tty_io_error(tty)) in tty_read()
1084 ld = tty_ldisc_ref_wait(tty); in tty_read()
1088 i = ld->ops->read(tty, file, buf, count); in tty_read()
1099 static void tty_write_unlock(struct tty_struct *tty) in tty_write_unlock() argument
1101 mutex_unlock(&tty->atomic_write_lock); in tty_write_unlock()
1102 wake_up_interruptible_poll(&tty->write_wait, POLLOUT); in tty_write_unlock()
1105 static int tty_write_lock(struct tty_struct *tty, int ndelay) in tty_write_lock() argument
1107 if (!mutex_trylock(&tty->atomic_write_lock)) { in tty_write_lock()
1110 if (mutex_lock_interruptible(&tty->atomic_write_lock)) in tty_write_lock()
1122 struct tty_struct *tty, in do_tty_write() argument
1130 ret = tty_write_lock(tty, file->f_flags & O_NDELAY); in do_tty_write()
1151 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) in do_tty_write()
1157 if (tty->write_cnt < chunk) { in do_tty_write()
1168 kfree(tty->write_buf); in do_tty_write()
1169 tty->write_cnt = chunk; in do_tty_write()
1170 tty->write_buf = buf_chunk; in do_tty_write()
1179 if (copy_from_user(tty->write_buf, buf, size)) in do_tty_write()
1181 ret = write(tty, file, tty->write_buf, size); in do_tty_write()
1199 tty_write_unlock(tty); in do_tty_write()
1215 void tty_write_message(struct tty_struct *tty, char *msg) in tty_write_message() argument
1217 if (tty) { in tty_write_message()
1218 mutex_lock(&tty->atomic_write_lock); in tty_write_message()
1219 tty_lock(tty); in tty_write_message()
1220 if (tty->ops->write && tty->count > 0) in tty_write_message()
1221 tty->ops->write(tty, msg, strlen(msg)); in tty_write_message()
1222 tty_unlock(tty); in tty_write_message()
1223 tty_write_unlock(tty); in tty_write_message()
1248 struct tty_struct *tty = file_tty(file); in tty_write() local
1252 if (tty_paranoia_check(tty, file_inode(file), "tty_write")) in tty_write()
1254 if (!tty || !tty->ops->write || tty_io_error(tty)) in tty_write()
1257 if (tty->ops->write_room == NULL) in tty_write()
1258 tty_err(tty, "missing write_room method\n"); in tty_write()
1259 ld = tty_ldisc_ref_wait(tty); in tty_write()
1265 ret = do_tty_write(ld->ops->write, tty, file, buf, count); in tty_write()
1297 int tty_send_xchar(struct tty_struct *tty, char ch) in tty_send_xchar() argument
1299 int was_stopped = tty->stopped; in tty_send_xchar()
1301 if (tty->ops->send_xchar) { in tty_send_xchar()
1302 down_read(&tty->termios_rwsem); in tty_send_xchar()
1303 tty->ops->send_xchar(tty, ch); in tty_send_xchar()
1304 up_read(&tty->termios_rwsem); in tty_send_xchar()
1308 if (tty_write_lock(tty, 0) < 0) in tty_send_xchar()
1311 down_read(&tty->termios_rwsem); in tty_send_xchar()
1313 start_tty(tty); in tty_send_xchar()
1314 tty->ops->write(tty, &ch, 1); in tty_send_xchar()
1316 stop_tty(tty); in tty_send_xchar()
1317 up_read(&tty->termios_rwsem); in tty_send_xchar()
1318 tty_write_unlock(tty); in tty_send_xchar()
1377 struct tty_struct *tty; in tty_driver_lookup_tty() local
1380 tty = driver->ops->lookup(driver, file, idx); in tty_driver_lookup_tty()
1382 tty = driver->ttys[idx]; in tty_driver_lookup_tty()
1384 if (!IS_ERR(tty)) in tty_driver_lookup_tty()
1385 tty_kref_get(tty); in tty_driver_lookup_tty()
1386 return tty; in tty_driver_lookup_tty()
1397 void tty_init_termios(struct tty_struct *tty) in tty_init_termios() argument
1400 int idx = tty->index; in tty_init_termios()
1402 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_init_termios()
1403 tty->termios = tty->driver->init_termios; in tty_init_termios()
1406 tp = tty->driver->termios[idx]; in tty_init_termios()
1408 tty->termios = *tp; in tty_init_termios()
1409 tty->termios.c_line = tty->driver->init_termios.c_line; in tty_init_termios()
1411 tty->termios = tty->driver->init_termios; in tty_init_termios()
1414 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); in tty_init_termios()
1415 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); in tty_init_termios()
1419 int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty) in tty_standard_install() argument
1421 tty_init_termios(tty); in tty_standard_install()
1423 tty->count++; in tty_standard_install()
1424 driver->ttys[tty->index] = tty; in tty_standard_install()
1442 struct tty_struct *tty) in tty_driver_install_tty() argument
1444 return driver->ops->install ? driver->ops->install(driver, tty) : in tty_driver_install_tty()
1445 tty_standard_install(driver, tty); in tty_driver_install_tty()
1458 static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) in tty_driver_remove_tty() argument
1461 driver->ops->remove(driver, tty); in tty_driver_remove_tty()
1463 driver->ttys[tty->index] = NULL; in tty_driver_remove_tty()
1475 static int tty_reopen(struct tty_struct *tty) in tty_reopen() argument
1477 struct tty_driver *driver = tty->driver; in tty_reopen()
1483 if (!tty->count) in tty_reopen()
1486 if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) in tty_reopen()
1489 tty->count++; in tty_reopen()
1491 if (!tty->ldisc) in tty_reopen()
1492 return tty_ldisc_reinit(tty, tty->termios.c_line); in tty_reopen()
1523 struct tty_struct *tty; in tty_init_dev() local
1537 tty = alloc_tty_struct(driver, idx); in tty_init_dev()
1538 if (!tty) { in tty_init_dev()
1543 tty_lock(tty); in tty_init_dev()
1544 retval = tty_driver_install_tty(driver, tty); in tty_init_dev()
1548 if (!tty->port) in tty_init_dev()
1549 tty->port = driver->ports[idx]; in tty_init_dev()
1551 WARN_RATELIMIT(!tty->port, in tty_init_dev()
1553 __func__, tty->driver->name); in tty_init_dev()
1555 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_init_dev()
1558 tty->port->itty = tty; in tty_init_dev()
1565 retval = tty_ldisc_setup(tty, tty->link); in tty_init_dev()
1568 tty_ldisc_unlock(tty); in tty_init_dev()
1570 return tty; in tty_init_dev()
1573 tty_unlock(tty); in tty_init_dev()
1574 free_tty_struct(tty); in tty_init_dev()
1581 tty_ldisc_unlock(tty); in tty_init_dev()
1582 tty_info_ratelimited(tty, "ldisc open failed (%d), clearing slot %d\n", in tty_init_dev()
1585 tty_unlock(tty); in tty_init_dev()
1586 release_tty(tty, idx); in tty_init_dev()
1590 static void tty_free_termios(struct tty_struct *tty) in tty_free_termios() argument
1593 int idx = tty->index; in tty_free_termios()
1596 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_free_termios()
1600 tp = tty->driver->termios[idx]; in tty_free_termios()
1605 tty->driver->termios[idx] = tp; in tty_free_termios()
1607 *tp = tty->termios; in tty_free_termios()
1616 static void tty_flush_works(struct tty_struct *tty) in tty_flush_works() argument
1618 flush_work(&tty->SAK_work); in tty_flush_works()
1619 flush_work(&tty->hangup_work); in tty_flush_works()
1620 if (tty->link) { in tty_flush_works()
1621 flush_work(&tty->link->SAK_work); in tty_flush_works()
1622 flush_work(&tty->link->hangup_work); in tty_flush_works()
1643 struct tty_struct *tty = in release_one_tty() local
1645 struct tty_driver *driver = tty->driver; in release_one_tty()
1648 if (tty->ops->cleanup) in release_one_tty()
1649 tty->ops->cleanup(tty); in release_one_tty()
1651 tty->magic = 0; in release_one_tty()
1655 spin_lock(&tty->files_lock); in release_one_tty()
1656 list_del_init(&tty->tty_files); in release_one_tty()
1657 spin_unlock(&tty->files_lock); in release_one_tty()
1659 put_pid(tty->pgrp); in release_one_tty()
1660 put_pid(tty->session); in release_one_tty()
1661 free_tty_struct(tty); in release_one_tty()
1666 struct tty_struct *tty = container_of(kref, struct tty_struct, kref); in queue_release_one_tty() local
1670 INIT_WORK(&tty->hangup_work, release_one_tty); in queue_release_one_tty()
1671 schedule_work(&tty->hangup_work); in queue_release_one_tty()
1682 void tty_kref_put(struct tty_struct *tty) in tty_kref_put() argument
1684 if (tty) in tty_kref_put()
1685 kref_put(&tty->kref, queue_release_one_tty); in tty_kref_put()
1701 static void release_tty(struct tty_struct *tty, int idx) in release_tty() argument
1704 WARN_ON(tty->index != idx); in release_tty()
1706 if (tty->ops->shutdown) in release_tty()
1707 tty->ops->shutdown(tty); in release_tty()
1708 tty_free_termios(tty); in release_tty()
1709 tty_driver_remove_tty(tty->driver, tty); in release_tty()
1710 tty->port->itty = NULL; in release_tty()
1711 if (tty->link) in release_tty()
1712 tty->link->port->itty = NULL; in release_tty()
1713 tty_buffer_cancel_work(tty->port); in release_tty()
1714 if (tty->link) in release_tty()
1715 tty_buffer_cancel_work(tty->link->port); in release_tty()
1717 tty_kref_put(tty->link); in release_tty()
1718 tty_kref_put(tty); in release_tty()
1730 static int tty_release_checks(struct tty_struct *tty, int idx) in tty_release_checks() argument
1733 if (idx < 0 || idx >= tty->driver->num) { in tty_release_checks()
1734 tty_debug(tty, "bad idx %d\n", idx); in tty_release_checks()
1739 if (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) in tty_release_checks()
1742 if (tty != tty->driver->ttys[idx]) { in tty_release_checks()
1743 tty_debug(tty, "bad driver table[%d] = %p\n", in tty_release_checks()
1744 idx, tty->driver->ttys[idx]); in tty_release_checks()
1747 if (tty->driver->other) { in tty_release_checks()
1748 struct tty_struct *o_tty = tty->link; in tty_release_checks()
1750 if (o_tty != tty->driver->other->ttys[idx]) { in tty_release_checks()
1751 tty_debug(tty, "bad other table[%d] = %p\n", in tty_release_checks()
1752 idx, tty->driver->other->ttys[idx]); in tty_release_checks()
1755 if (o_tty->link != tty) { in tty_release_checks()
1756 tty_debug(tty, "bad link = %p\n", o_tty->link); in tty_release_checks()
1785 struct tty_struct *tty = file_tty(filp); in tty_release() local
1792 if (tty_paranoia_check(tty, inode, __func__)) in tty_release()
1795 tty_lock(tty); in tty_release()
1796 check_tty_count(tty, __func__); in tty_release()
1800 idx = tty->index; in tty_release()
1801 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_release()
1802 tty->driver->subtype == PTY_TYPE_MASTER) in tty_release()
1803 o_tty = tty->link; in tty_release()
1805 if (tty_release_checks(tty, idx)) { in tty_release()
1806 tty_unlock(tty); in tty_release()
1810 tty_debug_hangup(tty, "releasing (count=%d)\n", tty->count); in tty_release()
1812 if (tty->ops->close) in tty_release()
1813 tty->ops->close(tty, filp); in tty_release()
1834 if (tty->count <= 1) { in tty_release()
1835 if (waitqueue_active(&tty->read_wait)) { in tty_release()
1836 wake_up_poll(&tty->read_wait, POLLIN); in tty_release()
1839 if (waitqueue_active(&tty->write_wait)) { in tty_release()
1840 wake_up_poll(&tty->write_wait, POLLOUT); in tty_release()
1859 tty_warn(tty, "read/write wait queue active!\n"); in tty_release()
1870 tty_warn(tty, "bad slave count (%d)\n", o_tty->count); in tty_release()
1874 if (--tty->count < 0) { in tty_release()
1875 tty_warn(tty, "bad tty->count (%d)\n", tty->count); in tty_release()
1876 tty->count = 0; in tty_release()
1897 if (!tty->count) { in tty_release()
1899 session_clear_tty(tty->session); in tty_release()
1906 final = !tty->count && !(o_tty && o_tty->count); in tty_release()
1909 tty_unlock(tty); in tty_release()
1917 tty_debug_hangup(tty, "final close\n"); in tty_release()
1921 tty_ldisc_release(tty); in tty_release()
1924 tty_flush_works(tty); in tty_release()
1926 tty_debug_hangup(tty, "freeing structure\n"); in tty_release()
1934 release_tty(tty, idx); in tty_release()
1953 struct tty_struct *tty; in tty_open_current_tty() local
1959 tty = get_current_tty(); in tty_open_current_tty()
1960 if (!tty) in tty_open_current_tty()
1965 tty_lock(tty); in tty_open_current_tty()
1966 tty_kref_put(tty); /* safe to drop the kref now */ in tty_open_current_tty()
1968 retval = tty_reopen(tty); in tty_open_current_tty()
1970 tty_unlock(tty); in tty_open_current_tty()
1971 tty = ERR_PTR(retval); in tty_open_current_tty()
1973 return tty; in tty_open_current_tty()
2042 struct tty_struct *tty; in tty_open_by_driver() local
2055 tty = tty_driver_lookup_tty(driver, filp, index); in tty_open_by_driver()
2056 if (IS_ERR(tty)) { in tty_open_by_driver()
2061 if (tty) { in tty_open_by_driver()
2063 retval = tty_lock_interruptible(tty); in tty_open_by_driver()
2064 tty_kref_put(tty); /* drop kref from tty_driver_lookup_tty() */ in tty_open_by_driver()
2068 tty = ERR_PTR(retval); in tty_open_by_driver()
2071 retval = tty_reopen(tty); in tty_open_by_driver()
2073 tty_unlock(tty); in tty_open_by_driver()
2074 tty = ERR_PTR(retval); in tty_open_by_driver()
2077 tty = tty_init_dev(driver, index); in tty_open_by_driver()
2082 return tty; in tty_open_by_driver()
2111 struct tty_struct *tty; in tty_open() local
2123 tty = tty_open_current_tty(device, filp); in tty_open()
2124 if (!tty) in tty_open()
2125 tty = tty_open_by_driver(device, inode, filp); in tty_open()
2127 if (IS_ERR(tty)) { in tty_open()
2129 retval = PTR_ERR(tty); in tty_open()
2136 tty_add_file(tty, filp); in tty_open()
2138 check_tty_count(tty, __func__); in tty_open()
2139 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in tty_open()
2141 if (tty->ops->open) in tty_open()
2142 retval = tty->ops->open(tty, filp); in tty_open()
2148 tty_debug_hangup(tty, "open error %d, releasing\n", retval); in tty_open()
2150 tty_unlock(tty); /* need to call tty_release without BTM */ in tty_open()
2166 clear_bit(TTY_HUPPED, &tty->flags); in tty_open()
2174 (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_open()
2175 tty->driver->subtype == PTY_TYPE_MASTER); in tty_open()
2179 !current->signal->tty && in tty_open()
2180 tty->session == NULL) { in tty_open()
2196 __proc_set_tty(tty); in tty_open()
2200 tty_unlock(tty); in tty_open()
2220 struct tty_struct *tty = file_tty(filp); in tty_poll() local
2224 if (tty_paranoia_check(tty, file_inode(filp), "tty_poll")) in tty_poll()
2227 ld = tty_ldisc_ref_wait(tty); in tty_poll()
2231 ret = ld->ops->poll(tty, filp, wait); in tty_poll()
2238 struct tty_struct *tty = file_tty(filp); in __tty_fasync() local
2242 if (tty_paranoia_check(tty, file_inode(filp), "tty_fasync")) in __tty_fasync()
2245 retval = fasync_helper(fd, filp, on, &tty->fasync); in __tty_fasync()
2253 spin_lock_irqsave(&tty->ctrl_lock, flags); in __tty_fasync()
2254 if (tty->pgrp) { in __tty_fasync()
2255 pid = tty->pgrp; in __tty_fasync()
2262 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __tty_fasync()
2273 struct tty_struct *tty = file_tty(filp); in tty_fasync() local
2276 tty_lock(tty); in tty_fasync()
2279 tty_unlock(tty); in tty_fasync()
2301 static int tiocsti(struct tty_struct *tty, char __user *p) in tiocsti() argument
2306 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) in tiocsti()
2310 tty_audit_tiocsti(tty, ch); in tiocsti()
2311 ld = tty_ldisc_ref_wait(tty); in tiocsti()
2314 ld->ops->receive_buf(tty, &ch, &mbz, 1); in tiocsti()
2330 static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocgwinsz() argument
2334 mutex_lock(&tty->winsize_mutex); in tiocgwinsz()
2335 err = copy_to_user(arg, &tty->winsize, sizeof(*arg)); in tiocgwinsz()
2336 mutex_unlock(&tty->winsize_mutex); in tiocgwinsz()
2351 int tty_do_resize(struct tty_struct *tty, struct winsize *ws) in tty_do_resize() argument
2356 mutex_lock(&tty->winsize_mutex); in tty_do_resize()
2357 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in tty_do_resize()
2361 pgrp = tty_get_pgrp(tty); in tty_do_resize()
2366 tty->winsize = *ws; in tty_do_resize()
2368 mutex_unlock(&tty->winsize_mutex); in tty_do_resize()
2388 static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocswinsz() argument
2394 if (tty->ops->resize) in tiocswinsz()
2395 return tty->ops->resize(tty, &tmp_ws); in tiocswinsz()
2397 return tty_do_resize(tty, &tmp_ws); in tiocswinsz()
2475 static int tiocsctty(struct tty_struct *tty, struct file *file, int arg) in tiocsctty() argument
2479 tty_lock(tty); in tiocsctty()
2482 if (current->signal->leader && (task_session(current) == tty->session)) in tiocsctty()
2489 if (!current->signal->leader || current->signal->tty) { in tiocsctty()
2494 if (tty->session) { in tiocsctty()
2503 session_clear_tty(tty->session); in tiocsctty()
2516 proc_set_tty(tty); in tiocsctty()
2519 tty_unlock(tty); in tiocsctty()
2531 struct pid *tty_get_pgrp(struct tty_struct *tty) in tty_get_pgrp() argument
2536 spin_lock_irqsave(&tty->ctrl_lock, flags); in tty_get_pgrp()
2537 pgrp = get_pid(tty->pgrp); in tty_get_pgrp()
2538 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in tty_get_pgrp()
2577 static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocgpgrp() argument
2585 if (tty == real_tty && current->signal->tty != real_tty) in tiocgpgrp()
2605 static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocspgrp() argument
2615 if (!current->signal->tty || in tiocspgrp()
2616 (current->signal->tty != real_tty) || in tiocspgrp()
2632 spin_lock_irq(&tty->ctrl_lock); in tiocspgrp()
2635 spin_unlock_irq(&tty->ctrl_lock); in tiocspgrp()
2653 static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocgsid() argument
2659 if (tty == real_tty && current->signal->tty != real_tty) in tiocgsid()
2676 static int tiocsetd(struct tty_struct *tty, int __user *p) in tiocsetd() argument
2684 ret = tty_set_ldisc(tty, disc); in tiocsetd()
2700 static int tiocgetd(struct tty_struct *tty, int __user *p) in tiocgetd() argument
2705 ld = tty_ldisc_ref_wait(tty); in tiocgetd()
2726 static int send_break(struct tty_struct *tty, unsigned int duration) in send_break() argument
2730 if (tty->ops->break_ctl == NULL) in send_break()
2733 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK) in send_break()
2734 retval = tty->ops->break_ctl(tty, duration); in send_break()
2737 if (tty_write_lock(tty, 0) < 0) in send_break()
2739 retval = tty->ops->break_ctl(tty, -1); in send_break()
2744 retval = tty->ops->break_ctl(tty, 0); in send_break()
2746 tty_write_unlock(tty); in send_break()
2765 static int tty_tiocmget(struct tty_struct *tty, int __user *p) in tty_tiocmget() argument
2769 if (tty->ops->tiocmget) { in tty_tiocmget()
2770 retval = tty->ops->tiocmget(tty); in tty_tiocmget()
2790 static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd, in tty_tiocmset() argument
2796 if (tty->ops->tiocmset == NULL) in tty_tiocmset()
2817 return tty->ops->tiocmset(tty, set, clear); in tty_tiocmset()
2820 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) in tty_tiocgicount() argument
2825 if (tty->ops->get_icount) in tty_tiocgicount()
2826 retval = tty->ops->get_icount(tty, &icount); in tty_tiocgicount()
2856 static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) in tty_pair_get_tty() argument
2858 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_pair_get_tty()
2859 tty->driver->subtype == PTY_TYPE_MASTER) in tty_pair_get_tty()
2860 tty = tty->link; in tty_pair_get_tty()
2861 return tty; in tty_pair_get_tty()
2869 struct tty_struct *tty = file_tty(file); in tty_ioctl() local
2875 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_ioctl()
2878 real_tty = tty_pair_get_tty(tty); in tty_ioctl()
2889 retval = tty_check_change(tty); in tty_ioctl()
2893 tty_wait_until_sent(tty, 0); in tty_ioctl()
2905 return tiocsti(tty, p); in tty_ioctl()
2911 return real_tty != tty ? -EINVAL : tioccons(file); in tty_ioctl()
2915 set_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2918 clear_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2922 int excl = test_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2926 if (current->signal->tty != tty) in tty_ioctl()
2933 return tiocgpgrp(tty, real_tty, p); in tty_ioctl()
2935 return tiocspgrp(tty, real_tty, p); in tty_ioctl()
2937 return tiocgsid(tty, real_tty, p); in tty_ioctl()
2939 return tiocgetd(tty, p); in tty_ioctl()
2941 return tiocsetd(tty, p); in tty_ioctl()
2945 tty_vhangup(tty); in tty_ioctl()
2956 if (tty->ops->break_ctl) in tty_ioctl()
2957 return tty->ops->break_ctl(tty, -1); in tty_ioctl()
2960 if (tty->ops->break_ctl) in tty_ioctl()
2961 return tty->ops->break_ctl(tty, 0); in tty_ioctl()
2969 return send_break(tty, 250); in tty_ioctl()
2972 return send_break(tty, arg ? arg*100 : 250); in tty_ioctl()
2975 return tty_tiocmget(tty, p); in tty_ioctl()
2979 return tty_tiocmset(tty, cmd, p); in tty_ioctl()
2981 retval = tty_tiocgicount(tty, p); in tty_ioctl()
2991 tty_buffer_flush(tty, NULL); in tty_ioctl()
2999 if (tty->ops->ioctl) { in tty_ioctl()
3000 retval = tty->ops->ioctl(tty, cmd, arg); in tty_ioctl()
3004 ld = tty_ldisc_ref_wait(tty); in tty_ioctl()
3009 retval = ld->ops->ioctl(tty, file, cmd, arg); in tty_ioctl()
3021 struct tty_struct *tty = file_tty(file); in tty_compat_ioctl() local
3025 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_compat_ioctl()
3028 if (tty->ops->compat_ioctl) { in tty_compat_ioctl()
3029 retval = tty->ops->compat_ioctl(tty, cmd, arg); in tty_compat_ioctl()
3034 ld = tty_ldisc_ref_wait(tty); in tty_compat_ioctl()
3038 retval = ld->ops->compat_ioctl(tty, file, cmd, arg); in tty_compat_ioctl()
3040 retval = n_tty_compat_ioctl_helper(tty, file, cmd, arg); in tty_compat_ioctl()
3073 void __do_SAK(struct tty_struct *tty) in __do_SAK() argument
3076 tty_hangup(tty); in __do_SAK()
3082 if (!tty) in __do_SAK()
3084 session = tty->session; in __do_SAK()
3086 tty_ldisc_flush(tty); in __do_SAK()
3088 tty_driver_flush_buffer(tty); in __do_SAK()
3093 tty_notice(tty, "SAK: killed process %d (%s): by session\n", in __do_SAK()
3100 if (p->signal->tty == tty) { in __do_SAK()
3101 tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", in __do_SAK()
3107 i = iterate_fd(p->files, 0, this_tty, tty); in __do_SAK()
3109 tty_notice(tty, "SAK: killed process %d (%s): by fd#%d\n", in __do_SAK()
3121 struct tty_struct *tty = in do_SAK_work() local
3123 __do_SAK(tty); in do_SAK_work()
3132 void do_SAK(struct tty_struct *tty) in do_SAK() argument
3134 if (!tty) in do_SAK()
3136 schedule_work(&tty->SAK_work); in do_SAK()
3148 static struct device *tty_get_device(struct tty_struct *tty) in tty_get_device() argument
3150 dev_t devt = tty_devnum(tty); in tty_get_device()
3165 struct tty_struct *tty; in alloc_tty_struct() local
3167 tty = kzalloc(sizeof(*tty), GFP_KERNEL); in alloc_tty_struct()
3168 if (!tty) in alloc_tty_struct()
3171 kref_init(&tty->kref); in alloc_tty_struct()
3172 tty->magic = TTY_MAGIC; in alloc_tty_struct()
3173 tty_ldisc_init(tty); in alloc_tty_struct()
3174 tty->session = NULL; in alloc_tty_struct()
3175 tty->pgrp = NULL; in alloc_tty_struct()
3176 mutex_init(&tty->legacy_mutex); in alloc_tty_struct()
3177 mutex_init(&tty->throttle_mutex); in alloc_tty_struct()
3178 init_rwsem(&tty->termios_rwsem); in alloc_tty_struct()
3179 mutex_init(&tty->winsize_mutex); in alloc_tty_struct()
3180 init_ldsem(&tty->ldisc_sem); in alloc_tty_struct()
3181 init_waitqueue_head(&tty->write_wait); in alloc_tty_struct()
3182 init_waitqueue_head(&tty->read_wait); in alloc_tty_struct()
3183 INIT_WORK(&tty->hangup_work, do_tty_hangup); in alloc_tty_struct()
3184 mutex_init(&tty->atomic_write_lock); in alloc_tty_struct()
3185 spin_lock_init(&tty->ctrl_lock); in alloc_tty_struct()
3186 spin_lock_init(&tty->flow_lock); in alloc_tty_struct()
3187 spin_lock_init(&tty->files_lock); in alloc_tty_struct()
3188 INIT_LIST_HEAD(&tty->tty_files); in alloc_tty_struct()
3189 INIT_WORK(&tty->SAK_work, do_SAK_work); in alloc_tty_struct()
3191 tty->driver = driver; in alloc_tty_struct()
3192 tty->ops = driver->ops; in alloc_tty_struct()
3193 tty->index = idx; in alloc_tty_struct()
3194 tty_line_name(driver, idx, tty->name); in alloc_tty_struct()
3195 tty->dev = tty_get_device(tty); in alloc_tty_struct()
3197 return tty; in alloc_tty_struct()
3212 int tty_put_char(struct tty_struct *tty, unsigned char ch) in tty_put_char() argument
3214 if (tty->ops->put_char) in tty_put_char()
3215 return tty->ops->put_char(tty, ch); in tty_put_char()
3216 return tty->ops->write(tty, &ch, 1); in tty_put_char()
3572 dev_t tty_devnum(struct tty_struct *tty) in tty_devnum() argument
3574 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; in tty_devnum()