acct: create a special plimit object and set it for exiting processes

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).

MFC after:	1 week
This commit is contained in:
Mateusz Guzik 2013-06-30 19:08:06 +00:00
parent 1862d13b8a
commit f15ba03632
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=252422

View File

@ -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, replacing;
int error, flags, i, replacing;
error = priv_check(td, PRIV_ACCT);
if (error)
@ -266,6 +267,15 @@ sys_acct(struct thread *td, struct acct_args *uap)
return (error);
}
/*
* 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.
@ -309,6 +319,7 @@ acct_disable(struct thread *td, int logging)
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;
@ -329,7 +340,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;
@ -405,7 +416,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;
@ -414,14 +424,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);