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
160 static void release_tty(struct tty_struct *tty, int idx);
171 static void free_tty_struct(struct tty_struct *tty) in free_tty_struct() argument
173 tty_ldisc_deinit(tty); in free_tty_struct()
174 put_device(tty->dev); in free_tty_struct()
175 kfree(tty->write_buf); in free_tty_struct()
176 tty->magic = 0xDEADDEAD; in free_tty_struct()
177 kfree(tty); in free_tty_struct()
182 return ((struct tty_file_private *)file->private_data)->tty; in file_tty()
199 void tty_add_file(struct tty_struct *tty, struct file *file) in tty_add_file() argument
203 priv->tty = tty; in tty_add_file()
206 spin_lock(&tty->files_lock); in tty_add_file()
207 list_add(&priv->list, &tty->tty_files); in tty_add_file()
208 spin_unlock(&tty->files_lock); in tty_add_file()
229 struct tty_struct *tty = priv->tty; in tty_del_file() local
231 spin_lock(&tty->files_lock); in tty_del_file()
233 spin_unlock(&tty->files_lock); in tty_del_file()
247 const char *tty_name(const struct tty_struct *tty) in tty_name() argument
249 if (!tty) /* Hmm. NULL pointer. That's fun. */ in tty_name()
251 return tty->name; in tty_name()
256 const char *tty_driver_name(const struct tty_struct *tty) in tty_driver_name() argument
258 if (!tty || !tty->driver) in tty_driver_name()
260 return tty->driver->name; in tty_driver_name()
263 static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, in tty_paranoia_check() argument
267 if (!tty) { in tty_paranoia_check()
272 if (tty->magic != TTY_MAGIC) { in tty_paranoia_check()
282 static int check_tty_count(struct tty_struct *tty, const char *routine) in check_tty_count() argument
288 spin_lock(&tty->files_lock); in check_tty_count()
289 list_for_each(p, &tty->tty_files) { in check_tty_count()
292 spin_unlock(&tty->files_lock); in check_tty_count()
293 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in check_tty_count()
294 tty->driver->subtype == PTY_TYPE_SLAVE && in check_tty_count()
295 tty->link && tty->link->count) in check_tty_count()
297 if (tty_port_kopened(tty->port)) in check_tty_count()
299 if (tty->count != (count + kopen_count)) { in check_tty_count()
300 tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", in check_tty_count()
301 routine, tty->count, count, kopen_count); in check_tty_count()
472 struct tty_struct *tty = file_tty(file); in tty_show_fdinfo() local
474 if (tty && tty->ops && tty->ops->show_fdinfo) in tty_show_fdinfo()
475 tty->ops->show_fdinfo(tty, m); in tty_show_fdinfo()
528 void tty_wakeup(struct tty_struct *tty) in tty_wakeup() argument
532 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { in tty_wakeup()
533 ld = tty_ldisc_ref(tty); in tty_wakeup()
536 ld->ops->write_wakeup(tty); in tty_wakeup()
540 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_wakeup()
567 static void __tty_hangup(struct tty_struct *tty, int exit_session) in __tty_hangup() argument
575 if (!tty) in __tty_hangup()
580 if (redirect && file_tty(redirect) == tty) { in __tty_hangup()
586 tty_lock(tty); in __tty_hangup()
588 if (test_bit(TTY_HUPPED, &tty->flags)) { in __tty_hangup()
589 tty_unlock(tty); in __tty_hangup()
599 set_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
604 check_tty_count(tty, "tty_hangup"); in __tty_hangup()
606 spin_lock(&tty->files_lock); in __tty_hangup()
608 list_for_each_entry(priv, &tty->tty_files, list) { in __tty_hangup()
618 spin_unlock(&tty->files_lock); in __tty_hangup()
620 refs = tty_signal_session_leader(tty, exit_session); in __tty_hangup()
623 tty_kref_put(tty); in __tty_hangup()
625 tty_ldisc_hangup(tty, cons_filp != NULL); in __tty_hangup()
627 spin_lock_irq(&tty->ctrl_lock); in __tty_hangup()
628 clear_bit(TTY_THROTTLED, &tty->flags); in __tty_hangup()
629 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in __tty_hangup()
630 put_pid(tty->session); in __tty_hangup()
631 put_pid(tty->pgrp); in __tty_hangup()
632 tty->session = NULL; in __tty_hangup()
633 tty->pgrp = NULL; in __tty_hangup()
634 tty->ctrl_status = 0; in __tty_hangup()
635 spin_unlock_irq(&tty->ctrl_lock); in __tty_hangup()
644 if (tty->ops->close) in __tty_hangup()
646 tty->ops->close(tty, cons_filp); in __tty_hangup()
647 } else if (tty->ops->hangup) in __tty_hangup()
648 tty->ops->hangup(tty); in __tty_hangup()
654 set_bit(TTY_HUPPED, &tty->flags); in __tty_hangup()
655 clear_bit(TTY_HUPPING, &tty->flags); in __tty_hangup()
656 tty_unlock(tty); in __tty_hangup()
664 struct tty_struct *tty = in do_tty_hangup() local
667 __tty_hangup(tty, 0); in do_tty_hangup()
678 void tty_hangup(struct tty_struct *tty) in tty_hangup() argument
680 tty_debug_hangup(tty, "hangup\n"); in tty_hangup()
681 schedule_work(&tty->hangup_work); in tty_hangup()
695 void tty_vhangup(struct tty_struct *tty) in tty_vhangup() argument
697 tty_debug_hangup(tty, "vhangup\n"); in tty_vhangup()
698 __tty_hangup(tty, 0); in tty_vhangup()
712 struct tty_struct *tty; in tty_vhangup_self() local
714 tty = get_current_tty(); in tty_vhangup_self()
715 if (tty) { in tty_vhangup_self()
716 tty_vhangup(tty); in tty_vhangup_self()
717 tty_kref_put(tty); in tty_vhangup_self()
732 void tty_vhangup_session(struct tty_struct *tty) in tty_vhangup_session() argument
734 tty_debug_hangup(tty, "session hangup\n"); in tty_vhangup_session()
735 __tty_hangup(tty, 1); in tty_vhangup_session()
770 void __stop_tty(struct tty_struct *tty) in __stop_tty() argument
772 if (tty->stopped) in __stop_tty()
774 tty->stopped = 1; in __stop_tty()
775 if (tty->ops->stop) in __stop_tty()
776 tty->ops->stop(tty); in __stop_tty()
779 void stop_tty(struct tty_struct *tty) in stop_tty() argument
783 spin_lock_irqsave(&tty->flow_lock, flags); in stop_tty()
784 __stop_tty(tty); in stop_tty()
785 spin_unlock_irqrestore(&tty->flow_lock, flags); in stop_tty()
801 void __start_tty(struct tty_struct *tty) in __start_tty() argument
803 if (!tty->stopped || tty->flow_stopped) in __start_tty()
805 tty->stopped = 0; in __start_tty()
806 if (tty->ops->start) in __start_tty()
807 tty->ops->start(tty); in __start_tty()
808 tty_wakeup(tty); in __start_tty()
811 void start_tty(struct tty_struct *tty) in start_tty() argument
815 spin_lock_irqsave(&tty->flow_lock, flags); in start_tty()
816 __start_tty(tty); in start_tty()
817 spin_unlock_irqrestore(&tty->flow_lock, flags); in start_tty()
855 struct tty_struct *tty = file_tty(file); in tty_read() local
858 if (tty_paranoia_check(tty, inode, "tty_read")) in tty_read()
860 if (!tty || tty_io_error(tty)) in tty_read()
865 ld = tty_ldisc_ref_wait(tty); in tty_read()
869 i = ld->ops->read(tty, file, buf, count); in tty_read()
880 static void tty_write_unlock(struct tty_struct *tty) in tty_write_unlock() argument
882 mutex_unlock(&tty->atomic_write_lock); in tty_write_unlock()
883 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_write_unlock()
886 static int tty_write_lock(struct tty_struct *tty, int ndelay) in tty_write_lock() argument
888 if (!mutex_trylock(&tty->atomic_write_lock)) { in tty_write_lock()
891 if (mutex_lock_interruptible(&tty->atomic_write_lock)) in tty_write_lock()
903 struct tty_struct *tty, in do_tty_write() argument
911 ret = tty_write_lock(tty, file->f_flags & O_NDELAY); in do_tty_write()
932 if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) in do_tty_write()
938 if (tty->write_cnt < chunk) { in do_tty_write()
949 kfree(tty->write_buf); in do_tty_write()
950 tty->write_cnt = chunk; in do_tty_write()
951 tty->write_buf = buf_chunk; in do_tty_write()
960 if (copy_from_user(tty->write_buf, buf, size)) in do_tty_write()
962 ret = write(tty, file, tty->write_buf, size); in do_tty_write()
980 tty_write_unlock(tty); in do_tty_write()
996 void tty_write_message(struct tty_struct *tty, char *msg) in tty_write_message() argument
998 if (tty) { in tty_write_message()
999 mutex_lock(&tty->atomic_write_lock); in tty_write_message()
1000 tty_lock(tty); in tty_write_message()
1001 if (tty->ops->write && tty->count > 0) in tty_write_message()
1002 tty->ops->write(tty, msg, strlen(msg)); in tty_write_message()
1003 tty_unlock(tty); in tty_write_message()
1004 tty_write_unlock(tty); in tty_write_message()
1029 struct tty_struct *tty = file_tty(file); in tty_write() local
1033 if (tty_paranoia_check(tty, file_inode(file), "tty_write")) in tty_write()
1035 if (!tty || !tty->ops->write || tty_io_error(tty)) in tty_write()
1038 if (tty->ops->write_room == NULL) in tty_write()
1039 tty_err(tty, "missing write_room method\n"); in tty_write()
1040 ld = tty_ldisc_ref_wait(tty); in tty_write()
1046 ret = do_tty_write(ld->ops->write, tty, file, buf, count); in tty_write()
1078 int tty_send_xchar(struct tty_struct *tty, char ch) in tty_send_xchar() argument
1080 int was_stopped = tty->stopped; in tty_send_xchar()
1082 if (tty->ops->send_xchar) { in tty_send_xchar()
1083 down_read(&tty->termios_rwsem); in tty_send_xchar()
1084 tty->ops->send_xchar(tty, ch); in tty_send_xchar()
1085 up_read(&tty->termios_rwsem); in tty_send_xchar()
1089 if (tty_write_lock(tty, 0) < 0) in tty_send_xchar()
1092 down_read(&tty->termios_rwsem); in tty_send_xchar()
1094 start_tty(tty); in tty_send_xchar()
1095 tty->ops->write(tty, &ch, 1); in tty_send_xchar()
1097 stop_tty(tty); in tty_send_xchar()
1098 up_read(&tty->termios_rwsem); in tty_send_xchar()
1099 tty_write_unlock(tty); in tty_send_xchar()
1158 struct tty_struct *tty; in tty_driver_lookup_tty() local
1162 tty = ERR_PTR(-EIO); in tty_driver_lookup_tty()
1164 tty = driver->ops->lookup(driver, file, idx); in tty_driver_lookup_tty()
1166 tty = driver->ttys[idx]; in tty_driver_lookup_tty()
1168 if (!IS_ERR(tty)) in tty_driver_lookup_tty()
1169 tty_kref_get(tty); in tty_driver_lookup_tty()
1170 return tty; in tty_driver_lookup_tty()
1181 void tty_init_termios(struct tty_struct *tty) in tty_init_termios() argument
1184 int idx = tty->index; in tty_init_termios()
1186 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_init_termios()
1187 tty->termios = tty->driver->init_termios; in tty_init_termios()
1190 tp = tty->driver->termios[idx]; in tty_init_termios()
1192 tty->termios = *tp; in tty_init_termios()
1193 tty->termios.c_line = tty->driver->init_termios.c_line; in tty_init_termios()
1195 tty->termios = tty->driver->init_termios; in tty_init_termios()
1198 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); in tty_init_termios()
1199 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); in tty_init_termios()
1203 int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty) in tty_standard_install() argument
1205 tty_init_termios(tty); in tty_standard_install()
1207 tty->count++; in tty_standard_install()
1208 driver->ttys[tty->index] = tty; in tty_standard_install()
1226 struct tty_struct *tty) in tty_driver_install_tty() argument
1228 return driver->ops->install ? driver->ops->install(driver, tty) : in tty_driver_install_tty()
1229 tty_standard_install(driver, tty); in tty_driver_install_tty()
1242 static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty) in tty_driver_remove_tty() argument
1245 driver->ops->remove(driver, tty); in tty_driver_remove_tty()
1247 driver->ttys[tty->index] = NULL; in tty_driver_remove_tty()
1259 static int tty_reopen(struct tty_struct *tty) in tty_reopen() argument
1261 struct tty_driver *driver = tty->driver; in tty_reopen()
1269 if (!tty->count) in tty_reopen()
1272 if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) in tty_reopen()
1275 ld = tty_ldisc_ref_wait(tty); in tty_reopen()
1279 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_reopen()
1283 if (!tty->ldisc) in tty_reopen()
1284 retval = tty_ldisc_reinit(tty, tty->termios.c_line); in tty_reopen()
1285 tty_ldisc_unlock(tty); in tty_reopen()
1289 tty->count++; in tty_reopen()
1321 struct tty_struct *tty; in tty_init_dev() local
1335 tty = alloc_tty_struct(driver, idx); in tty_init_dev()
1336 if (!tty) { in tty_init_dev()
1341 tty_lock(tty); in tty_init_dev()
1342 retval = tty_driver_install_tty(driver, tty); in tty_init_dev()
1346 if (!tty->port) in tty_init_dev()
1347 tty->port = driver->ports[idx]; in tty_init_dev()
1349 if (WARN_RATELIMIT(!tty->port, in tty_init_dev()
1351 __func__, tty->driver->name)) { in tty_init_dev()
1356 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_init_dev()
1359 tty->port->itty = tty; in tty_init_dev()
1366 retval = tty_ldisc_setup(tty, tty->link); in tty_init_dev()
1369 tty_ldisc_unlock(tty); in tty_init_dev()
1371 return tty; in tty_init_dev()
1374 tty_unlock(tty); in tty_init_dev()
1375 free_tty_struct(tty); in tty_init_dev()
1382 tty_ldisc_unlock(tty); in tty_init_dev()
1383 tty_info_ratelimited(tty, "ldisc open failed (%d), clearing slot %d\n", in tty_init_dev()
1386 tty_unlock(tty); in tty_init_dev()
1387 release_tty(tty, idx); in tty_init_dev()
1397 void tty_save_termios(struct tty_struct *tty) in tty_save_termios() argument
1400 int idx = tty->index; in tty_save_termios()
1403 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_save_termios()
1407 tp = tty->driver->termios[idx]; in tty_save_termios()
1412 tty->driver->termios[idx] = tp; in tty_save_termios()
1414 *tp = tty->termios; in tty_save_termios()
1424 static void tty_flush_works(struct tty_struct *tty) in tty_flush_works() argument
1426 flush_work(&tty->SAK_work); in tty_flush_works()
1427 flush_work(&tty->hangup_work); in tty_flush_works()
1428 if (tty->link) { in tty_flush_works()
1429 flush_work(&tty->link->SAK_work); in tty_flush_works()
1430 flush_work(&tty->link->hangup_work); in tty_flush_works()
1451 struct tty_struct *tty = in release_one_tty() local
1453 struct tty_driver *driver = tty->driver; in release_one_tty()
1456 if (tty->ops->cleanup) in release_one_tty()
1457 tty->ops->cleanup(tty); in release_one_tty()
1459 tty->magic = 0; in release_one_tty()
1463 spin_lock(&tty->files_lock); in release_one_tty()
1464 list_del_init(&tty->tty_files); in release_one_tty()
1465 spin_unlock(&tty->files_lock); in release_one_tty()
1467 put_pid(tty->pgrp); in release_one_tty()
1468 put_pid(tty->session); in release_one_tty()
1469 free_tty_struct(tty); in release_one_tty()
1474 struct tty_struct *tty = container_of(kref, struct tty_struct, kref); in queue_release_one_tty() local
1478 INIT_WORK(&tty->hangup_work, release_one_tty); in queue_release_one_tty()
1479 schedule_work(&tty->hangup_work); in queue_release_one_tty()
1490 void tty_kref_put(struct tty_struct *tty) in tty_kref_put() argument
1492 if (tty) in tty_kref_put()
1493 kref_put(&tty->kref, queue_release_one_tty); in tty_kref_put()
1509 static void release_tty(struct tty_struct *tty, int idx) in release_tty() argument
1512 WARN_ON(tty->index != idx); in release_tty()
1514 if (tty->ops->shutdown) in release_tty()
1515 tty->ops->shutdown(tty); in release_tty()
1516 tty_save_termios(tty); in release_tty()
1517 tty_driver_remove_tty(tty->driver, tty); in release_tty()
1518 if (tty->port) in release_tty()
1519 tty->port->itty = NULL; in release_tty()
1520 if (tty->link) in release_tty()
1521 tty->link->port->itty = NULL; in release_tty()
1522 if (tty->port) in release_tty()
1523 tty_buffer_cancel_work(tty->port); in release_tty()
1524 if (tty->link) in release_tty()
1525 tty_buffer_cancel_work(tty->link->port); in release_tty()
1527 tty_kref_put(tty->link); in release_tty()
1528 tty_kref_put(tty); in release_tty()
1539 static int tty_release_checks(struct tty_struct *tty, int idx) in tty_release_checks() argument
1542 if (idx < 0 || idx >= tty->driver->num) { in tty_release_checks()
1543 tty_debug(tty, "bad idx %d\n", idx); in tty_release_checks()
1548 if (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) in tty_release_checks()
1551 if (tty != tty->driver->ttys[idx]) { in tty_release_checks()
1552 tty_debug(tty, "bad driver table[%d] = %p\n", in tty_release_checks()
1553 idx, tty->driver->ttys[idx]); in tty_release_checks()
1556 if (tty->driver->other) { in tty_release_checks()
1557 struct tty_struct *o_tty = tty->link; in tty_release_checks()
1559 if (o_tty != tty->driver->other->ttys[idx]) { in tty_release_checks()
1560 tty_debug(tty, "bad other table[%d] = %p\n", in tty_release_checks()
1561 idx, tty->driver->other->ttys[idx]); in tty_release_checks()
1564 if (o_tty->link != tty) { in tty_release_checks()
1565 tty_debug(tty, "bad link = %p\n", o_tty->link); in tty_release_checks()
1581 void tty_kclose(struct tty_struct *tty) in tty_kclose() argument
1586 tty_ldisc_release(tty); in tty_kclose()
1589 tty_flush_works(tty); in tty_kclose()
1591 tty_debug_hangup(tty, "freeing structure\n"); in tty_kclose()
1597 tty_port_set_kopened(tty->port, 0); in tty_kclose()
1598 release_tty(tty, tty->index); in tty_kclose()
1611 void tty_release_struct(struct tty_struct *tty, int idx) in tty_release_struct() argument
1616 tty_ldisc_release(tty); in tty_release_struct()
1619 tty_flush_works(tty); in tty_release_struct()
1621 tty_debug_hangup(tty, "freeing structure\n"); in tty_release_struct()
1627 release_tty(tty, idx); in tty_release_struct()
1653 struct tty_struct *tty = file_tty(filp); in tty_release() local
1660 if (tty_paranoia_check(tty, inode, __func__)) in tty_release()
1663 tty_lock(tty); in tty_release()
1664 check_tty_count(tty, __func__); in tty_release()
1668 idx = tty->index; in tty_release()
1669 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_release()
1670 tty->driver->subtype == PTY_TYPE_MASTER) in tty_release()
1671 o_tty = tty->link; in tty_release()
1673 if (tty_release_checks(tty, idx)) { in tty_release()
1674 tty_unlock(tty); in tty_release()
1678 tty_debug_hangup(tty, "releasing (count=%d)\n", tty->count); in tty_release()
1680 if (tty->ops->close) in tty_release()
1681 tty->ops->close(tty, filp); in tty_release()
1702 if (tty->count <= 1) { in tty_release()
1703 if (waitqueue_active(&tty->read_wait)) { in tty_release()
1704 wake_up_poll(&tty->read_wait, EPOLLIN); in tty_release()
1707 if (waitqueue_active(&tty->write_wait)) { in tty_release()
1708 wake_up_poll(&tty->write_wait, EPOLLOUT); in tty_release()
1727 tty_warn(tty, "read/write wait queue active!\n"); in tty_release()
1738 tty_warn(tty, "bad slave count (%d)\n", o_tty->count); in tty_release()
1742 if (--tty->count < 0) { in tty_release()
1743 tty_warn(tty, "bad tty->count (%d)\n", tty->count); in tty_release()
1744 tty->count = 0; in tty_release()
1765 if (!tty->count) { in tty_release()
1767 session_clear_tty(tty->session); in tty_release()
1774 final = !tty->count && !(o_tty && o_tty->count); in tty_release()
1777 tty_unlock(tty); in tty_release()
1785 tty_debug_hangup(tty, "final close\n"); in tty_release()
1787 tty_release_struct(tty, idx); in tty_release()
1804 struct tty_struct *tty; in tty_open_current_tty() local
1810 tty = get_current_tty(); in tty_open_current_tty()
1811 if (!tty) in tty_open_current_tty()
1816 tty_lock(tty); in tty_open_current_tty()
1817 tty_kref_put(tty); /* safe to drop the kref now */ in tty_open_current_tty()
1819 retval = tty_reopen(tty); in tty_open_current_tty()
1821 tty_unlock(tty); in tty_open_current_tty()
1822 tty = ERR_PTR(retval); in tty_open_current_tty()
1824 return tty; in tty_open_current_tty()
1893 struct tty_struct *tty; in tty_kopen() local
1905 tty = tty_driver_lookup_tty(driver, NULL, index); in tty_kopen()
1906 if (IS_ERR(tty)) in tty_kopen()
1909 if (tty) { in tty_kopen()
1911 tty_kref_put(tty); in tty_kopen()
1912 tty = ERR_PTR(-EBUSY); in tty_kopen()
1914 tty = tty_init_dev(driver, index); in tty_kopen()
1915 if (IS_ERR(tty)) in tty_kopen()
1917 tty_port_set_kopened(tty->port, 1); in tty_kopen()
1922 return tty; in tty_kopen()
1944 struct tty_struct *tty; in tty_open_by_driver() local
1957 tty = tty_driver_lookup_tty(driver, filp, index); in tty_open_by_driver()
1958 if (IS_ERR(tty)) { in tty_open_by_driver()
1963 if (tty) { in tty_open_by_driver()
1964 if (tty_port_kopened(tty->port)) { in tty_open_by_driver()
1965 tty_kref_put(tty); in tty_open_by_driver()
1967 tty = ERR_PTR(-EBUSY); in tty_open_by_driver()
1971 retval = tty_lock_interruptible(tty); in tty_open_by_driver()
1972 tty_kref_put(tty); /* drop kref from tty_driver_lookup_tty() */ in tty_open_by_driver()
1976 tty = ERR_PTR(retval); in tty_open_by_driver()
1979 retval = tty_reopen(tty); in tty_open_by_driver()
1981 tty_unlock(tty); in tty_open_by_driver()
1982 tty = ERR_PTR(retval); in tty_open_by_driver()
1985 tty = tty_init_dev(driver, index); in tty_open_by_driver()
1990 return tty; in tty_open_by_driver()
2019 struct tty_struct *tty; in tty_open() local
2031 tty = tty_open_current_tty(device, filp); in tty_open()
2032 if (!tty) in tty_open()
2033 tty = tty_open_by_driver(device, filp); in tty_open()
2035 if (IS_ERR(tty)) { in tty_open()
2037 retval = PTR_ERR(tty); in tty_open()
2044 tty_add_file(tty, filp); in tty_open()
2046 check_tty_count(tty, __func__); in tty_open()
2047 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in tty_open()
2049 if (tty->ops->open) in tty_open()
2050 retval = tty->ops->open(tty, filp); in tty_open()
2056 tty_debug_hangup(tty, "open error %d, releasing\n", retval); in tty_open()
2058 tty_unlock(tty); /* need to call tty_release without BTM */ in tty_open()
2074 clear_bit(TTY_HUPPED, &tty->flags); in tty_open()
2079 (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_open()
2080 tty->driver->subtype == PTY_TYPE_MASTER); in tty_open()
2082 tty_open_proc_set_tty(filp, tty); in tty_open()
2083 tty_unlock(tty); in tty_open()
2103 struct tty_struct *tty = file_tty(filp); in tty_poll() local
2107 if (tty_paranoia_check(tty, file_inode(filp), "tty_poll")) in tty_poll()
2110 ld = tty_ldisc_ref_wait(tty); in tty_poll()
2114 ret = ld->ops->poll(tty, filp, wait); in tty_poll()
2121 struct tty_struct *tty = file_tty(filp); in __tty_fasync() local
2125 if (tty_paranoia_check(tty, file_inode(filp), "tty_fasync")) in __tty_fasync()
2128 retval = fasync_helper(fd, filp, on, &tty->fasync); in __tty_fasync()
2136 spin_lock_irqsave(&tty->ctrl_lock, flags); in __tty_fasync()
2137 if (tty->pgrp) { in __tty_fasync()
2138 pid = tty->pgrp; in __tty_fasync()
2145 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __tty_fasync()
2156 struct tty_struct *tty = file_tty(filp); in tty_fasync() local
2159 tty_lock(tty); in tty_fasync()
2162 tty_unlock(tty); in tty_fasync()
2184 static int tiocsti(struct tty_struct *tty, char __user *p) in tiocsti() argument
2189 if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) in tiocsti()
2193 tty_audit_tiocsti(tty, ch); in tiocsti()
2194 ld = tty_ldisc_ref_wait(tty); in tiocsti()
2198 ld->ops->receive_buf(tty, &ch, &mbz, 1); in tiocsti()
2214 static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocgwinsz() argument
2218 mutex_lock(&tty->winsize_mutex); in tiocgwinsz()
2219 err = copy_to_user(arg, &tty->winsize, sizeof(*arg)); in tiocgwinsz()
2220 mutex_unlock(&tty->winsize_mutex); in tiocgwinsz()
2234 int tty_do_resize(struct tty_struct *tty, struct winsize *ws) in tty_do_resize() argument
2239 mutex_lock(&tty->winsize_mutex); in tty_do_resize()
2240 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in tty_do_resize()
2244 pgrp = tty_get_pgrp(tty); in tty_do_resize()
2249 tty->winsize = *ws; in tty_do_resize()
2251 mutex_unlock(&tty->winsize_mutex); in tty_do_resize()
2271 static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg) in tiocswinsz() argument
2277 if (tty->ops->resize) in tiocswinsz()
2278 return tty->ops->resize(tty, &tmp_ws); in tiocswinsz()
2280 return tty_do_resize(tty, &tmp_ws); in tiocswinsz()
2326 static int tiocsetd(struct tty_struct *tty, int __user *p) in tiocsetd() argument
2334 ret = tty_set_ldisc(tty, disc); in tiocsetd()
2350 static int tiocgetd(struct tty_struct *tty, int __user *p) in tiocgetd() argument
2355 ld = tty_ldisc_ref_wait(tty); in tiocgetd()
2376 static int send_break(struct tty_struct *tty, unsigned int duration) in send_break() argument
2380 if (tty->ops->break_ctl == NULL) in send_break()
2383 if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK) in send_break()
2384 retval = tty->ops->break_ctl(tty, duration); in send_break()
2387 if (tty_write_lock(tty, 0) < 0) in send_break()
2389 retval = tty->ops->break_ctl(tty, -1); in send_break()
2394 retval = tty->ops->break_ctl(tty, 0); in send_break()
2396 tty_write_unlock(tty); in send_break()
2414 static int tty_tiocmget(struct tty_struct *tty, int __user *p) in tty_tiocmget() argument
2418 if (tty->ops->tiocmget) { in tty_tiocmget()
2419 retval = tty->ops->tiocmget(tty); in tty_tiocmget()
2439 static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd, in tty_tiocmset() argument
2445 if (tty->ops->tiocmset == NULL) in tty_tiocmset()
2466 return tty->ops->tiocmset(tty, set, clear); in tty_tiocmset()
2469 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) in tty_tiocgicount() argument
2474 if (tty->ops->get_icount) in tty_tiocgicount()
2475 retval = tty->ops->get_icount(tty, &icount); in tty_tiocgicount()
2483 static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocsserial() argument
2500 if (!tty->ops->set_serial) in tty_tiocsserial()
2502 return tty->ops->set_serial(tty, &v); in tty_tiocsserial()
2505 static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss) in tty_tiocgserial() argument
2511 if (!tty->ops->get_serial) in tty_tiocgserial()
2513 err = tty->ops->get_serial(tty, &v); in tty_tiocgserial()
2523 static struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) in tty_pair_get_tty() argument
2525 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_pair_get_tty()
2526 tty->driver->subtype == PTY_TYPE_MASTER) in tty_pair_get_tty()
2527 tty = tty->link; in tty_pair_get_tty()
2528 return tty; in tty_pair_get_tty()
2536 struct tty_struct *tty = file_tty(file); in tty_ioctl() local
2542 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_ioctl()
2545 real_tty = tty_pair_get_tty(tty); in tty_ioctl()
2556 retval = tty_check_change(tty); in tty_ioctl()
2560 tty_wait_until_sent(tty, 0); in tty_ioctl()
2572 return tiocsti(tty, p); in tty_ioctl()
2578 return real_tty != tty ? -EINVAL : tioccons(file); in tty_ioctl()
2580 set_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2583 clear_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2587 int excl = test_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2591 return tiocgetd(tty, p); in tty_ioctl()
2593 return tiocsetd(tty, p); in tty_ioctl()
2597 tty_vhangup(tty); in tty_ioctl()
2608 if (tty->ops->break_ctl) in tty_ioctl()
2609 return tty->ops->break_ctl(tty, -1); in tty_ioctl()
2612 if (tty->ops->break_ctl) in tty_ioctl()
2613 return tty->ops->break_ctl(tty, 0); in tty_ioctl()
2621 return send_break(tty, 250); in tty_ioctl()
2624 return send_break(tty, arg ? arg*100 : 250); in tty_ioctl()
2627 return tty_tiocmget(tty, p); in tty_ioctl()
2631 return tty_tiocmset(tty, cmd, p); in tty_ioctl()
2633 return tty_tiocgicount(tty, p); in tty_ioctl()
2639 tty_buffer_flush(tty, NULL); in tty_ioctl()
2644 return tty_tiocsserial(tty, p); in tty_ioctl()
2646 return tty_tiocgserial(tty, p); in tty_ioctl()
2649 return ptm_open_peer(file, tty, (int)arg); in tty_ioctl()
2651 retval = tty_jobctrl_ioctl(tty, real_tty, file, cmd, arg); in tty_ioctl()
2655 if (tty->ops->ioctl) { in tty_ioctl()
2656 retval = tty->ops->ioctl(tty, cmd, arg); in tty_ioctl()
2660 ld = tty_ldisc_ref_wait(tty); in tty_ioctl()
2665 retval = ld->ops->ioctl(tty, file, cmd, arg); in tty_ioctl()
2697 static int compat_tty_tiocsserial(struct tty_struct *tty, in compat_tty_tiocsserial() argument
2722 if (!tty->ops->set_serial) in compat_tty_tiocsserial()
2724 return tty->ops->set_serial(tty, &v); in compat_tty_tiocsserial()
2727 static int compat_tty_tiocgserial(struct tty_struct *tty, in compat_tty_tiocgserial() argument
2737 if (!tty->ops->get_serial) in compat_tty_tiocgserial()
2739 err = tty->ops->get_serial(tty, &v); in compat_tty_tiocgserial()
2754 struct tty_struct *tty = file_tty(file); in tty_compat_ioctl() local
2837 if (tty_paranoia_check(tty, file_inode(file), "tty_ioctl")) in tty_compat_ioctl()
2842 return compat_tty_tiocsserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2844 return compat_tty_tiocgserial(tty, compat_ptr(arg)); in tty_compat_ioctl()
2846 if (tty->ops->compat_ioctl) { in tty_compat_ioctl()
2847 retval = tty->ops->compat_ioctl(tty, cmd, arg); in tty_compat_ioctl()
2852 ld = tty_ldisc_ref_wait(tty); in tty_compat_ioctl()
2856 retval = ld->ops->compat_ioctl(tty, file, cmd, arg); in tty_compat_ioctl()
2858 retval = ld->ops->ioctl(tty, file, in tty_compat_ioctl()
2892 void __do_SAK(struct tty_struct *tty) in __do_SAK() argument
2895 tty_hangup(tty); in __do_SAK()
2902 if (!tty) in __do_SAK()
2905 spin_lock_irqsave(&tty->ctrl_lock, flags); in __do_SAK()
2906 session = get_pid(tty->session); in __do_SAK()
2907 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in __do_SAK()
2909 tty_ldisc_flush(tty); in __do_SAK()
2911 tty_driver_flush_buffer(tty); in __do_SAK()
2916 tty_notice(tty, "SAK: killed process %d (%s): by session\n", in __do_SAK()
2923 if (p->signal->tty == tty) { in __do_SAK()
2924 tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", in __do_SAK()
2930 i = iterate_fd(p->files, 0, this_tty, tty); in __do_SAK()
2932 tty_notice(tty, "SAK: killed process %d (%s): by fd#%d\n", in __do_SAK()
2945 struct tty_struct *tty = in do_SAK_work() local
2947 __do_SAK(tty); in do_SAK_work()
2956 void do_SAK(struct tty_struct *tty) in do_SAK() argument
2958 if (!tty) in do_SAK()
2960 schedule_work(&tty->SAK_work); in do_SAK()
2966 static struct device *tty_get_device(struct tty_struct *tty) in tty_get_device() argument
2968 dev_t devt = tty_devnum(tty); in tty_get_device()
2983 struct tty_struct *tty; in alloc_tty_struct() local
2985 tty = kzalloc(sizeof(*tty), GFP_KERNEL); in alloc_tty_struct()
2986 if (!tty) in alloc_tty_struct()
2989 kref_init(&tty->kref); in alloc_tty_struct()
2990 tty->magic = TTY_MAGIC; in alloc_tty_struct()
2991 if (tty_ldisc_init(tty)) { in alloc_tty_struct()
2992 kfree(tty); in alloc_tty_struct()
2995 tty->session = NULL; in alloc_tty_struct()
2996 tty->pgrp = NULL; in alloc_tty_struct()
2997 mutex_init(&tty->legacy_mutex); in alloc_tty_struct()
2998 mutex_init(&tty->throttle_mutex); in alloc_tty_struct()
2999 init_rwsem(&tty->termios_rwsem); in alloc_tty_struct()
3000 mutex_init(&tty->winsize_mutex); in alloc_tty_struct()
3001 init_ldsem(&tty->ldisc_sem); in alloc_tty_struct()
3002 init_waitqueue_head(&tty->write_wait); in alloc_tty_struct()
3003 init_waitqueue_head(&tty->read_wait); in alloc_tty_struct()
3004 INIT_WORK(&tty->hangup_work, do_tty_hangup); in alloc_tty_struct()
3005 mutex_init(&tty->atomic_write_lock); in alloc_tty_struct()
3006 spin_lock_init(&tty->ctrl_lock); in alloc_tty_struct()
3007 spin_lock_init(&tty->flow_lock); in alloc_tty_struct()
3008 spin_lock_init(&tty->files_lock); in alloc_tty_struct()
3009 INIT_LIST_HEAD(&tty->tty_files); in alloc_tty_struct()
3010 INIT_WORK(&tty->SAK_work, do_SAK_work); in alloc_tty_struct()
3012 tty->driver = driver; in alloc_tty_struct()
3013 tty->ops = driver->ops; in alloc_tty_struct()
3014 tty->index = idx; in alloc_tty_struct()
3015 tty_line_name(driver, idx, tty->name); in alloc_tty_struct()
3016 tty->dev = tty_get_device(tty); in alloc_tty_struct()
3018 return tty; in alloc_tty_struct()
3033 int tty_put_char(struct tty_struct *tty, unsigned char ch) in tty_put_char() argument
3035 if (tty->ops->put_char) in tty_put_char()
3036 return tty->ops->put_char(tty, ch); in tty_put_char()
3037 return tty->ops->write(tty, &ch, 1); in tty_put_char()
3399 dev_t tty_devnum(struct tty_struct *tty) in tty_devnum() argument
3401 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; in tty_devnum()