vlimit.c revision 722:636b850d4ee9
114062Swpaul/*
214062Swpaul * CDDL HEADER START
314062Swpaul *
414062Swpaul * The contents of this file are subject to the terms of the
514062Swpaul * Common Development and Distribution License, Version 1.0 only
614062Swpaul * (the "License").  You may not use this file except in compliance
714062Swpaul * with the License.
814062Swpaul *
914062Swpaul * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1014062Swpaul * or http://www.opensolaris.org/os/licensing.
1114062Swpaul * See the License for the specific language governing permissions
1214062Swpaul * and limitations under the License.
1314062Swpaul *
1414062Swpaul * When distributing Covered Code, include this CDDL HEADER in each
1514062Swpaul * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1614062Swpaul * If applicable, add the following below this CDDL HEADER, with the
1714062Swpaul * fields enclosed by brackets "[]" replaced with your own identifying
1814062Swpaul * information: Portions Copyright [yyyy] [name of copyright owner]
1914062Swpaul *
2014062Swpaul * CDDL HEADER END
2114062Swpaul */
2214062Swpaul/*
2314062Swpaul * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
2414062Swpaul * Use is subject to license terms.
2514062Swpaul */
2614062Swpaul
2714062Swpaul#pragma ident	"%Z%%M%	%I%	%E% SMI"
2814062Swpaul
2914062Swpaul/*
3014062Swpaul * (Almost) backwards compatible vlimit.
3114062Swpaul */
3250479Speter#include <sys/time.h>
3314062Swpaul#include <sys/resource.h>
3414062Swpaul#include <errno.h>
3596222Sdes
3696222Sdes/* LIM_NORAISE is not emulated */
3714062Swpaul#define	LIM_NORAISE	0	/* if <> 0, can't raise limits */
3814062Swpaul#define	LIM_CPU		1	/* max secs cpu time */
3914062Swpaul#define	LIM_FSIZE	2	/* max size of file created */
4014062Swpaul#define	LIM_DATA	3	/* max growth of data space */
4116649Swpaul#define	LIM_STACK	4	/* max growth of stack */
4216649Swpaul#define	LIM_CORE	5	/* max size of ``core'' file */
4316649Swpaul#define	LIM_MAXRSS	6	/* max desired data+stack core usage */
4416649Swpaul
4516649Swpaul#define	NLIMITS		6
4614062Swpaul
4714062Swpaulint
4814062Swpaulvlimit(int limit, int value)
4914062Swpaul{
5014062Swpaul	struct rlimit rlim;
5190297Sdes
5290297Sdes	if (limit <= 0 || limit > NLIMITS)
5399824Salfred		return (EINVAL);
5490297Sdes	if (value == -1) {
5590297Sdes		if (getrlimit(limit - 1, &rlim) < 0)
5699824Salfred			return (-1);
5714062Swpaul		return (rlim.rlim_cur);
5814062Swpaul	}
5914062Swpaul	rlim.rlim_cur = value;
6014062Swpaul	rlim.rlim_max = RLIM_INFINITY;
6114062Swpaul	return (setrlimit(limit - 1, &rlim));
6214062Swpaul}
6314062Swpaul