1*21336Sdist /* 2*21336Sdist * Copyright (c) 1980 Regents of the University of California. 3*21336Sdist * All rights reserved. The Berkeley software License Agreement 4*21336Sdist * specifies the terms and conditions for redistribution. 5*21336Sdist */ 613218Ssam 7*21336Sdist #ifndef lint 8*21336Sdist static char sccsid[] = "@(#)vlimit.c 5.1 (Berkeley) 05/30/85"; 9*21336Sdist #endif not lint 10*21336Sdist 1113218Ssam /* 1213218Ssam * (Almost) backwards compatible vlimit. 1313218Ssam */ 1413219Ssam #include <sys/time.h> 1513218Ssam #include <sys/resource.h> 1613219Ssam #include <errno.h> 1713218Ssam 1813218Ssam /* LIM_NORAISE is not emulated */ 1913218Ssam #define LIM_NORAISE 0 /* if <> 0, can't raise limits */ 2013218Ssam #define LIM_CPU 1 /* max secs cpu time */ 2113218Ssam #define LIM_FSIZE 2 /* max size of file created */ 2213218Ssam #define LIM_DATA 3 /* max growth of data space */ 2313218Ssam #define LIM_STACK 4 /* max growth of stack */ 2413218Ssam #define LIM_CORE 5 /* max size of ``core'' file */ 2513218Ssam #define LIM_MAXRSS 6 /* max desired data+stack core usage */ 2613218Ssam 2713218Ssam #define NLIMITS 6 2813218Ssam 2913218Ssam vlimit(limit, value) 3013218Ssam int limit, value; 3113218Ssam { 3213218Ssam struct rlimit rlim; 3313218Ssam 3413218Ssam if (limit <= 0 || limit > NLIMITS) 3513218Ssam return (EINVAL); 3613218Ssam if (value == -1) { 3713218Ssam if (getrlimit(limit - 1, &rlim) < 0) 3813218Ssam return (-1); 3913218Ssam return (rlim.rlim_cur); 4013218Ssam } 4113218Ssam rlim.rlim_cur = value; 4213218Ssam rlim.rlim_max = RLIM_INFINITY; 4313218Ssam return (setrlimit(limit - 1, &rlim)); 4413218Ssam } 45