From owner-p4-projects@FreeBSD.ORG Thu Aug 21 14:17:27 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E225D106567D; Thu, 21 Aug 2008 14:17:26 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A5D8A1065678 for ; Thu, 21 Aug 2008 14:17:26 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 7A5688FC27 for ; Thu, 21 Aug 2008 14:17:26 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7LEHQpB041099 for ; Thu, 21 Aug 2008 14:17:26 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7LEHQef041097 for perforce@freebsd.org; Thu, 21 Aug 2008 14:17:26 GMT (envelope-from ed@FreeBSD.org) Date: Thu, 21 Aug 2008 14:17:26 GMT Message-Id: <200808211417.m7LEHQef041097@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ed@FreeBSD.org using -f From: Ed Schouten To: Perforce Change Reviews Cc: Subject: PERFORCE change 148002 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2008 14:17:27 -0000 http://perforce.freebsd.org/chv.cgi?CH=148002 Change 148002 by ed@ed_dull on 2008/08/21 14:16:34 Fix lock order reversal in the change to kern_acct.c I committed. We should not pick up proctree_lock after PROC_LOCK. Fix acct_process() to pick up the locks in the right order. Because we should hold proctree_lock as short as possible, drop it after obtaining the TTY udev. Submitted by: kib (thanks!) Affected files ... .. //depot/projects/mpsafetty/sys/kern/kern_acct.c#3 edit Differences ... ==== //depot/projects/mpsafetty/sys/kern/kern_acct.c#3 (text+ko) ==== @@ -366,16 +366,25 @@ * Get process accounting information. */ + sx_slock(&proctree_lock); PROC_LOCK(p); - /* (1) The name of the command that ran */ + + /* (1) The terminal from which the process was started */ + if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp) + acct.ac_tty = tty_udev(p->p_pgrp->pg_session->s_ttyp); + else + acct.ac_tty = NODEV; + sx_sunlock(&proctree_lock); + + /* (2) The name of the command that ran */ bcopy(p->p_comm, acct.ac_comm, sizeof acct.ac_comm); - /* (2) The amount of user and system time that was used */ + /* (3) The amount of user and system time that was used */ rufetchcalc(p, &ru, &ut, &st); acct.ac_utime = encode_timeval(ut); acct.ac_stime = encode_timeval(st); - /* (3) The elapsed time the command ran (and its starting time) */ + /* (4) The elapsed time the command ran (and its starting time) */ tmp = boottime; timevaladd(&tmp, &p->p_stats->p_start); acct.ac_btime = tmp.tv_sec; @@ -383,7 +392,7 @@ timevalsub(&tmp, &p->p_stats->p_start); acct.ac_etime = encode_timeval(tmp); - /* (4) The average amount of memory used */ + /* (5) The average amount of memory used */ tmp = ut; timevaladd(&tmp, &st); /* Convert tmp (i.e. u + s) into hz units to match ru_i*. */ @@ -394,21 +403,13 @@ else acct.ac_mem = 0; - /* (5) The number of disk I/O operations done */ + /* (6) The number of disk I/O operations done */ acct.ac_io = encode_long(ru.ru_inblock + ru.ru_oublock); - /* (6) The UID and GID of the process */ + /* (7) The UID and GID of the process */ acct.ac_uid = p->p_ucred->cr_ruid; acct.ac_gid = p->p_ucred->cr_rgid; - /* (7) The terminal from which the process was started */ - sx_slock(&proctree_lock); - if ((p->p_flag & P_CONTROLT) && p->p_pgrp->pg_session->s_ttyp) - acct.ac_tty = tty_udev(p->p_pgrp->pg_session->s_ttyp); - else - acct.ac_tty = NODEV; - sx_sunlock(&proctree_lock); - /* (8) The boolean flags that tell how the process terminated, etc. */ acct.ac_flagx = p->p_acflag; PROC_UNLOCK(p);