Skip to content

Commit

Permalink
pty: reconnect the BSD TIOCSPTLCK handling to legacy ptys
Browse files Browse the repository at this point in the history
David Howells noticed (due to the compiler warning about an unused
'pty_ops_bsd' variable) that we haven't actually been using the code
that implements TIOCSPTLCK for legacy pty handling.  It's been that way
since 2.6.26, commit 3e8e88c to be
exact ("pty: prepare for tty->ops changes").

DavidH initially submitted a patch just removing the dead code entirely,
and since nobody has apparently ever complained, I'm not entirely sure
that wouldn't be the right thing to do.  But since the whole and only
point of the legacy pty code is to be compatible with legacy distros
that don't use the new unix98 pty model, let's just wire it up again.

And clean it up a bit while we're at it.

Acked-by: David Howells <dhowells@redhat.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Sep 30, 2009
1 parent e207e14 commit 342a597
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions drivers/char/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ int pty_resize(struct tty_struct *tty, struct winsize *ws)
return 0;
}

/* Traditional BSD devices */
#ifdef CONFIG_LEGACY_PTYS

static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
{
struct tty_struct *o_tty;
Expand Down Expand Up @@ -310,24 +313,6 @@ static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
return -ENOMEM;
}


static const struct tty_operations pty_ops = {
.install = pty_install,
.open = pty_open,
.close = pty_close,
.write = pty_write,
.write_room = pty_write_room,
.flush_buffer = pty_flush_buffer,
.chars_in_buffer = pty_chars_in_buffer,
.unthrottle = pty_unthrottle,
.set_termios = pty_set_termios,
.resize = pty_resize
};

/* Traditional BSD devices */
#ifdef CONFIG_LEGACY_PTYS
static struct tty_driver *pty_driver, *pty_slave_driver;

static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
Expand All @@ -341,7 +326,12 @@ static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
static int legacy_count = CONFIG_LEGACY_PTY_COUNT;
module_param(legacy_count, int, 0);

static const struct tty_operations pty_ops_bsd = {
/*
* The master side of a pty can do TIOCSPTLCK and thus
* has pty_bsd_ioctl.
*/
static const struct tty_operations master_pty_ops_bsd = {
.install = pty_install,
.open = pty_open,
.close = pty_close,
.write = pty_write,
Expand All @@ -354,8 +344,23 @@ static const struct tty_operations pty_ops_bsd = {
.resize = pty_resize
};

static const struct tty_operations slave_pty_ops_bsd = {
.install = pty_install,
.open = pty_open,
.close = pty_close,
.write = pty_write,
.write_room = pty_write_room,
.flush_buffer = pty_flush_buffer,
.chars_in_buffer = pty_chars_in_buffer,
.unthrottle = pty_unthrottle,
.set_termios = pty_set_termios,
.resize = pty_resize
};

static void __init legacy_pty_init(void)
{
struct tty_driver *pty_driver, *pty_slave_driver;

if (legacy_count <= 0)
return;

Expand Down Expand Up @@ -383,7 +388,7 @@ static void __init legacy_pty_init(void)
pty_driver->init_termios.c_ospeed = 38400;
pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
pty_driver->other = pty_slave_driver;
tty_set_operations(pty_driver, &pty_ops);
tty_set_operations(pty_driver, &master_pty_ops_bsd);

pty_slave_driver->owner = THIS_MODULE;
pty_slave_driver->driver_name = "pty_slave";
Expand All @@ -399,7 +404,7 @@ static void __init legacy_pty_init(void)
pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS |
TTY_DRIVER_REAL_RAW;
pty_slave_driver->other = pty_driver;
tty_set_operations(pty_slave_driver, &pty_ops);
tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd);

if (tty_register_driver(pty_driver))
panic("Couldn't register pty driver");
Expand Down

0 comments on commit 342a597

Please sign in to comment.