2005-10-24 15:26:25 +00:00
|
|
|
|
/** \file builtin_ulimit.c Functions defining the ulimit builtin
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
2012-11-18 10:23:22 +00:00
|
|
|
|
Functions used for implementing the ulimit builtin.
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
|
|
|
|
*/
|
2006-03-29 00:14:50 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2005-10-14 22:33:01 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
#include <wctype.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/resource.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2006-02-28 13:17:16 +00:00
|
|
|
|
#include "fallback.h"
|
2005-10-14 22:33:01 +00:00
|
|
|
|
#include "util.h"
|
2006-02-28 13:17:16 +00:00
|
|
|
|
|
2005-10-14 22:33:01 +00:00
|
|
|
|
#include "builtin.h"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "wgetopt.h"
|
2006-07-19 22:55:49 +00:00
|
|
|
|
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Struct describing a resource limit
|
|
|
|
|
*/
|
2005-10-14 22:33:01 +00:00
|
|
|
|
struct resource_t
|
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
/**
|
|
|
|
|
Resource id
|
|
|
|
|
*/
|
|
|
|
|
int resource;
|
|
|
|
|
/**
|
|
|
|
|
Description of resource
|
|
|
|
|
*/
|
|
|
|
|
const wchar_t *desc;
|
|
|
|
|
/**
|
|
|
|
|
Switch used on commandline to specify resource
|
|
|
|
|
*/
|
|
|
|
|
wchar_t switch_char;
|
|
|
|
|
/**
|
|
|
|
|
The implicit multiplier used when setting getting values
|
|
|
|
|
*/
|
|
|
|
|
int multiplier;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
2012-11-19 00:30:30 +00:00
|
|
|
|
;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Array of resource_t structs, describing all known resource types.
|
|
|
|
|
*/
|
2010-10-08 00:43:57 +00:00
|
|
|
|
static const struct resource_t resource_arr[] =
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_CORE, L"Maximum size of core files created", L'c', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
RLIMIT_DATA, L"Maximum size of a process’s data segment", L'd', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
RLIMIT_FSIZE, L"Maximum size of files created by the shell", L'f', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
2006-05-19 15:14:43 +00:00
|
|
|
|
#ifdef RLIMIT_MEMLOCK
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_MEMLOCK, L"Maximum size that may be locked into memory", L'l', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
2006-05-19 15:14:43 +00:00
|
|
|
|
#ifdef RLIMIT_RSS
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_RSS, L"Maximum resident set size", L'm', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_NOFILE, L"Maximum number of open file descriptors", L'n', 1
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
RLIMIT_STACK, L"Maximum stack size", L's', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
RLIMIT_CPU, L"Maximum amount of cpu time in seconds", L't', 1
|
|
|
|
|
}
|
|
|
|
|
,
|
2006-05-19 15:14:43 +00:00
|
|
|
|
#ifdef RLIMIT_NPROC
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_NPROC, L"Maximum number of processes available to a single user", L'u', 1
|
|
|
|
|
}
|
|
|
|
|
,
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
2006-05-19 15:14:43 +00:00
|
|
|
|
#ifdef RLIMIT_AS
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
RLIMIT_AS, L"Maximum amount of virtual memory available to the shell", L'v', 1024
|
|
|
|
|
}
|
|
|
|
|
,
|
2005-10-17 13:36:57 +00:00
|
|
|
|
#endif
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
0, 0, 0, 0
|
|
|
|
|
}
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
2012-11-19 00:30:30 +00:00
|
|
|
|
;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Get the implicit multiplication factor for the specified resource limit
|
|
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
|
static int get_multiplier(int what)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int i;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
for (i=0; resource_arr[i].desc; i++)
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (resource_arr[i].resource == what)
|
|
|
|
|
{
|
|
|
|
|
return resource_arr[i].multiplier;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return -1;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
2007-01-12 15:00:17 +00:00
|
|
|
|
Return the value for the specified resource limit. This function
|
|
|
|
|
does _not_ multiply the limit value by the multiplier constant used
|
|
|
|
|
by the commandline ulimit.
|
2005-10-24 15:26:25 +00:00
|
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
|
static rlim_t get(int resource, int hard)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
struct rlimit ls;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
getrlimit(resource, &ls);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return hard ? ls.rlim_max:ls.rlim_cur;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Print the value of the specified resource limit
|
|
|
|
|
*/
|
2015-09-21 18:24:49 +00:00
|
|
|
|
static void print(int resource, int hard, io_streams_t &streams)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
rlim_t l = get(resource, hard);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (l == RLIM_INFINITY)
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.out.append(L"unlimited\n");
|
2012-11-19 00:30:30 +00:00
|
|
|
|
else
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.out.append_format( L"%d\n", l / get_multiplier(resource));
|
2005-10-14 22:33:01 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Print values of all resource limits
|
|
|
|
|
*/
|
2015-09-21 18:24:49 +00:00
|
|
|
|
static void print_all(int hard, io_streams_t &streams)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int i;
|
|
|
|
|
int w=0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
for (i=0; resource_arr[i].desc; i++)
|
|
|
|
|
{
|
2014-09-26 01:04:11 +00:00
|
|
|
|
w=maxi(w, fish_wcswidth(resource_arr[i].desc));
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
for (i=0; resource_arr[i].desc; i++)
|
|
|
|
|
{
|
|
|
|
|
struct rlimit ls;
|
|
|
|
|
rlim_t l;
|
|
|
|
|
getrlimit(resource_arr[i].resource, &ls);
|
|
|
|
|
l = hard ? ls.rlim_max:ls.rlim_cur;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
const wchar_t *unit = ((resource_arr[i].resource==RLIMIT_CPU)?L"(seconds, ":(get_multiplier(resource_arr[i].resource)==1?L"(":L"(kB, "));
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.out.append_format(
|
2012-11-19 00:30:30 +00:00
|
|
|
|
L"%-*ls %10ls-%lc) ",
|
|
|
|
|
w,
|
|
|
|
|
resource_arr[i].desc,
|
|
|
|
|
unit,
|
|
|
|
|
resource_arr[i].switch_char);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (l == RLIM_INFINITY)
|
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.out.append(L"unlimited\n");
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.out.append_format( L"%d\n", l/get_multiplier(resource_arr[i].resource));
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
|
|
|
|
Returns the description for the specified resource limit
|
|
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
|
static const wchar_t *get_desc(int what)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int i;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
for (i=0; resource_arr[i].desc; i++)
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (resource_arr[i].resource == what)
|
|
|
|
|
{
|
|
|
|
|
return resource_arr[i].desc;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return L"Not a resource";
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-24 15:26:25 +00:00
|
|
|
|
/**
|
2007-01-12 15:00:17 +00:00
|
|
|
|
Set the new value of the specified resource limit. This function
|
|
|
|
|
does _not_ multiply the limit value by the multiplier constant used
|
|
|
|
|
by the commandline ulimit.
|
2005-10-24 15:26:25 +00:00
|
|
|
|
*/
|
2015-09-21 18:24:49 +00:00
|
|
|
|
static int set(int resource, int hard, int soft, rlim_t value, io_streams_t &streams)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
struct rlimit ls;
|
|
|
|
|
getrlimit(resource, &ls);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (hard)
|
|
|
|
|
{
|
|
|
|
|
ls.rlim_max = value;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (soft)
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
ls.rlim_cur = value;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Do not attempt to set the soft limit higher than the hard limit
|
|
|
|
|
*/
|
|
|
|
|
if ((value == RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY) ||
|
|
|
|
|
(value != RLIM_INFINITY && ls.rlim_max != RLIM_INFINITY && value > ls.rlim_max))
|
|
|
|
|
{
|
|
|
|
|
ls.rlim_cur = ls.rlim_max;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (setrlimit(resource, &ls))
|
|
|
|
|
{
|
|
|
|
|
if (errno == EPERM)
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.err.append_format(L"ulimit: Permission denied when changing resource of type '%ls'\n", get_desc(resource));
|
2012-11-19 00:30:30 +00:00
|
|
|
|
else
|
2015-09-21 18:24:49 +00:00
|
|
|
|
builtin_wperror(L"ulimit", streams);
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-13 13:43:28 +00:00
|
|
|
|
/**
|
|
|
|
|
The ulimit builtin, used for setting resource limits. Defined in
|
|
|
|
|
builtin_ulimit.c.
|
|
|
|
|
*/
|
2015-09-21 18:24:49 +00:00
|
|
|
|
static int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv)
|
2005-10-14 22:33:01 +00:00
|
|
|
|
{
|
2015-07-26 01:16:00 +00:00
|
|
|
|
wgetopter_t w;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int hard=0;
|
|
|
|
|
int soft=0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int what = RLIMIT_FSIZE;
|
|
|
|
|
int report_all = 0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int argc = builtin_count_args(argv);
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2015-07-26 01:16:00 +00:00
|
|
|
|
w.woptind=0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
static const struct woption
|
|
|
|
|
long_options[] =
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
|
|
|
|
L"all", no_argument, 0, 'a'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"hard", no_argument, 0, 'H'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"soft", no_argument, 0, 'S'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"core-size", no_argument, 0, 'c'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"data-size", no_argument, 0, 'd'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"file-size", no_argument, 0, 'f'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"lock-size", no_argument, 0, 'l'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"resident-set-size", no_argument, 0, 'm'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"file-descriptor-count", no_argument, 0, 'n'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"stack-size", no_argument, 0, 's'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"cpu-time", no_argument, 0, 't'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"process-count", no_argument, 0, 'u'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"virtual-memory-size", no_argument, 0, 'v'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
L"help", no_argument, 0, 'h'
|
|
|
|
|
}
|
|
|
|
|
,
|
|
|
|
|
{
|
|
|
|
|
0, 0, 0, 0
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
2012-11-19 00:30:30 +00:00
|
|
|
|
;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
int opt_index = 0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2015-07-26 01:16:00 +00:00
|
|
|
|
int opt = w.wgetopt_long(argc,
|
|
|
|
|
argv,
|
|
|
|
|
L"aHScdflmnstuvh",
|
|
|
|
|
long_options,
|
|
|
|
|
&opt_index);
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (opt == -1)
|
|
|
|
|
break;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
switch (opt)
|
|
|
|
|
{
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case 0:
|
|
|
|
|
if (long_options[opt_index].flag != 0)
|
|
|
|
|
break;
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.err.append_format(BUILTIN_ERR_UNKNOWN,
|
2012-11-19 08:31:03 +00:00
|
|
|
|
argv[0],
|
|
|
|
|
long_options[opt_index].name);
|
2015-09-21 18:24:49 +00:00
|
|
|
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
return 1;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'a':
|
|
|
|
|
report_all=1;
|
|
|
|
|
break;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'H':
|
|
|
|
|
hard=1;
|
|
|
|
|
break;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'S':
|
|
|
|
|
soft=1;
|
|
|
|
|
break;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'c':
|
|
|
|
|
what=RLIMIT_CORE;
|
|
|
|
|
break;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'd':
|
|
|
|
|
what=RLIMIT_DATA;
|
|
|
|
|
break;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'f':
|
|
|
|
|
what=RLIMIT_FSIZE;
|
|
|
|
|
break;
|
2006-05-26 11:19:34 +00:00
|
|
|
|
#ifdef RLIMIT_MEMLOCK
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'l':
|
|
|
|
|
what=RLIMIT_MEMLOCK;
|
|
|
|
|
break;
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-11-18 10:23:22 +00:00
|
|
|
|
#ifdef RLIMIT_RSS
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'm':
|
|
|
|
|
what=RLIMIT_RSS;
|
|
|
|
|
break;
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'n':
|
|
|
|
|
what=RLIMIT_NOFILE;
|
|
|
|
|
break;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L's':
|
|
|
|
|
what=RLIMIT_STACK;
|
|
|
|
|
break;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L't':
|
|
|
|
|
what=RLIMIT_CPU;
|
|
|
|
|
break;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
|
|
|
|
#ifdef RLIMIT_NPROC
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'u':
|
|
|
|
|
what=RLIMIT_NPROC;
|
|
|
|
|
break;
|
2005-11-24 11:13:21 +00:00
|
|
|
|
#endif
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
|
|
|
|
#ifdef RLIMIT_AS
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'v':
|
|
|
|
|
what=RLIMIT_AS;
|
|
|
|
|
break;
|
2005-10-17 13:36:57 +00:00
|
|
|
|
#endif
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'h':
|
2015-09-21 18:24:49 +00:00
|
|
|
|
builtin_print_help(parser, streams, argv[0], streams.out);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
return 0;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case L'?':
|
2015-09-21 18:24:49 +00:00
|
|
|
|
builtin_unknown_option(parser, streams, argv[0], argv[w.woptind-1]);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
return 1;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
if (report_all)
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2015-07-26 01:16:00 +00:00
|
|
|
|
if (argc - w.woptind == 0)
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
print_all(hard, streams);
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.err.append(argv[0]);
|
|
|
|
|
streams.err.append(L": Too many arguments\n");
|
|
|
|
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2015-07-26 01:16:00 +00:00
|
|
|
|
switch (argc - w.woptind)
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case 0:
|
2012-11-18 10:23:22 +00:00
|
|
|
|
{
|
2012-11-19 08:31:03 +00:00
|
|
|
|
/*
|
|
|
|
|
Show current limit value
|
|
|
|
|
*/
|
2015-09-21 18:24:49 +00:00
|
|
|
|
print(what, hard, streams);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
break;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-19 08:31:03 +00:00
|
|
|
|
case 1:
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
2012-11-19 08:31:03 +00:00
|
|
|
|
/*
|
|
|
|
|
Change current limit value
|
|
|
|
|
*/
|
|
|
|
|
rlim_t new_limit;
|
|
|
|
|
wchar_t *end;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Set both hard and soft limits if nothing else was specified
|
|
|
|
|
*/
|
|
|
|
|
if (!(hard+soft))
|
2012-11-19 00:30:30 +00:00
|
|
|
|
{
|
2012-11-19 08:31:03 +00:00
|
|
|
|
hard=soft=1;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-26 01:16:00 +00:00
|
|
|
|
if (wcscasecmp(argv[w.woptind], L"unlimited")==0)
|
2012-11-19 08:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
new_limit = RLIM_INFINITY;
|
|
|
|
|
}
|
2015-07-26 01:16:00 +00:00
|
|
|
|
else if (wcscasecmp(argv[w.woptind], L"hard")==0)
|
2012-11-19 08:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
new_limit = get(what, 1);
|
|
|
|
|
}
|
2015-07-26 01:16:00 +00:00
|
|
|
|
else if (wcscasecmp(argv[w.woptind], L"soft")==0)
|
2012-11-19 08:31:03 +00:00
|
|
|
|
{
|
|
|
|
|
new_limit = get(what, soft);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
errno=0;
|
2015-07-26 01:16:00 +00:00
|
|
|
|
new_limit = wcstol(argv[w.woptind], &end, 10);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
if (errno || *end)
|
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.err.append_format(L"%ls: Invalid limit '%ls'\n",
|
2012-11-19 08:31:03 +00:00
|
|
|
|
argv[0],
|
2015-07-26 01:16:00 +00:00
|
|
|
|
argv[w.woptind]);
|
2015-09-21 18:24:49 +00:00
|
|
|
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
new_limit *= get_multiplier(what);
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2015-09-21 18:24:49 +00:00
|
|
|
|
return set(what, hard, soft, new_limit, streams);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
{
|
2015-09-21 18:24:49 +00:00
|
|
|
|
streams.err.append(argv[0]);
|
|
|
|
|
streams.err.append(L": Too many arguments\n");
|
|
|
|
|
builtin_print_help(parser, streams, argv[0], streams.err);
|
2012-11-19 08:31:03 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
2005-10-14 22:33:01 +00:00
|
|
|
|
}
|