aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/pty.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/pty.c')
-rw-r--r--drivers/tty/pty.c68
1 files changed, 5 insertions, 63 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index d8653ab6f498..39afd045f8ef 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -21,7 +21,6 @@
21#include <linux/major.h> 21#include <linux/major.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/sysctl.h>
25#include <linux/device.h> 24#include <linux/device.h>
26#include <linux/uaccess.h> 25#include <linux/uaccess.h>
27#include <linux/bitops.h> 26#include <linux/bitops.h>
@@ -55,11 +54,8 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
55 wake_up_interruptible(&tty->link->write_wait); 54 wake_up_interruptible(&tty->link->write_wait);
56 if (tty->driver->subtype == PTY_TYPE_MASTER) { 55 if (tty->driver->subtype == PTY_TYPE_MASTER) {
57 set_bit(TTY_OTHER_CLOSED, &tty->flags); 56 set_bit(TTY_OTHER_CLOSED, &tty->flags);
58#ifdef CONFIG_UNIX98_PTYS
59 if (tty->driver == ptm_driver)
60 devpts_pty_kill(tty->link);
61#endif
62 tty_unlock(); 57 tty_unlock();
58 devpts_pty_kill(tty->link);
63 tty_vhangup(tty->link); 59 tty_vhangup(tty->link);
64 tty_lock(); 60 tty_lock();
65 } 61 }
@@ -439,55 +435,9 @@ static inline void legacy_pty_init(void) { }
439 435
440/* Unix98 devices */ 436/* Unix98 devices */
441#ifdef CONFIG_UNIX98_PTYS 437#ifdef CONFIG_UNIX98_PTYS
442/*
443 * sysctl support for setting limits on the number of Unix98 ptys allocated.
444 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
445 */
446int pty_limit = NR_UNIX98_PTY_DEFAULT;
447static int pty_limit_min;
448static int pty_limit_max = NR_UNIX98_PTY_MAX;
449static int pty_count;
450 438
451static struct cdev ptmx_cdev; 439static struct cdev ptmx_cdev;
452 440
453static struct ctl_table pty_table[] = {
454 {
455 .procname = "max",
456 .maxlen = sizeof(int),
457 .mode = 0644,
458 .data = &pty_limit,
459 .proc_handler = proc_dointvec_minmax,
460 .extra1 = &pty_limit_min,
461 .extra2 = &pty_limit_max,
462 }, {
463 .procname = "nr",
464 .maxlen = sizeof(int),
465 .mode = 0444,
466 .data = &pty_count,
467 .proc_handler = proc_dointvec,
468 },
469 {}
470};
471
472static struct ctl_table pty_kern_table[] = {
473 {
474 .procname = "pty",
475 .mode = 0555,
476 .child = pty_table,
477 },
478 {}
479};
480
481static struct ctl_table pty_root_table[] = {
482 {
483 .procname = "kernel",
484 .mode = 0555,
485 .child = pty_kern_table,
486 },
487 {}
488};
489
490
491static int pty_unix98_ioctl(struct tty_struct *tty, 441static int pty_unix98_ioctl(struct tty_struct *tty,
492 unsigned int cmd, unsigned long arg) 442 unsigned int cmd, unsigned long arg)
493{ 443{
@@ -515,10 +465,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
515static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, 465static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
516 struct inode *ptm_inode, int idx) 466 struct inode *ptm_inode, int idx)
517{ 467{
518 struct tty_struct *tty = devpts_get_tty(ptm_inode, idx); 468 /* Master must be open via /dev/ptmx */
519 if (tty) 469 return ERR_PTR(-EIO);
520 tty = tty->link;
521 return tty;
522} 470}
523 471
524/** 472/**
@@ -589,7 +537,6 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
589 */ 537 */
590 tty_driver_kref_get(driver); 538 tty_driver_kref_get(driver);
591 tty->count++; 539 tty->count++;
592 pty_count++;
593 return 0; 540 return 0;
594err_free_mem: 541err_free_mem:
595 deinitialize_tty_struct(o_tty); 542 deinitialize_tty_struct(o_tty);
@@ -603,7 +550,6 @@ err_free_tty:
603 550
604static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) 551static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
605{ 552{
606 pty_count--;
607} 553}
608 554
609static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) 555static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
@@ -667,9 +613,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
667 return retval; 613 return retval;
668 614
669 /* find a device that is not in use. */ 615 /* find a device that is not in use. */
670 tty_lock();
671 index = devpts_new_index(inode); 616 index = devpts_new_index(inode);
672 tty_unlock();
673 if (index < 0) { 617 if (index < 0) {
674 retval = index; 618 retval = index;
675 goto err_file; 619 goto err_file;
@@ -677,7 +621,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
677 621
678 mutex_lock(&tty_mutex); 622 mutex_lock(&tty_mutex);
679 tty_lock(); 623 tty_lock();
680 tty = tty_init_dev(ptm_driver, index, 1); 624 tty = tty_init_dev(ptm_driver, index);
681 mutex_unlock(&tty_mutex); 625 mutex_unlock(&tty_mutex);
682 626
683 if (IS_ERR(tty)) { 627 if (IS_ERR(tty)) {
@@ -704,8 +648,8 @@ err_release:
704 tty_release(inode, filp); 648 tty_release(inode, filp);
705 return retval; 649 return retval;
706out: 650out:
707 devpts_kill_index(inode, index);
708 tty_unlock(); 651 tty_unlock();
652 devpts_kill_index(inode, index);
709err_file: 653err_file:
710 tty_free_file(filp); 654 tty_free_file(filp);
711 return retval; 655 return retval;
@@ -762,8 +706,6 @@ static void __init unix98_pty_init(void)
762 if (tty_register_driver(pts_driver)) 706 if (tty_register_driver(pts_driver))
763 panic("Couldn't register Unix98 pts driver"); 707 panic("Couldn't register Unix98 pts driver");
764 708
765 register_sysctl_table(pty_root_table);
766
767 /* Now create the /dev/ptmx special device */ 709 /* Now create the /dev/ptmx special device */
768 tty_default_fops(&ptmx_fops); 710 tty_default_fops(&ptmx_fops);
769 ptmx_fops.open = ptmx_open; 711 ptmx_fops.open = ptmx_open;