summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty_pts.c
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2011-04-02 15:02:42 +0000
committertrasz <trasz@FreeBSD.org>2011-04-02 15:02:42 +0000
commit400f21cacb7b1afe78af9b598fbf6cf3e1b25cce (patch)
tree74b1d2d7b3961ef5accbb89685fc4c7720ac3fc9 /sys/kern/tty_pts.c
parent203d983fecfd05d719b330c52c2a424c8cac209b (diff)
downloadFreeBSD-src-400f21cacb7b1afe78af9b598fbf6cf3e1b25cce.zip
FreeBSD-src-400f21cacb7b1afe78af9b598fbf6cf3e1b25cce.tar.gz
Add accounting for RACCT_NPTS.
Diffstat (limited to 'sys/kern/tty_pts.c')
-rw-r--r--sys/kern/tty_pts.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c
index b749f3f..d89c183 100644
--- a/sys/kern/tty_pts.c
+++ b/sys/kern/tty_pts.c
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/poll.h>
#include <sys/proc.h>
+#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/serial.h>
#include <sys/stat.h>
@@ -682,6 +683,7 @@ ptsdrv_free(void *softc)
free_unr(pts_pool, psc->pts_unit);
chgptscnt(psc->pts_cred->cr_ruidinfo, -1, 0);
+ racct_sub_cred(psc->pts_cred, RACCT_NPTS, 1);
crfree(psc->pts_cred);
knlist_destroy(&psc->pts_inpoll.si_note);
@@ -712,7 +714,7 @@ static
int
pts_alloc(int fflags, struct thread *td, struct file *fp)
{
- int unit, ok;
+ int unit, ok, error;
struct tty *tp;
struct pts_softc *psc;
struct proc *p = td->td_proc;
@@ -720,14 +722,23 @@ pts_alloc(int fflags, struct thread *td, struct file *fp)
/* Resource limiting. */
PROC_LOCK(p);
+ error = racct_add(p, RACCT_NPTS, 1);
+ if (error != 0) {
+ PROC_UNLOCK(p);
+ return (EAGAIN);
+ }
ok = chgptscnt(cred->cr_ruidinfo, 1, lim_cur(p, RLIMIT_NPTS));
- PROC_UNLOCK(p);
- if (!ok)
+ if (!ok) {
+ racct_sub(p, RACCT_NPTS, 1);
+ PROC_UNLOCK(p);
return (EAGAIN);
+ }
+ PROC_UNLOCK(p);
/* Try to allocate a new pts unit number. */
unit = alloc_unr(pts_pool);
if (unit < 0) {
+ racct_sub(p, RACCT_NPTS, 1);
chgptscnt(cred->cr_ruidinfo, -1, 0);
return (EAGAIN);
}
@@ -757,7 +768,7 @@ int
pts_alloc_external(int fflags, struct thread *td, struct file *fp,
struct cdev *dev, const char *name)
{
- int ok;
+ int ok, error;
struct tty *tp;
struct pts_softc *psc;
struct proc *p = td->td_proc;
@@ -765,10 +776,18 @@ pts_alloc_external(int fflags, struct thread *td, struct file *fp,
/* Resource limiting. */
PROC_LOCK(p);
+ error = racct_add(p, RACCT_NPTS, 1);
+ if (error != 0) {
+ PROC_UNLOCK(p);
+ return (EAGAIN);
+ }
ok = chgptscnt(cred->cr_ruidinfo, 1, lim_cur(p, RLIMIT_NPTS));
- PROC_UNLOCK(p);
- if (!ok)
+ if (!ok) {
+ racct_sub(p, RACCT_NPTS, 1);
+ PROC_UNLOCK(p);
return (EAGAIN);
+ }
+ PROC_UNLOCK(p);
/* Allocate TTY and softc. */
psc = malloc(sizeof(struct pts_softc), M_PTS, M_WAITOK|M_ZERO);
OpenPOWER on IntegriCloud