History

TTY: pty, fix pty counting

tty_operations->remove is normally called like: queue_release_one_tty ->tty_shutdown ->tty_driver_remove_tty ->tty_operations->remove However tty_shutdown() is called from queue_release_one_tty() only if tty_operations->shutdown is NULL. But for pty, it is not. pty_unix98_shutdown() is used there as ->shutdown. So tty_operations->remove of pty (i.e. pty_unix98_remove()) is never called. This results in invalid pty_count. I.e. what can be seen in /proc/sys/kernel/pty/nr. I see this was already reported at: https://lkml.org/lkml/2009/11/5/370 But it was not fixed since then. This patch is kind of a hackish way. The problem lies in ->install. We allocate there another tty (so-called tty->link). So ->install is called once, but ->remove twice, for both tty and tty->link. The fix here is to count both tty and tty->link and divide the count by 2 for user. And to have ->remove called, let's make tty_driver_remove_tty() global and call that from pty_unix98_shutdown() (tty_operations->shutdown). While at it, let's document that when ->shutdown is defined, tty_shutdown() is not called.

Jiri Slaby committed 15 years ago

Commit 24d406a1 parent dbb3b1c4 files · +21 −4Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/tty.h +2 −0
  2. include/linux/tty_driver.h +3 −0
include/linux/tty.h+2−0
@@ -421,6 +421,8 @@ extern void tty_driver_flush_buffer(struct tty_struct *tty); · 420 unmodified lines
421extern void tty_throttle(struct tty_struct *tty);421extern void tty_throttle(struct tty_struct *tty);
422extern void tty_unthrottle(struct tty_struct *tty);422extern void tty_unthrottle(struct tty_struct *tty);
423extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);423extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
424extern void tty_driver_remove_tty(struct tty_driver *driver,
425 struct tty_struct *tty);
424extern void tty_shutdown(struct tty_struct *tty);426extern void tty_shutdown(struct tty_struct *tty);
425extern void tty_free_termios(struct tty_struct *tty);427extern void tty_free_termios(struct tty_struct *tty);
426extern int is_current_pgrp_orphaned(void);428extern int is_current_pgrp_orphaned(void);
include/linux/tty_driver.h+3−0
@@ -47,6 +47,9 @@ · 46 unmodified lines
47 *47 *
48 * This routine is called synchronously when a particular tty device48 * This routine is called synchronously when a particular tty device
49 * is closed for the last time freeing up the resources.49 * is closed for the last time freeing up the resources.
50 * Note that tty_shutdown() is not called if ops->shutdown is defined.
51 * This means one is responsible to take care of calling ops->remove (e.g.
52 * via tty_driver_remove_tty) and releasing tty->termios.
50 *53 *
51 *54 *
52 * void (*cleanup)(struct tty_struct * tty);55 * void (*cleanup)(struct tty_struct * tty);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t