Clean up struct session hold/rele management. The tty half-closed support
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 13 Sep 2004 16:22:41 +0000 (16:22 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 13 Sep 2004 16:22:41 +0000 (16:22 +0000)
commit8b90699bbb47e00e66db06c02537f5e3e9d77982
treeb6e1b7590c7bc4f24317f60aa3c2f6e08fdb73c4
parente4bdd9945e11e0b2d636cb9a3f87afbc86b335d9
Clean up struct session hold/rele management.  The tty half-closed support
(i.e. showing 'p0-' in the ps output for the tty instead of '??' after a
process has detached) had an issue where the tty would be left with a
reference to the freed session structure in certain situations because the
session structure's ref-counting code was not properly implementing the
release case.  Consolidate the disparate session ref-counting code into
real sess_hold() and sess_rele() functions and ensure that any tty reference
to the session is cleared before the session structure is free()'d.

NOTE: Joerg noticed a 0xdeadc1de (deadcode) panic related to this issue
which means that prior to this fix it was possible for the bug to cause
memory corruption in certain situations.

NOTE: Linux does not implement half-closed tty sessions like BSD.  Add code
to implement fully-closed tty sessions, and document the whole mess, but
leave it conditionalized-out for now.

Reported-by: Joerg Sonnenberger <joerg@britannica.bec.de>
sys/kern/kern_proc.c
sys/kern/subr_prf.c
sys/kern/tty.c
sys/kern/tty_cons.c
sys/sys/proc.h
sys/sys/tty.h