From owner-svn-src-head@FreeBSD.ORG Sat Sep 17 19:55:33 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9655B1065670; Sat, 17 Sep 2011 19:55:33 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 425788FC18; Sat, 17 Sep 2011 19:55:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p8HJtXv1096855; Sat, 17 Sep 2011 19:55:33 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8HJtXdA096852; Sat, 17 Sep 2011 19:55:33 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201109171955.p8HJtXdA096852@svn.freebsd.org> From: Edward Tomasz Napierala Date: Sat, 17 Sep 2011 19:55:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225641 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Sep 2011 19:55:33 -0000 Author: trasz Date: Sat Sep 17 19:55:32 2011 New Revision: 225641 URL: http://svn.freebsd.org/changeset/base/225641 Log: Fix long-standing thinko regarding maxproc accounting. Basically, we were accounting the newly created process to its parent instead of the child itself. This caused problems later, when the child changed its credentials - the per-uid, per-jail etc counters were not properly updated, because the maxproc counter in the child process was 0. Approved by: re (kib) Modified: head/sys/kern/kern_exit.c head/sys/kern/kern_fork.c Modified: head/sys/kern/kern_exit.c ============================================================================== --- head/sys/kern/kern_exit.c Sat Sep 17 13:48:09 2011 (r225640) +++ head/sys/kern/kern_exit.c Sat Sep 17 19:55:32 2011 (r225641) @@ -765,12 +765,12 @@ proc_reap(struct thread *td, struct proc /* * Destroy resource accounting information associated with the process. */ - racct_proc_exit(p); #ifdef RACCT - PROC_LOCK(p->p_pptr); - racct_sub(p->p_pptr, RACCT_NPROC, 1); - PROC_UNLOCK(p->p_pptr); + PROC_LOCK(p); + racct_sub(p, RACCT_NPROC, 1); + PROC_UNLOCK(p); #endif + racct_proc_exit(p); /* * Free credentials, arguments, and sigacts. @@ -929,25 +929,13 @@ loop: void proc_reparent(struct proc *child, struct proc *parent) { -#ifdef RACCT - int locked; -#endif sx_assert(&proctree_lock, SX_XLOCKED); PROC_LOCK_ASSERT(child, MA_OWNED); if (child->p_pptr == parent) return; -#ifdef RACCT - locked = PROC_LOCKED(parent); - if (!locked) - PROC_LOCK(parent); - racct_add_force(parent, RACCT_NPROC, 1); - if (!locked) - PROC_UNLOCK(parent); -#endif PROC_LOCK(child->p_pptr); - racct_sub(child->p_pptr, RACCT_NPROC, 1); sigqueue_take(child->p_ksi); PROC_UNLOCK(child->p_pptr); LIST_REMOVE(child, p_sibling); Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Sat Sep 17 13:48:09 2011 (r225640) +++ head/sys/kern/kern_fork.c Sat Sep 17 19:55:32 2011 (r225641) @@ -806,14 +806,6 @@ fork1(struct thread *td, int flags, int return (fork_norfproc(td, flags)); } -#ifdef RACCT - PROC_LOCK(p1); - error = racct_add(p1, RACCT_NPROC, 1); - PROC_UNLOCK(p1); - if (error != 0) - return (EAGAIN); -#endif - #ifdef PROCDESC /* * If required, create a process descriptor in the parent first; we @@ -822,14 +814,8 @@ fork1(struct thread *td, int flags, int */ if (flags & RFPROCDESC) { error = falloc(td, &fp_procdesc, procdescp, 0); - if (error != 0) { -#ifdef RACCT - PROC_LOCK(p1); - racct_sub(p1, RACCT_NPROC, 1); - PROC_UNLOCK(p1); -#endif + if (error != 0) return (error); - } } #endif @@ -920,7 +906,8 @@ fork1(struct thread *td, int flags, int * After fork, there is exactly one thread running. */ PROC_LOCK(newproc); - error = racct_set(newproc, RACCT_NTHR, 1); + error = racct_add(newproc, RACCT_NPROC, 1); + error += racct_add(newproc, RACCT_NTHR, 1); PROC_UNLOCK(newproc); if (error != 0) { error = EAGAIN; @@ -977,11 +964,6 @@ fail1: fdrop(fp_procdesc, td); #endif pause("fork", hz / 2); -#ifdef RACCT - PROC_LOCK(p1); - racct_sub(p1, RACCT_NPROC, 1); - PROC_UNLOCK(p1); -#endif return (error); }