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" },
70 if (!strcasecmp(
string,
limits[i].clicmd))
80 if (!strcmp(
string,
limits[i].clicmd))
89 int wordlen = strlen(
a->word);
94 if (!strncasecmp(
limits[i].clicmd,
a->word, wordlen)) {
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) {
166 ast_cli(
a->fd,
"Unknown resource\n");
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);
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
Standard Command Line Interface.
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
#define ast_cli_register(e)
Registers a command or an array of commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
static const char * str2desc(const char *string)
static struct ast_cli_entry cli_ulimit
static char * handle_cli_ulimit(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * complete_ulimit(struct ast_cli_args *a)
static int load_module(void)
static int unload_module(void)
static int str2limit(const char *string)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
descriptor for a cli entry.