From owner-svn-src-all@FreeBSD.ORG Sat Jul 6 12:56:31 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 08E50D99; Sat, 6 Jul 2013 12:56:31 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id ED5F91711; Sat, 6 Jul 2013 12:56:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r66CuUN3064077; Sat, 6 Jul 2013 12:56:30 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r66CuUJN064076; Sat, 6 Jul 2013 12:56:30 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201307061256.r66CuUJN064076@svn.freebsd.org> From: Mateusz Guzik Date: Sat, 6 Jul 2013 12:56:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r252886 - stable/9/sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jul 2013 12:56:31 -0000 Author: mjg Date: Sat Jul 6 12:56:30 2013 New Revision: 252886 URL: http://svnweb.freebsd.org/changeset/base/252886 Log: MFC r252415, r252422: acct: reduce code duplication by using acct_disable as cleanup for failed kproc_create acct: create a special plimit object and set it for exiting processe instead of allocating new one each time All limits are set to RLIM_INFINITY which sould be ok (even though we care only about RLIMT_FSIZE in this case). Modified: stable/9/sys/kern/kern_acct.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_acct.c ============================================================================== --- stable/9/sys/kern/kern_acct.c Sat Jul 6 11:39:37 2013 (r252885) +++ stable/9/sys/kern/kern_acct.c Sat Jul 6 12:56:30 2013 (r252886) @@ -133,6 +133,7 @@ static int acct_configured; static int acct_suspended; static struct vnode *acct_vp; static struct ucred *acct_cred; +static struct plimit *acct_limit; static int acct_flags; static struct sx acct_sx; @@ -196,7 +197,7 @@ int sys_acct(struct thread *td, struct acct_args *uap) { struct nameidata nd; - int error, flags, vfslocked, replacing; + int error, flags, i, vfslocked, replacing; error = priv_check(td, PRIV_ACCT); if (error) @@ -274,6 +275,15 @@ sys_acct(struct thread *td, struct acct_ } /* + * Create our own plimit object without limits. It will be assigned + * to exiting processes. + */ + acct_limit = lim_alloc(); + for (i = 0; i < RLIM_NLIMITS; i++) + acct_limit->pl_rlimit[i].rlim_cur = + acct_limit->pl_rlimit[i].rlim_max = RLIM_INFINITY; + + /* * Save the new accounting file vnode, and schedule the new * free space watcher. */ @@ -292,13 +302,8 @@ sys_acct(struct thread *td, struct acct_ "accounting"); if (error) { vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount); - (void) vn_close(acct_vp, acct_flags, acct_cred, td); + (void) acct_disable(td, 0); VFS_UNLOCK_GIANT(vfslocked); - crfree(acct_cred); - acct_configured = 0; - acct_vp = NULL; - acct_cred = NULL; - acct_flags = 0; sx_xunlock(&acct_sx); log(LOG_NOTICE, "Unable to start accounting thread\n"); return (error); @@ -323,6 +328,7 @@ acct_disable(struct thread *td, int logg sx_assert(&acct_sx, SX_XLOCKED); error = vn_close(acct_vp, acct_flags, acct_cred, td); crfree(acct_cred); + lim_free(acct_limit); acct_configured = 0; acct_vp = NULL; acct_cred = NULL; @@ -343,7 +349,7 @@ acct_process(struct thread *td) { struct acctv2 acct; struct timeval ut, st, tmp; - struct plimit *newlim, *oldlim; + struct plimit *oldlim; struct proc *p; struct rusage ru; int t, ret, vfslocked; @@ -419,7 +425,6 @@ acct_process(struct thread *td) /* (8) The boolean flags that tell how the process terminated, etc. */ acct.ac_flagx = p->p_acflag; - PROC_UNLOCK(p); /* Setup ancillary structure fields. */ acct.ac_flagx |= ANVER; @@ -428,14 +433,10 @@ acct_process(struct thread *td) acct.ac_len = acct.ac_len2 = sizeof(acct); /* - * Eliminate any file size rlimit. + * Eliminate rlimits (file size limit in particular). */ - newlim = lim_alloc(); - PROC_LOCK(p); oldlim = p->p_limit; - lim_copy(newlim, oldlim); - newlim->pl_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; - p->p_limit = newlim; + p->p_limit = lim_hold(acct_limit); PROC_UNLOCK(p); lim_free(oldlim);