Definition at line 102 of file res_limit.c.
References ast_cli_args::argc, ast_cli_args::argv, ARRAY_LEN, ast_cli(), ast_copy_string(), CLI_FAILURE, CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, limits::clicmd, ast_cli_entry::command, complete_ulimit(), limits::desc, errno, ast_cli_args::fd, NULL, limits::resource, str2desc(), str2limit(), and ast_cli_entry::usage.
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);
void ast_cli(int fd, const char *fmt,...)
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)
static char * complete_ulimit(struct ast_cli_args *a)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.