Commit daf178a7 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] reduce pty.c ifdef clutter

- build only if either CONFIG_LEGACY_PTYS or CONFIG_UNIX98_PTYS are set
  instead of testing in the file

- try to keep big CONFIG_LEGACY_PTYS and CONFIG_UNIX98_PTYS ifdef blocks
  at the end of the file instead of cluttering all over
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a64a3bab
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
# #
FONTMAPFILE = cp437.uni FONTMAPFILE = cp437.uni
obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o pty.o misc.o obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o
obj-$(CONFIG_LEGACY_PTYS) += pty.o
obj-$(CONFIG_UNIX98_PTYS) += pty.o
obj-y += misc.o
obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o \ obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o consolemap.o \
consolemap_deftbl.o selection.o keyboard.o consolemap_deftbl.o selection.o keyboard.o
obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
......
...@@ -32,12 +32,6 @@ ...@@ -32,12 +32,6 @@
#include <asm/bitops.h> #include <asm/bitops.h>
#include <linux/devpts_fs.h> #include <linux/devpts_fs.h>
#if defined(CONFIG_LEGACY_PTYS) || defined(CONFIG_UNIX98_PTYS)
#ifdef CONFIG_LEGACY_PTYS
static struct tty_driver *pty_driver, *pty_slave_driver;
#endif
/* These are global because they are accessed in tty_io.c */ /* These are global because they are accessed in tty_io.c */
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
struct tty_driver *ptm_driver; struct tty_driver *ptm_driver;
...@@ -205,19 +199,6 @@ static int pty_chars_in_buffer(struct tty_struct *tty) ...@@ -205,19 +199,6 @@ static int pty_chars_in_buffer(struct tty_struct *tty)
return ((count < N_TTY_BUF_SIZE/2) ? 0 : count); return ((count < N_TTY_BUF_SIZE/2) ? 0 : count);
} }
/*
* Return the device number of a Unix98 PTY (only!). This lets us open a
* master pty with the multi-headed ptmx device, then find out which
* one we got after it is open, with an ioctl.
*/
#ifdef CONFIG_UNIX98_PTYS
static int pty_get_device_number(struct tty_struct *tty, unsigned __user *value)
{
unsigned int result = tty->index;
return put_user(result, value);
}
#endif
/* Set the lock flag on a pty */ /* Set the lock flag on a pty */
static int pty_set_lock(struct tty_struct *tty, int __user * arg) static int pty_set_lock(struct tty_struct *tty, int __user * arg)
{ {
...@@ -231,41 +212,6 @@ static int pty_set_lock(struct tty_struct *tty, int __user * arg) ...@@ -231,41 +212,6 @@ static int pty_set_lock(struct tty_struct *tty, int __user * arg)
return 0; return 0;
} }
#ifdef CONFIG_LEGACY_PTYS
static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
if (!tty) {
printk("pty_ioctl called with NULL tty!\n");
return -EIO;
}
switch(cmd) {
case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
return pty_set_lock(tty, (int __user *) arg);
}
return -ENOIOCTLCMD;
}
#endif
#ifdef CONFIG_UNIX98_PTYS
static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
if (!tty) {
printk("pty_unix98_ioctl called with NULL tty!\n");
return -EIO;
}
switch(cmd) {
case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
return pty_set_lock(tty, (int __user *)arg);
case TIOCGPTN: /* Get PT Number */
return pty_get_device_number(tty, (unsigned int __user *)arg);
}
return -ENOIOCTLCMD;
}
#endif
static void pty_flush_buffer(struct tty_struct *tty) static void pty_flush_buffer(struct tty_struct *tty)
{ {
struct tty_struct *to = tty->link; struct tty_struct *to = tty->link;
...@@ -322,42 +268,22 @@ static struct tty_operations pty_ops = { ...@@ -322,42 +268,22 @@ static struct tty_operations pty_ops = {
.set_termios = pty_set_termios, .set_termios = pty_set_termios,
}; };
/* sysctl support for setting limits on the number of Unix98 ptys allocated. /* Traditional BSD devices */
Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly. */ #ifdef CONFIG_LEGACY_PTYS
#ifdef CONFIG_UNIX98_PTYS static struct tty_driver *pty_driver, *pty_slave_driver;
int pty_limit = NR_UNIX98_PTY_DEFAULT;
static int pty_limit_min = 0;
static int pty_limit_max = NR_UNIX98_PTY_MAX;
ctl_table pty_table[] = { static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
{ unsigned int cmd, unsigned long arg)
.ctl_name = PTY_MAX, {
.procname = "max", switch (cmd) {
.maxlen = sizeof(int), case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
.mode = 0644, return pty_set_lock(tty, (int __user *) arg);
.data = &pty_limit,
.proc_handler = &proc_dointvec_minmax,
.strategy = &sysctl_intvec,
.extra1 = &pty_limit_min,
.extra2 = &pty_limit_max,
}, {
.ctl_name = PTY_NR,
.procname = "nr",
.maxlen = sizeof(int),
.mode = 0444,
.proc_handler = &proc_dointvec,
}, {
.ctl_name = 0
} }
}; return -ENOIOCTLCMD;
#endif }
/* Initialization */
static int __init pty_init(void) static void __init legacy_pty_init(void)
{ {
#ifdef CONFIG_LEGACY_PTYS
/* Traditional BSD devices */
pty_driver = alloc_tty_driver(NR_PTYS); pty_driver = alloc_tty_driver(NR_PTYS);
if (!pty_driver) if (!pty_driver)
...@@ -404,11 +330,58 @@ static int __init pty_init(void) ...@@ -404,11 +330,58 @@ static int __init pty_init(void)
panic("Couldn't register pty driver"); panic("Couldn't register pty driver");
if (tty_register_driver(pty_slave_driver)) if (tty_register_driver(pty_slave_driver))
panic("Couldn't register pty slave driver"); panic("Couldn't register pty slave driver");
}
#else
static inline void legacy_pty_init(void) { }
#endif
#endif /* CONFIG_LEGACY_PTYS */ /* Unix98 devices */
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
/* Unix98 devices */ /*
* sysctl support for setting limits on the number of Unix98 ptys allocated.
* Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
*/
int pty_limit = NR_UNIX98_PTY_DEFAULT;
static int pty_limit_min = 0;
static int pty_limit_max = NR_UNIX98_PTY_MAX;
ctl_table pty_table[] = {
{
.ctl_name = PTY_MAX,
.procname = "max",
.maxlen = sizeof(int),
.mode = 0644,
.data = &pty_limit,
.proc_handler = &proc_dointvec_minmax,
.strategy = &sysctl_intvec,
.extra1 = &pty_limit_min,
.extra2 = &pty_limit_max,
}, {
.ctl_name = PTY_NR,
.procname = "nr",
.maxlen = sizeof(int),
.mode = 0444,
.proc_handler = &proc_dointvec,
}, {
.ctl_name = 0
}
};
static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
return pty_set_lock(tty, (int __user *)arg);
case TIOCGPTN: /* Get PT Number */
return put_user(tty->index, (unsigned int __user *)arg);
}
return -ENOIOCTLCMD;
}
static void __init unix98_pty_init(void)
{
devfs_mk_dir("pts"); devfs_mk_dir("pts");
ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX); ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
if (!ptm_driver) if (!ptm_driver)
...@@ -455,10 +428,15 @@ static int __init pty_init(void) ...@@ -455,10 +428,15 @@ static int __init pty_init(void)
panic("Couldn't register Unix98 pts driver"); panic("Couldn't register Unix98 pts driver");
pty_table[1].data = &ptm_driver->refcount; pty_table[1].data = &ptm_driver->refcount;
#endif /* CONFIG_UNIX98_PTYS */ }
#else
static inline void unix98_pty_init(void) { }
#endif
static int __init pty_init(void)
{
legacy_pty_init();
unix98_pty_init();
return 0; return 0;
} }
module_init(pty_init); module_init(pty_init);
#endif /* CONFIG_LEGACY_PTYS || CONFIG_UNIX98_PTYS */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment