FreeBSD/sys/kern/kern_proc.c
/*
 * This sysctl allows a process to retrieve or/and set the resource limit for
 * another process.
 */
This sysctl allows a process to retrieve or/and set the resource limit for
another process.
This sysctl allows a process to retrieve or / and set the resource limit for another process .
static int
sysctl_kern_proc_rlimit(SYSCTL_HANDLER_ARGS)
{
	int *name = (int *)arg1;
	u_int namelen = arg2;
	struct rlimit rlim;
	struct proc *p;
	u_int which;
	int flags, error;
	if (namelen != 2)
		return (EINVAL);
	which = (u_int)name[1];
	if (which >= RLIM_NLIMITS)
		return (EINVAL);
	if (req->newptr != NULL && req->newlen != sizeof(rlim))
		return (EINVAL);
	flags = PGET_HOLD | PGET_NOTWEXIT;
	if (req->newptr != NULL)
		flags |= PGET_CANDEBUG;
	else
		flags |= PGET_CANSEE;
	error = pget((pid_t)name[0], flags, &p);
	if (error != 0)
		return (error);
	if (req->oldptr != NULL) {
		PROC_LOCK(p);
		lim_rlimit_proc(p, which, &rlim);
		PROC_UNLOCK(p);
	}
	error = SYSCTL_OUT(req, &rlim, sizeof(rlim));
	if (error != 0)
		goto errout;
	if (req->newptr != NULL) {
		error = SYSCTL_IN(req, &rlim, sizeof(rlim));
		if (error == 0)
			error = kern_proc_setrlimit(curthread, p, which, &rlim);
	}
errout:
	PRELE(p);
	return (error);
}
static int sysctl_kern_proc_rlimit ( SYSCTL_HANDLER_ARGS ) { int * name = ( int * ) arg1 ; u_int namelen = arg2 ; struct rlimit rlim ; struct proc * p ; u_int which ; int flags , error ; if ( namelen != 2 ) return ( EINVAL ) ; which = ( u_int ) name [ 1 ] ; if ( which >= RLIM_NLIMITS ) return ( EINVAL ) ; if ( req -> newptr != NULL && req -> newlen != sizeof ( rlim ) ) return ( EINVAL ) ; flags = PGET_HOLD | PGET_NOTWEXIT ; if ( req -> newptr != NULL ) flags |= PGET_CANDEBUG ; else flags |= PGET_CANSEE ; error = pget ( ( pid_t ) name [ 0 ] , flags , & p ) ; if ( error != 0 ) return ( error ) ; if ( req -> oldptr != NULL ) { PROC_LOCK ( p ) ; lim_rlimit_proc ( p , which , & rlim ) ; PROC_UNLOCK ( p ) ; } error = SYSCTL_OUT ( req , & rlim , sizeof ( rlim ) ) ; if ( error != 0 ) goto errout ; if ( req -> newptr != NULL ) { error = SYSCTL_IN ( req , & rlim , sizeof ( rlim ) ) ; if ( error == 0 ) error = kern_proc_setrlimit ( curthread , p , which , & rlim ) ; } errout : PRELE ( p ) ; return ( error ) ; }
This sysctl allows a process to retrieve or/and set the resource limit for
 another process.
This sysctl allows a process to retrieve or / and set the resource limit for another process .
/*
	 * Retrieve limit.
	 */ /*
	 * Set limit.
	 */