From 7d930e85723d5b1b5f5e4fe6ce714ebd413c6402 Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 12 Apr 2002 17:02:33 +0000 Subject: [PATCH] Use SESSHOLD and SESSRELE consistently. Add SESSHOLD and SESSRELE to the t_session, so that we don't have dangling references [inspired by OpenBSD]. --- sys/kern/kern_proc.c | 13 ++++--------- sys/kern/tty.c | 10 +++++++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 3c5c5198fa61..e0ee75f7bb84 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_proc.c,v 1.46 2002/03/08 20:48:40 thorpej Exp $ */ +/* $NetBSD: kern_proc.c,v 1.47 2002/04/12 17:02:33 christos Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.46 2002/03/08 20:48:40 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.47 2002/04/12 17:02:33 christos Exp $"); #include #include @@ -393,8 +393,8 @@ enterpgrp(p, pgid, mksess) panic("enterpgrp: mksession and p != curproc"); #endif } else { + SESSHOLD(p->p_session); pgrp->pg_session = p->p_session; - pgrp->pg_session->s_count++; } pgrp->pg_id = pgid; LIST_INIT(&pgrp->pg_members); @@ -447,12 +447,7 @@ pgdelete(pgrp) pgrp->pg_session->s_ttyp->t_pgrp == pgrp) pgrp->pg_session->s_ttyp->t_pgrp = NULL; LIST_REMOVE(pgrp, pg_hash); - if (--pgrp->pg_session->s_count == 0) { - /* Remove reference (if any) from tty to this session */ - if (pgrp->pg_session->s_ttyp != NULL) - pgrp->pg_session->s_ttyp->t_session = NULL; - FREE(pgrp->pg_session, M_SESSION); - } + SESSRELE(pgrp->pg_session); pool_put(&pgrp_pool, pgrp); } diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 7c628256b603..449ecb734637 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.135 2002/03/25 04:26:43 itohy Exp $ */ +/* $NetBSD: tty.c,v 1.136 2002/04/12 17:02:33 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1991, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.135 2002/03/25 04:26:43 itohy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.136 2002/04/12 17:02:33 christos Exp $"); #include "opt_uconsole.h" @@ -267,7 +267,10 @@ ttyclose(struct tty *tp) tp->t_gen++; tp->t_pgrp = NULL; - tp->t_session = NULL; + if (tp->t_session != NULL) { + SESSRELE(tp->t_session); + tp->t_session = NULL; + } tp->t_state = 0; return (0); } @@ -988,6 +991,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p) ((p->p_session->s_ttyvp || tp->t_session) && (tp->t_session != p->p_session))) return (EPERM); + SESSHOLD(p->p_session); tp->t_session = p->p_session; tp->t_pgrp = p->p_pgrp; p->p_session->s_ttyp = tp;