107 struct rlimit rlimit = { 0, 0 };
113 "Usage: ulimit {data|"
128 "core|descriptors} [<num>]\n"
129 " Shows or sets the corresponding resource limit.\n"
130 " data Process data segment [readonly]\n"
132 " lock Memory lock size [readonly]\n"
136 " memory Process resident memory [readonly]\n"
138 " stack Process stack size [readonly]\n"
139 " time CPU usage [readonly]\n"
141 " processes Child processes\n"
144 " virtual Process virtual memory [readonly]\n"
146 " core Core dump file size\n"
147 " descriptors Number of file descriptors\n";
158 const char *
const newargv[2] = {
"ulimit", arg2 };
167 if (resource == -1) {
175 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) {
177 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) {
179 ast_cli(a->
fd,
"Resource not permitted to be set\n");
183 sscanf(a->
argv[2],
"%30d", &x);
184 rlimit.rlim_max = rlimit.rlim_cur = x;
185 setrlimit(resource, &rlimit);
188 if (!getrlimit(resource, &rlimit)) {
191 if (rlimit.rlim_max == RLIM_INFINITY)
192 ast_copy_string(printlimit,
"effectively unlimited",
sizeof(printlimit));
194 snprintf(printlimit,
sizeof(printlimit),
"limited to %d", (
int) rlimit.rlim_cur);
196 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.