| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | This file is ulimit.def, from which is created ulimit.c. | 
					
						
							|  |  |  | It implements the builtin "ulimit" in Bash. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Copyright (C) 1987-2009 Free Software Foundation, Inc. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | This file is part of GNU Bash, the Bourne Again SHell. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Bash is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | (at your option) any later version. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | Bash is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | along with Bash.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $PRODUCES ulimit.c | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN ulimit | 
					
						
							|  |  |  | $FUNCTION ulimit_builtin | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | $DEPENDS_ON !_MINIX | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | $SHORT_DOC ulimit [-SHacdefilmnpqrstuvx] [limit] | 
					
						
							|  |  |  | Modify shell resource limits. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Provides control over the resources available to the shell and processes | 
					
						
							|  |  |  | it creates, on systems that allow such control. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Options: | 
					
						
							|  |  |  |   -S	use the `soft' resource limit | 
					
						
							|  |  |  |   -H	use the `hard' resource limit | 
					
						
							|  |  |  |   -a	all current limits are reported | 
					
						
							|  |  |  |   -b	the socket buffer size | 
					
						
							|  |  |  |   -c	the maximum size of core files created | 
					
						
							|  |  |  |   -d	the maximum size of a process's data segment | 
					
						
							|  |  |  |   -e	the maximum scheduling priority (`nice') | 
					
						
							|  |  |  |   -f	the maximum size of files written by the shell and its children | 
					
						
							|  |  |  |   -i	the maximum number of pending signals | 
					
						
							|  |  |  |   -l	the maximum size a process may lock into memory | 
					
						
							|  |  |  |   -m	the maximum resident set size | 
					
						
							|  |  |  |   -n	the maximum number of open file descriptors | 
					
						
							|  |  |  |   -p	the pipe buffer size | 
					
						
							|  |  |  |   -q	the maximum number of bytes in POSIX message queues | 
					
						
							|  |  |  |   -r	the maximum real-time scheduling priority | 
					
						
							|  |  |  |   -s	the maximum stack size | 
					
						
							|  |  |  |   -t	the maximum amount of cpu time in seconds | 
					
						
							|  |  |  |   -u	the maximum number of user processes | 
					
						
							|  |  |  |   -v	the size of virtual memory | 
					
						
							|  |  |  |   -x	the maximum number of file locks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If LIMIT is given, it is the new value of the specified resource; the | 
					
						
							|  |  |  | special LIMIT values `soft', `hard', and `unlimited' stand for the | 
					
						
							|  |  |  | current soft limit, the current hard limit, and no limit, respectively. | 
					
						
							|  |  |  | Otherwise, the current value of the specified resource is printed.  If | 
					
						
							|  |  |  | no option is given, then -f is assumed. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Values are in 1024-byte increments, except for -t, which is in seconds, | 
					
						
							|  |  |  | -p, which is in increments of 512 bytes, and -u, which is an unscaled | 
					
						
							|  |  |  | number of processes. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Exit Status: | 
					
						
							|  |  |  | Returns success unless an invalid option is supplied or an error occurs. | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #if !defined (_MINIX) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include <config.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../bashtypes.h" | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #ifndef _MINIX | 
					
						
							|  |  |  | #  include <sys/param.h> | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_UNISTD_H) | 
					
						
							|  |  |  | #  include <unistd.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h> | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include <errno.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | #include "../bashintl.h" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "../shell.h" | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include "common.h" | 
					
						
							|  |  |  | #include "bashgetopt.h" | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #include "pipesize.h" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined (errno) | 
					
						
							|  |  |  | extern int errno; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* For some reason, HPUX chose to make these definitions visible only if | 
					
						
							|  |  |  |    _KERNEL is defined, so we define _KERNEL before including <sys/resource.h> | 
					
						
							|  |  |  |    and #undef it afterward. */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							|  |  |  | #  include <sys/time.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL) | 
					
						
							|  |  |  | #    define _KERNEL | 
					
						
							|  |  |  | #  endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  include <sys/resource.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL) | 
					
						
							|  |  |  | #    undef _KERNEL | 
					
						
							|  |  |  | #  endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #elif defined (HAVE_SYS_TIMES_H) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  include <sys/times.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_LIMITS_H) | 
					
						
							|  |  |  | #  include <limits.h> | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Check for the most basic symbols.  If they aren't present, this | 
					
						
							|  |  |  |    system's <sys/resource.h> isn't very useful to us. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if !defined (RLIMIT_FSIZE) || !defined (HAVE_GETRLIMIT) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  undef HAVE_RESOURCE | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined (RLIMTYPE) | 
					
						
							|  |  |  | #  define RLIMTYPE long | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #  define string_to_rlimtype(s) strtol(s, (char **)NULL, 10) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  define print_rlimtype(num, nl) printf ("%ld%s", num, nl ? "\n" : "") | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Some systems use RLIMIT_NOFILE, others use RLIMIT_OFILE */ | 
					
						
							|  |  |  | #if defined (HAVE_RESOURCE) && defined (RLIMIT_OFILE) && !defined (RLIMIT_NOFILE) | 
					
						
							|  |  |  | #  define RLIMIT_NOFILE RLIMIT_OFILE | 
					
						
							|  |  |  | #endif /* HAVE_RESOURCE && RLIMIT_OFILE && !RLIMIT_NOFILE */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Some systems have these, some do not. */ | 
					
						
							|  |  |  | #ifdef RLIMIT_FSIZE | 
					
						
							|  |  |  | #  define RLIMIT_FILESIZE	RLIMIT_FSIZE | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  | #  define RLIMIT_FILESIZE	256 | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define RLIMIT_PIPESIZE	257 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #ifdef RLIMIT_NOFILE | 
					
						
							|  |  |  | #  define RLIMIT_OPENFILES	RLIMIT_NOFILE | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  | #  define RLIMIT_OPENFILES	258 | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #ifdef RLIMIT_VMEM | 
					
						
							|  |  |  | #  define RLIMIT_VIRTMEM	RLIMIT_VMEM | 
					
						
							|  |  |  | #  define RLIMIT_VMBLKSZ	1024 | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  | #  ifdef RLIMIT_AS | 
					
						
							|  |  |  | #    define RLIMIT_VIRTMEM	RLIMIT_AS | 
					
						
							|  |  |  | #    define RLIMIT_VMBLKSZ	1024 | 
					
						
							|  |  |  | #  else | 
					
						
							|  |  |  | #    define RLIMIT_VIRTMEM	259 | 
					
						
							|  |  |  | #    define RLIMIT_VMBLKSZ	1 | 
					
						
							|  |  |  | #  endif | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef RLIMIT_NPROC | 
					
						
							|  |  |  | #  define RLIMIT_MAXUPROC	RLIMIT_NPROC | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  | #  define RLIMIT_MAXUPROC	260 | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if !defined (RLIM_INFINITY) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  define RLIM_INFINITY 0x7fffffff | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #if !defined (RLIM_SAVED_CUR) | 
					
						
							|  |  |  | #  define RLIM_SAVED_CUR RLIM_INFINITY | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined (RLIM_SAVED_MAX) | 
					
						
							|  |  |  | #  define RLIM_SAVED_MAX RLIM_INFINITY | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #define LIMIT_HARD 0x01 | 
					
						
							|  |  |  | #define LIMIT_SOFT 0x02 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | /* "Blocks" are defined as 512 bytes when in Posix mode and 1024 bytes | 
					
						
							|  |  |  |    otherwise. */ | 
					
						
							|  |  |  | #define POSIXBLK	-2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BLOCKSIZE(x)	(((x) == POSIXBLK) ? (posixly_correct ? 512 : 1024) : (x)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern int posixly_correct; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int _findlim __P((int)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int ulimit_internal __P((int, char *, int, int)); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int get_limit __P((int, RLIMTYPE *, RLIMTYPE *)); | 
					
						
							|  |  |  | static int set_limit __P((int, RLIMTYPE, int)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static void printone __P((int, RLIMTYPE, int)); | 
					
						
							|  |  |  | static void print_all_limits __P((int)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int set_all_limits __P((int, RLIMTYPE)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int filesize __P((RLIMTYPE *)); | 
					
						
							|  |  |  | static int pipesize __P((RLIMTYPE *)); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | static int getmaxuprc __P((RLIMTYPE *)); | 
					
						
							|  |  |  | static int getmaxvm __P((RLIMTYPE *, RLIMTYPE *)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  |   int  option;			/* The ulimit option for this limit. */ | 
					
						
							|  |  |  |   int  parameter;		/* Parameter to pass to get_limit (). */ | 
					
						
							|  |  |  |   int  block_factor;		/* Blocking factor for specific limit. */ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   const char * const description;	/* Descriptive string to output. */ | 
					
						
							|  |  |  |   const char * const units;	/* scale */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } RESOURCE_LIMITS; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static RESOURCE_LIMITS limits[] = { | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | #ifdef RLIMIT_PTHREAD | 
					
						
							|  |  |  |   { 'T',	RLIMIT_PTHREAD,  1,	"number of threads",	(char *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_SBSIZE | 
					
						
							|  |  |  |   { 'b',	RLIMIT_SBSIZE,  1,	"socket buffer size",	"bytes" }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #ifdef RLIMIT_CORE | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   { 'c',	RLIMIT_CORE,  POSIXBLK,	"core file size",	"blocks" }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_DATA | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'd',	RLIMIT_DATA,  1024,	"data seg size",	"kbytes" }, | 
					
						
							| 
									
										
										
										
											2006-10-10 14:15:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_NICE | 
					
						
							|  |  |  |   { 'e',	RLIMIT_NICE,  1,	"scheduling priority",	(char *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   { 'f',	RLIMIT_FILESIZE, POSIXBLK,	"file size",		"blocks" }, | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #ifdef RLIMIT_SIGPENDING | 
					
						
							|  |  |  |   { 'i',	RLIMIT_SIGPENDING, 1,	"pending signals",	(char *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #ifdef RLIMIT_MEMLOCK | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'l',	RLIMIT_MEMLOCK, 1024,	"max locked memory",	"kbytes" }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_RSS | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'm',	RLIMIT_RSS,   1024,	"max memory size",	"kbytes" }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif /* RLIMIT_RSS */ | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'n',	RLIMIT_OPENFILES, 1,	"open files",		(char *)NULL}, | 
					
						
							|  |  |  |   { 'p',	RLIMIT_PIPESIZE, 512,	"pipe size", 		"512 bytes" }, | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #ifdef RLIMIT_MSGQUEUE | 
					
						
							|  |  |  |   { 'q',	RLIMIT_MSGQUEUE, 1,	"POSIX message queues",	"bytes" }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2006-10-10 14:15:34 +00:00
										 |  |  | #ifdef RLIMIT_RTPRIO | 
					
						
							|  |  |  |   { 'r',	RLIMIT_RTPRIO,  1,	"real-time priority",	(char *)NULL }, | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #ifdef RLIMIT_STACK | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 's',	RLIMIT_STACK, 1024,	"stack size",		"kbytes" }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_CPU | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 't',	RLIMIT_CPU,      1,	"cpu time",		"seconds" }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif /* RLIMIT_CPU */ | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'u',	RLIMIT_MAXUPROC, 1,	"max user processes",	(char *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'v',	RLIMIT_VIRTMEM, RLIMIT_VMBLKSZ, "virtual memory", "kbytes" }, | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_SWAP | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { 'w',	RLIMIT_SWAP,	1024,	"swap size",		"kbytes" }, | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | #ifdef RLIMIT_LOCKS | 
					
						
							|  |  |  |   { 'x',	RLIMIT_LOCKS,	1,	"file locks",		(char *)NULL }, | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   { -1, -1, -1, (char *)NULL, (char *)NULL } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | #define NCMDS	(sizeof(limits) / sizeof(limits[0])) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | typedef struct _cmd { | 
					
						
							|  |  |  |   int cmd; | 
					
						
							|  |  |  |   char *arg; | 
					
						
							|  |  |  | } ULCMD; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static ULCMD *cmdlist; | 
					
						
							|  |  |  | static int ncmd; | 
					
						
							|  |  |  | static int cmdlistsz; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #if !defined (HAVE_RESOURCE) && !defined (HAVE_ULIMIT) | 
					
						
							|  |  |  | long | 
					
						
							|  |  |  | ulimit (cmd, newlim) | 
					
						
							|  |  |  |      int cmd; | 
					
						
							|  |  |  |      long newlim; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   errno = EINVAL; | 
					
						
							|  |  |  |   return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* !HAVE_RESOURCE && !HAVE_ULIMIT */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | _findlim (opt) | 
					
						
							|  |  |  |      int opt; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   register int i; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   for (i = 0; limits[i].option > 0; i++) | 
					
						
							|  |  |  |     if (limits[i].option == opt) | 
					
						
							|  |  |  |       return i; | 
					
						
							|  |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static char optstring[4 + 2 * NCMDS]; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Report or set limits associated with certain per-process resources. | 
					
						
							|  |  |  |    See the help documentation in builtins.c for a full description. */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | int | 
					
						
							|  |  |  | ulimit_builtin (list) | 
					
						
							|  |  |  |      register WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   register char *s; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   int c, limind, mode, opt, all_limits; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   mode = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   all_limits = 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   /* Idea stolen from pdksh -- build option string the first time called. */ | 
					
						
							|  |  |  |   if (optstring[0] == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s = optstring; | 
					
						
							|  |  |  |       *s++ = 'a'; *s++ = 'S'; *s++ = 'H'; | 
					
						
							|  |  |  |       for (c = 0; limits[c].option > 0; c++) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  *s++ = limits[c].option; | 
					
						
							|  |  |  | 	  *s++ = ';'; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       *s = '\0'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   /* Initialize the command list. */ | 
					
						
							|  |  |  |   if (cmdlistsz == 0) | 
					
						
							|  |  |  |     cmdlist = (ULCMD *)xmalloc ((cmdlistsz = 16) * sizeof (ULCMD)); | 
					
						
							|  |  |  |   ncmd = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   reset_internal_getopt (); | 
					
						
							|  |  |  |   while ((opt = internal_getopt (list, optstring)) != -1) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       switch (opt) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	case 'a': | 
					
						
							|  |  |  | 	  all_limits++; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* -S and -H are modifiers, not real options.  */ | 
					
						
							|  |  |  | 	case 'S': | 
					
						
							|  |  |  | 	  mode |= LIMIT_SOFT; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 'H': | 
					
						
							|  |  |  | 	  mode |= LIMIT_HARD; | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case '?': | 
					
						
							|  |  |  | 	  builtin_usage (); | 
					
						
							|  |  |  | 	  return (EX_USAGE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	  if (ncmd >= cmdlistsz) | 
					
						
							|  |  |  | 	    cmdlist = (ULCMD *)xrealloc (cmdlist, (cmdlistsz *= 2) * sizeof (ULCMD)); | 
					
						
							|  |  |  | 	  cmdlist[ncmd].cmd = opt; | 
					
						
							|  |  |  | 	  cmdlist[ncmd++].arg = list_optarg; | 
					
						
							|  |  |  | 	  break; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   list = loptend; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (all_limits) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | #ifdef NOTYET | 
					
						
							|  |  |  |       if (list)		/* setting */ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           if (STREQ (list->word->word, "unlimited") == 0) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |               builtin_error (_("%s: invalid limit argument"), list->word->word); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |               return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           return (set_all_limits (mode == 0 ? LIMIT_SOFT|LIMIT_HARD : mode, RLIM_INFINITY)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       print_all_limits (mode == 0 ? LIMIT_SOFT : mode); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       return (sh_chkwrite (EXECUTION_SUCCESS)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   /* default is `ulimit -f' */ | 
					
						
							|  |  |  |   if (ncmd == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       cmdlist[ncmd].cmd = 'f'; | 
					
						
							|  |  |  |       /* `ulimit something' is same as `ulimit -f something' */ | 
					
						
							|  |  |  |       cmdlist[ncmd++].arg = list ? list->word->word : (char *)NULL; | 
					
						
							|  |  |  |       if (list) | 
					
						
							|  |  |  | 	list = list->next; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* verify each command in the list. */ | 
					
						
							|  |  |  |   for (c = 0; c < ncmd; c++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       limind = _findlim (cmdlist[c].cmd); | 
					
						
							|  |  |  |       if (limind == -1) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  | 	  builtin_error (_("`%c': bad command"), cmdlist[c].cmd); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  return (EX_USAGE); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (c = 0; c < ncmd; c++) | 
					
						
							|  |  |  |     if (ulimit_internal (cmdlist[c].cmd, cmdlist[c].arg, mode, ncmd > 1) == EXECUTION_FAILURE) | 
					
						
							|  |  |  |       return (EXECUTION_FAILURE); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | ulimit_internal (cmd, cmdarg, mode, multiple) | 
					
						
							|  |  |  |      int cmd; | 
					
						
							|  |  |  |      char *cmdarg; | 
					
						
							|  |  |  |      int mode, multiple; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int opt, limind, setting; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   int block_factor; | 
					
						
							|  |  |  |   RLIMTYPE soft_limit, hard_limit, real_limit, limit; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   setting = cmdarg != 0; | 
					
						
							|  |  |  |   limind = _findlim (cmd); | 
					
						
							|  |  |  |   if (mode == 0) | 
					
						
							|  |  |  |     mode = setting ? (LIMIT_HARD|LIMIT_SOFT) : LIMIT_SOFT; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   opt = get_limit (limind, &soft_limit, &hard_limit); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (opt < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |       builtin_error (_("%s: cannot get limit: %s"), limits[limind].description, | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 						 strerror (errno)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (setting == 0)	/* print the value of the specified limit */ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       printone (limind, (mode & LIMIT_SOFT) ? soft_limit : hard_limit, multiple); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |   /* Setting the limit. */ | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   if (STREQ (cmdarg, "hard")) | 
					
						
							|  |  |  |     real_limit = hard_limit; | 
					
						
							|  |  |  |   else if (STREQ (cmdarg, "soft")) | 
					
						
							|  |  |  |     real_limit = soft_limit; | 
					
						
							|  |  |  |   else if (STREQ (cmdarg, "unlimited")) | 
					
						
							|  |  |  |     real_limit = RLIM_INFINITY; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else if (all_digits (cmdarg)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       limit = string_to_rlimtype (cmdarg); | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |       block_factor = BLOCKSIZE(limits[limind].block_factor); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       real_limit = limit * block_factor; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       if ((real_limit / block_factor) != limit) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	  sh_erange (cmdarg, _("limit")); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	  return (EXECUTION_FAILURE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |       sh_invalidnum (cmdarg); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (set_limit (limind, real_limit, mode) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2004-07-27 13:29:18 +00:00
										 |  |  |       builtin_error (_("%s: cannot modify limit: %s"), limits[limind].description, | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 						    strerror (errno)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return (EXECUTION_FAILURE); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | get_limit (ind, softlim, hardlim) | 
					
						
							|  |  |  |      int ind; | 
					
						
							|  |  |  |      RLIMTYPE *softlim, *hardlim; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   RLIMTYPE value; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							|  |  |  |   struct rlimit limit; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (limits[ind].parameter >= 256) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       switch (limits[ind].parameter) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	case RLIMIT_FILESIZE: | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | 	  if (filesize (&value) < 0) | 
					
						
							|  |  |  | 	    return -1; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  break; | 
					
						
							|  |  |  | 	case RLIMIT_PIPESIZE: | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | 	  if (pipesize (&value) < 0) | 
					
						
							|  |  |  | 	    return -1; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  break; | 
					
						
							|  |  |  | 	case RLIMIT_OPENFILES: | 
					
						
							|  |  |  | 	  value = (RLIMTYPE)getdtablesize (); | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	case RLIMIT_VIRTMEM: | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	  return (getmaxvm (softlim, hardlim)); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	case RLIMIT_MAXUPROC: | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	  if (getmaxuprc (&value) < 0) | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | 	    return -1; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	  break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 	  errno = EINVAL; | 
					
						
							|  |  |  | 	  return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       *softlim = *hardlim = value; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |       return (0); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							|  |  |  |       if (getrlimit (limits[ind].parameter, &limit) < 0) | 
					
						
							|  |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |       *softlim = limit.rlim_cur; | 
					
						
							|  |  |  |       *hardlim = limit.rlim_max; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #  if defined (HPUX9) | 
					
						
							|  |  |  |       if (limits[ind].parameter == RLIMIT_FILESIZE) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	  *softlim *= 512; | 
					
						
							|  |  |  | 	  *hardlim *= 512;			/* Ugh. */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |       else | 
					
						
							|  |  |  | #  endif /* HPUX9 */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #else | 
					
						
							|  |  |  |       errno = EINVAL; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return -1; | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | set_limit (ind, newlim, mode) | 
					
						
							|  |  |  |      int ind; | 
					
						
							|  |  |  |      RLIMTYPE newlim; | 
					
						
							|  |  |  |      int mode; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							|  |  |  |    struct rlimit limit; | 
					
						
							|  |  |  |    RLIMTYPE val; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (limits[ind].parameter >= 256) | 
					
						
							|  |  |  |     switch (limits[ind].parameter) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |       case RLIMIT_FILESIZE: | 
					
						
							|  |  |  | #if !defined (HAVE_RESOURCE) | 
					
						
							|  |  |  | 	return (ulimit (2, newlim / 512L)); | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | #else | 
					
						
							|  |  |  | 	errno = EINVAL; | 
					
						
							|  |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       case RLIMIT_OPENFILES: | 
					
						
							|  |  |  | #if defined (HAVE_SETDTABLESIZE) | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | #  if defined (__CYGWIN__) | 
					
						
							|  |  |  | 	/* Grrr... Cygwin declares setdtablesize as void. */ | 
					
						
							|  |  |  | 	setdtablesize (newlim); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | #  else | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | 	return (setdtablesize (newlim)); | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | #  endif | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  |       case RLIMIT_PIPESIZE: | 
					
						
							|  |  |  |       case RLIMIT_VIRTMEM: | 
					
						
							|  |  |  |       case RLIMIT_MAXUPROC: | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  | 	errno = EINVAL; | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if (getrlimit (limits[ind].parameter, &limit) < 0) | 
					
						
							|  |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | #  if defined (HPUX9) | 
					
						
							|  |  |  |       if (limits[ind].parameter == RLIMIT_FILESIZE) | 
					
						
							|  |  |  | 	newlim /= 512;				/* Ugh. */ | 
					
						
							|  |  |  | #  endif /* HPUX9 */ | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  |       val = (current_user.euid != 0 && newlim == RLIM_INFINITY && | 
					
						
							| 
									
										
										
										
											2001-04-06 19:14:31 +00:00
										 |  |  | 	       (mode & LIMIT_HARD) == 0 &&		/* XXX -- test */ | 
					
						
							| 
									
										
										
										
											1997-06-05 14:59:13 +00:00
										 |  |  | 	       (limit.rlim_cur <= limit.rlim_max)) | 
					
						
							|  |  |  | 		 ? limit.rlim_max : newlim; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       if (mode & LIMIT_SOFT) | 
					
						
							|  |  |  | 	limit.rlim_cur = val; | 
					
						
							|  |  |  |       if (mode & LIMIT_HARD) | 
					
						
							|  |  |  | 	limit.rlim_max = val; | 
					
						
							|  |  |  | 	   | 
					
						
							|  |  |  |       return (setrlimit (limits[ind].parameter, &limit)); | 
					
						
							|  |  |  | #else | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |       errno = EINVAL; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |       return -1; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | getmaxvm (softlim, hardlim) | 
					
						
							|  |  |  |      RLIMTYPE *softlim, *hardlim; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HAVE_RESOURCE) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   struct rlimit datalim, stacklim; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   if (getrlimit (RLIMIT_DATA, &datalim) < 0) | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   if (getrlimit (RLIMIT_STACK, &stacklim) < 0) | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Protect against overflow. */ | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   *softlim = (datalim.rlim_cur / 1024L) + (stacklim.rlim_cur / 1024L); | 
					
						
							|  |  |  |   *hardlim = (datalim.rlim_max / 1024L) + (stacklim.rlim_max / 1024L); | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #else | 
					
						
							|  |  |  |   errno = EINVAL; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* HAVE_RESOURCE */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | filesize(valuep) | 
					
						
							|  |  |  |      RLIMTYPE *valuep; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if !defined (HAVE_RESOURCE) | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   long result; | 
					
						
							|  |  |  |   if ((result = ulimit (1, 0L)) < 0) | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |     *valuep = (RLIMTYPE) result * 512; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #else | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   errno = EINVAL; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | pipesize (valuep) | 
					
						
							|  |  |  |      RLIMTYPE *valuep; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if defined (PIPE_BUF) | 
					
						
							|  |  |  |   /* This is defined on Posix systems. */ | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   *valuep = (RLIMTYPE) PIPE_BUF; | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #else | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #  if defined (_POSIX_PIPE_BUF) | 
					
						
							|  |  |  |   *valuep = (RLIMTYPE) _POSIX_PIPE_BUF; | 
					
						
							|  |  |  |   return 0; | 
					
						
							|  |  |  | #  else | 
					
						
							|  |  |  | #    if defined (PIPESIZE) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   /* This is defined by running a program from the Makefile. */ | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   *valuep = (RLIMTYPE) PIPESIZE; | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #    else | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   errno = EINVAL; | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   return -1;   | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  | #    endif /* PIPESIZE */ | 
					
						
							|  |  |  | #  endif /* _POSIX_PIPE_BUF */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #endif /* PIPE_BUF */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | getmaxuprc (valuep) | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |      RLIMTYPE *valuep; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   long maxchild; | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   maxchild = getmaxchild (); | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   if (maxchild < 0) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       errno = EINVAL; | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1999-02-19 17:11:39 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       *valuep = (RLIMTYPE) maxchild; | 
					
						
							|  |  |  |       return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | print_all_limits (mode) | 
					
						
							|  |  |  |      int mode; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   register int i; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   RLIMTYPE softlim, hardlim; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (mode == 0) | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |     mode |= LIMIT_SOFT; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   for (i = 0; limits[i].option > 0; i++) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |       if (get_limit (i, &softlim, &hardlim) == 0) | 
					
						
							|  |  |  | 	printone (i, (mode & LIMIT_SOFT) ? softlim : hardlim, 1); | 
					
						
							|  |  |  |       else if (errno != EINVAL) | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 	builtin_error ("%s: cannot get limit: %s", limits[i].description, | 
					
						
							|  |  |  | 						   strerror (errno)); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | printone (limind, curlim, pdesc) | 
					
						
							|  |  |  |      int limind; | 
					
						
							|  |  |  |      RLIMTYPE curlim; | 
					
						
							|  |  |  |      int pdesc; | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   char unitstr[64]; | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   int factor; | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |   factor = BLOCKSIZE(limits[limind].block_factor); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (pdesc) | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       if (limits[limind].units) | 
					
						
							|  |  |  | 	sprintf (unitstr, "(%s, -%c) ", limits[limind].units, limits[limind].option); | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         sprintf (unitstr, "(-%c) ", limits[limind].option); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-07 14:08:12 +00:00
										 |  |  |       printf ("%-20s %16s", limits[limind].description, unitstr); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   if (curlim == RLIM_INFINITY) | 
					
						
							|  |  |  |     puts ("unlimited"); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  |   else if (curlim == RLIM_SAVED_MAX) | 
					
						
							|  |  |  |     puts ("hard"); | 
					
						
							|  |  |  |   else if (curlim == RLIM_SAVED_CUR) | 
					
						
							|  |  |  |     puts ("soft"); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  |     print_rlimtype ((curlim / factor), 1); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Set all limits to NEWLIM.  NEWLIM currently must be RLIM_INFINITY, which | 
					
						
							|  |  |  |    causes all limits to be set as high as possible depending on mode (like | 
					
						
							|  |  |  |    csh `unlimit').  Returns -1 if NEWLIM is invalid, 0 if all limits | 
					
						
							|  |  |  |    were set successfully, and 1 if at least one limit could not be set. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    To raise all soft limits to their corresponding hard limits, use | 
					
						
							|  |  |  | 	ulimit -S -a unlimited | 
					
						
							|  |  |  |    To attempt to raise all hard limits to infinity (superuser-only), use | 
					
						
							|  |  |  | 	ulimit -H -a unlimited | 
					
						
							|  |  |  |    To attempt to raise all soft and hard limits to infinity, use | 
					
						
							|  |  |  | 	ulimit -a unlimited | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | set_all_limits (mode, newlim) | 
					
						
							|  |  |  |      int mode; | 
					
						
							|  |  |  |      RLIMTYPE newlim; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   register int i; | 
					
						
							|  |  |  |   int retval = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (newlim != RLIM_INFINITY) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       errno = EINVAL; | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (mode == 0) | 
					
						
							|  |  |  |     mode = LIMIT_SOFT|LIMIT_HARD; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (retval = i = 0; limits[i].option > 0; i++) | 
					
						
							|  |  |  |     if (set_limit (i, newlim, mode) < 0) | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2009-01-12 13:36:28 +00:00
										 |  |  | 	builtin_error (_("%s: cannot modify limit: %s"), limits[i].description, | 
					
						
							| 
									
										
										
										
											2002-07-17 14:10:11 +00:00
										 |  |  | 						      strerror (errno)); | 
					
						
							| 
									
										
										
										
											2001-11-13 17:56:06 +00:00
										 |  |  | 	retval = 1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |   return retval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 19:52:44 +00:00
										 |  |  | #endif /* !_MINIX */ |