__tty_hangup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __tty_hangup(9) πŸ’…

okay so we're in the Kernel API Manual today bestie, and the star of the show is __tty_hangup β€” the actual handler for hangup events. like, the real one. the one that does the work. no cap. πŸŽ€


✨ NAME ✨

__tty_hangup β€” actual handler for hangup events


🌸 SYNOPSIS 🌸

void __tty_hangup (struct tty_struct *tty , int exit_session );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • tty β€” the tty device, obviously. the main character of this whole situation πŸ’…
  • exit_session β€” if this is non-zero, it signals all foreground group processes. like a little ripple effect, iykyk 🌊

πŸ’– DESCRIPTION πŸ’–

so this one can be called by a "kworker" kernel thread. that's process synchronous but it doesn't hold any locks, which means we gotta make sure we've got the appropriate locks for whatever we're doing. gotta be responsible, bestie 🫢

the hangup event clears any pending redirections onto the hung-up device. it makes sure future writes will error (yes, error β€” that's the whole point ✨) and it does the needed line discipline hangup and signal delivery. the tty object itself stays intact, so don't worry, nothing's getting deleted out from under you 🌸

πŸ”’ Locking πŸ”’

bestie, the locking situation is giving main character energy, so pay attention:

  • BTM
  • redirect lock for undoing redirection
  • file list lock for manipulating list of ttys
  • tty_ldiscs_lock from called functions
  • termios_rwsem resetting termios data
  • tasklist_lock to walk task list for hangup event
  • ->siglock to protect ->signal/->sighand
fr fr, that's a lot of locks. respect the lock order or the kernel will humble you πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./drivers/tty/tty_io.c:

free_tty_struct(9), tty_free_file(9), tty_name(9), get_tty_driver(9), tty_dev_name_to_number(9), tty_find_polling_driver(9), tty_wakeup(9), tty_release_redirect(9), tty_hangup(9), tty_vhangup(9), tty_vhangup_self(9), tty_vhangup_session(9), tty_hung_up_p(9), stop_tty(9), start_tty(9), tty_read(9), tty_write(9), tty_send_xchar(9), pty_line_name(9), tty_line_name(9), tty_driver_lookup_tty(9), tty_init_termios(9), tty_standard_install(9), tty_driver_install_tty(9), tty_driver_remove_tty(9), tty_reopen(9), tty_init_dev(9), tty_save_termios(9), tty_flush_works(9), release_one_tty(9), tty_kref_put(9), release_tty(9), tty_release_checks(9), tty_kclose(9), tty_release_struct(9), tty_release(9), tty_open_current_tty(9), tty_lookup_driver(9), tty_kopen_exclusive(9), tty_kopen_shared(9), tty_open_by_driver(9), tty_open(9), tty_poll(9), tiocsti(9), tiocgwinsz(9), tty_do_resize(9), tiocswinsz(9), tioccons(9), tiocsetd(9), tiocgetd(9), send_break(9), tty_get_tiocm(9), tty_tiocmget(9), tty_tiocmset(9), tty_get_icount(9), alloc_tty_struct(9), tty_put_char(9), tty_register_device(9), tty_register_device_attr(9), tty_unregister_device(9), __tty_alloc_driver(9), tty_driver_kref_put(9), tty_register_driver(9), tty_unregister_driver(9)


and that's the whole page, bestie 🧚 go forth and hang up those ttys responsibly πŸ’œ

later, legend πŸŽ€ β€” this lil page came from ./drivers/tty and it's dated October 2026 πŸ¦‹

πŸ“¦ where this page comes from