From: Christoph Hellwig - 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: Andrew Morton --- 25-akpm/drivers/char/Makefile | 5 + 25-akpm/drivers/char/pty.c | 162 ++++++++++++++++++------------------------ 2 files changed, 74 insertions(+), 93 deletions(-) diff -puN drivers/char/Makefile~reduce-ptyc-ifdef-clutter drivers/char/Makefile --- 25/drivers/char/Makefile~reduce-ptyc-ifdef-clutter 2004-08-15 15:43:34.394084944 -0700 +++ 25-akpm/drivers/char/Makefile 2004-08-15 15:43:34.399084184 -0700 @@ -7,8 +7,11 @@ # 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 \ consolemap_deftbl.o selection.o keyboard.o obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o diff -puN drivers/char/pty.c~reduce-ptyc-ifdef-clutter drivers/char/pty.c --- 25/drivers/char/pty.c~reduce-ptyc-ifdef-clutter 2004-08-15 15:43:34.396084640 -0700 +++ 25-akpm/drivers/char/pty.c 2004-08-15 15:43:34.400084032 -0700 @@ -32,12 +32,6 @@ #include #include -#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 */ #ifdef CONFIG_UNIX98_PTYS struct tty_driver *ptm_driver; @@ -208,19 +202,6 @@ static int pty_chars_in_buffer(struct tt 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 */ static int pty_set_lock(struct tty_struct *tty, int __user * arg) { @@ -234,41 +215,6 @@ static int pty_set_lock(struct tty_struc 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) { struct tty_struct *to = tty->link; @@ -325,42 +271,22 @@ static struct tty_operations pty_ops = { .set_termios = pty_set_termios, }; -/* 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. */ -#ifdef CONFIG_UNIX98_PTYS -int pty_limit = NR_UNIX98_PTY_DEFAULT; -static int pty_limit_min = 0; -static int pty_limit_max = NR_UNIX98_PTY_MAX; +/* Traditional BSD devices */ +#ifdef CONFIG_LEGACY_PTYS +static struct tty_driver *pty_driver, *pty_slave_driver; -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_bsd_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); } -}; -#endif - -/* Initialization */ + return -ENOIOCTLCMD; +} -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); if (!pty_driver) @@ -407,11 +333,58 @@ static int __init pty_init(void) panic("Couldn't register pty driver"); if (tty_register_driver(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 - /* 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"); ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX); if (!ptm_driver) @@ -458,10 +431,15 @@ static int __init pty_init(void) panic("Couldn't register Unix98 pts driver"); 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; } module_init(pty_init); - -#endif /* CONFIG_LEGACY_PTYS || CONFIG_UNIX98_PTYS */ _