29 #include <sys/resource.h> 35 #define VMEM_DEF RLIMIT_AS 38 #define VMEM_DEF RLIMIT_VMEM 48 { RLIMIT_CPU,
"-t",
"cpu time",
"time" },
49 { RLIMIT_FSIZE,
"-f",
"file size" ,
"file" },
50 { RLIMIT_DATA,
"-d",
"program data segment",
"data" },
51 { RLIMIT_STACK,
"-s",
"program stack size",
"stack" },
52 { RLIMIT_CORE,
"-c",
"core file size",
"core" },
54 { RLIMIT_RSS,
"-m",
"resident memory",
"memory" },
55 { RLIMIT_MEMLOCK,
"-l",
"amount of memory locked into RAM",
"locked" },
58 { RLIMIT_NPROC,
"-u",
"number of processes",
"processes" },
60 { RLIMIT_NOFILE,
"-n",
"number of file descriptors",
"descriptors" },
62 { VMEM_DEF,
"-v",
"virtual memory",
"virtual" },
76 static const char *
str2desc(
const char *
string)
89 int wordlen = strlen(a->
word);
105 struct rlimit rlimit = { 0, 0 };
111 "Usage: ulimit {data|" 126 "core|descriptors} [<num>]\n" 127 " Shows or sets the corresponding resource limit.\n" 128 " data Process data segment [readonly]\n" 130 " lock Memory lock size [readonly]\n" 134 " memory Process resident memory [readonly]\n" 136 " stack Process stack size [readonly]\n" 137 " time CPU usage [readonly]\n" 139 " processes Child processes\n" 142 " virtual Process virtual memory [readonly]\n" 144 " core Core dump file size\n" 145 " descriptors Number of file descriptors\n";
156 const char *
const newargv[2] = {
"ulimit", arg2 };
165 if (resource == -1) {
173 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) {
175 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) {
177 ast_cli(a->
fd,
"Resource not permitted to be set\n");
181 sscanf(a->
argv[2],
"%30d", &x);
182 rlimit.rlim_max = rlimit.rlim_cur = x;
183 setrlimit(resource, &rlimit);
186 if (!getrlimit(resource, &rlimit)) {
189 if (rlimit.rlim_max == RLIM_INFINITY)
190 ast_copy_string(printlimit,
"effectively unlimited",
sizeof(printlimit));
192 snprintf(printlimit,
sizeof(printlimit),
"limited to %d", (
int) rlimit.rlim_cur);
194 ast_cli(a->
fd,
"%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, a->
argv[1], printlimit);
#define AST_CLI_DEFINE(fn, txt,...)
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
descriptor for a cli entry.
static struct ast_cli_entry cli_ulimit
#define ast_strdup(str)
A wrapper for strdup()
void ast_cli(int fd, const char *fmt,...)
static int unload_module(void)
#define ast_cli_register(e)
Registers a command or an array of commands.
static const char * str2desc(const char *string)
static int str2limit(const char *string)
static char * handle_cli_ulimit(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Module has failed to load, may be in an inconsistent state.
static char * complete_ulimit(struct ast_cli_args *a)
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static int load_module(void)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.