summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/imgact_elf.c2
-rw-r--r--sys/kern/kern_descrip.c11
-rw-r--r--sys/kern/kern_exit.c6
-rw-r--r--sys/kern/kern_fork.c6
-rw-r--r--sys/kern/kern_thr.c4
-rw-r--r--sys/kern/sysv_msg.c8
-rw-r--r--sys/kern/sysv_sem.c4
-rw-r--r--sys/kern/sysv_shm.c4
8 files changed, 44 insertions, 1 deletions
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index ad79360..45f6d64 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -1115,6 +1115,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
hdrsize = 0;
__elfN(puthdr)(td, (void *)NULL, &hdrsize, seginfo.count);
+#ifdef RACCT
PROC_LOCK(td->td_proc);
error = racct_add(td->td_proc, RACCT_CORE, hdrsize + seginfo.size);
PROC_UNLOCK(td->td_proc);
@@ -1122,6 +1123,7 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags)
error = EFAULT;
goto done;
}
+#endif
if (hdrsize + seginfo.size >= limit) {
error = EFAULT;
goto done;
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 731bb61..b32c28a 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -821,6 +821,7 @@ do_dup(struct thread *td, int flags, int old, int new,
* descriptors, just put the limit on the size of the file
* descriptor table.
*/
+#ifdef RACCT
PROC_LOCK(p);
error = racct_set(p, RACCT_NOFILE, new + 1);
PROC_UNLOCK(p);
@@ -829,6 +830,7 @@ do_dup(struct thread *td, int flags, int old, int new,
fdrop(fp, td);
return (EMFILE);
}
+#endif
fdgrowtable(fdp, new + 1);
}
if (fdp->fd_ofiles[new] == NULL)
@@ -1476,7 +1478,10 @@ fdalloc(struct thread *td, int minfd, int *result)
{
struct proc *p = td->td_proc;
struct filedesc *fdp = p->p_fd;
- int fd = -1, maxfd, error;
+ int fd = -1, maxfd;
+#ifdef RACCT
+ int error;
+#endif
FILEDESC_XLOCK_ASSERT(fdp);
@@ -1499,11 +1504,13 @@ fdalloc(struct thread *td, int minfd, int *result)
return (EMFILE);
if (fd < fdp->fd_nfiles)
break;
+#ifdef RACCT
PROC_LOCK(p);
error = racct_set(p, RACCT_NOFILE, min(fdp->fd_nfiles * 2, maxfd));
PROC_UNLOCK(p);
if (error != 0)
return (EMFILE);
+#endif
fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd));
}
@@ -1819,9 +1826,11 @@ fdfree(struct thread *td)
if (fdp == NULL)
return;
+#ifdef RACCT
PROC_LOCK(td->td_proc);
racct_set(td->td_proc, RACCT_NOFILE, 0);
PROC_UNLOCK(td->td_proc);
+#endif
/* Check for special need to clear POSIX style locks */
fdtol = td->td_proc->p_fdtol;
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index bb25d17..30b94b6 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -744,9 +744,11 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options,
* 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);
+#endif
/*
* Free credentials, arguments, and sigacts.
@@ -905,19 +907,23 @@ 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);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 04e635a..a8abd8e 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -734,11 +734,13 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp)
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
mem_charged = 0;
vm2 = NULL;
@@ -822,6 +824,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp)
goto fail;
}
+#ifdef RACCT
/*
* After fork, there is exactly one thread running.
*/
@@ -832,6 +835,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp)
error = EAGAIN;
goto fail;
}
+#endif
/*
* Increment the count of procs running with this uid. Don't allow
@@ -874,9 +878,11 @@ fail1:
vmspace_free(vm2);
uma_zfree(proc_zone, newproc);
pause("fork", hz / 2);
+#ifdef RACCT
PROC_LOCK(p1);
racct_sub(p1, RACCT_NPROC, 1);
PROC_UNLOCK(p1);
+#endif
return (error);
}
diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c
index 7011a53..94e41e2 100644
--- a/sys/kern/kern_thr.c
+++ b/sys/kern/kern_thr.c
@@ -185,11 +185,13 @@ create_thread(struct thread *td, mcontext_t *ctx,
}
}
+#ifdef RACCT
PROC_LOCK(td->td_proc);
error = racct_add(p, RACCT_NTHR, 1);
PROC_UNLOCK(td->td_proc);
if (error != 0)
return (EPROCLIM);
+#endif
/* Initialize our td */
newtd = thread_alloc(0);
@@ -277,9 +279,11 @@ create_thread(struct thread *td, mcontext_t *ctx,
return (0);
fail:
+#ifdef RACCT
PROC_LOCK(p);
racct_sub(p, RACCT_NTHR, 1);
PROC_UNLOCK(p);
+#endif
return (error);
}
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
index 87d479e..ffd8580 100644
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -620,6 +620,7 @@ msgget(td, uap)
error = ENOSPC;
goto done2;
}
+#ifdef RACCT
PROC_LOCK(td->td_proc);
error = racct_add(td->td_proc, RACCT_NMSGQ, 1);
PROC_UNLOCK(td->td_proc);
@@ -627,6 +628,7 @@ msgget(td, uap)
error = ENOSPC;
goto done2;
}
+#endif
DPRINTF(("msqid %d is available\n", msqid));
msqkptr->u.msg_perm.key = key;
msqkptr->u.msg_perm.cuid = cred->cr_uid;
@@ -685,7 +687,9 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgflg, mtype)
register struct msqid_kernel *msqkptr;
register struct msg *msghdr;
short next;
+#ifdef RACCT
size_t saved_msgsz;
+#endif
if (!prison_allow(td->td_ucred, PR_ALLOW_SYSVIPC))
return (ENOSYS);
@@ -723,6 +727,7 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgflg, mtype)
goto done2;
#endif
+#ifdef RACCT
PROC_LOCK(td->td_proc);
if (racct_add(td->td_proc, RACCT_MSGQQUEUED, 1)) {
PROC_UNLOCK(td->td_proc);
@@ -737,6 +742,7 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgflg, mtype)
goto done2;
}
PROC_UNLOCK(td->td_proc);
+#endif
segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
DPRINTF(("msgsz=%zu, msgssz=%d, segs_needed=%d\n", msgsz,
@@ -991,12 +997,14 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgflg, mtype)
wakeup(msqkptr);
td->td_retval[0] = 0;
done3:
+#ifdef RACCT
if (error != 0) {
PROC_LOCK(td->td_proc);
racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1);
racct_sub(td->td_proc, RACCT_MSGQSIZE, saved_msgsz);
PROC_UNLOCK(td->td_proc);
}
+#endif
done2:
mtx_unlock(&msq_mtx);
return (error);
diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c
index ac53a8d..4bbe787 100644
--- a/sys/kern/sysv_sem.c
+++ b/sys/kern/sysv_sem.c
@@ -931,6 +931,7 @@ semget(struct thread *td, struct semget_args *uap)
error = ENOSPC;
goto done2;
}
+#ifdef RACCT
PROC_LOCK(td->td_proc);
error = racct_add(td->td_proc, RACCT_NSEM, nsems);
PROC_UNLOCK(td->td_proc);
@@ -938,6 +939,7 @@ semget(struct thread *td, struct semget_args *uap)
error = ENOSPC;
goto done2;
}
+#endif
DPRINTF(("semid %d is available\n", semid));
mtx_lock(&sema_mtx[semid]);
KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0,
@@ -1023,12 +1025,14 @@ semop(struct thread *td, struct semop_args *uap)
nsops));
return (E2BIG);
} else {
+#ifdef RACCT
PROC_LOCK(td->td_proc);
if (nsops > racct_get_available(td->td_proc, RACCT_NSEMOP)) {
PROC_UNLOCK(td->td_proc);
return (E2BIG);
}
PROC_UNLOCK(td->td_proc);
+#endif
sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK);
}
diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c
index f5a84ae..1741a21 100644
--- a/sys/kern/sysv_shm.c
+++ b/sys/kern/sysv_shm.c
@@ -672,6 +672,7 @@ shmget_allocate_segment(td, uap, mode)
shm_last_free = -1;
}
shmseg = &shmsegs[segnum];
+#ifdef RACCT
PROC_LOCK(td->td_proc);
if (racct_add(td->td_proc, RACCT_NSHM, 1)) {
PROC_UNLOCK(td->td_proc);
@@ -683,6 +684,7 @@ shmget_allocate_segment(td, uap, mode)
return (ENOMEM);
}
PROC_UNLOCK(td->td_proc);
+#endif
/*
* In case we sleep in malloc(), mark the segment present but deleted
* so that noone else tries to create the same key.
@@ -699,10 +701,12 @@ shmget_allocate_segment(td, uap, mode)
shm_object = vm_pager_allocate(shm_use_phys ? OBJT_PHYS : OBJT_SWAP,
0, size, VM_PROT_DEFAULT, 0, cred);
if (shm_object == NULL) {
+#ifdef RACCT
PROC_LOCK(td->td_proc);
racct_sub(td->td_proc, RACCT_NSHM, 1);
racct_sub(td->td_proc, RACCT_SHMSIZE, size);
PROC_UNLOCK(td->td_proc);
+#endif
return (ENOMEM);
}
VM_OBJECT_LOCK(shm_object);
OpenPOWER on IntegriCloud