#include "asterisk.h"
#include <ctype.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "asterisk/module.h"
#include "asterisk/cli.h"
Go to the source code of this file.
Data Structures | |
struct | limits |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static char * | complete_ulimit (struct ast_cli_args *a) |
static char * | handle_cli_ulimit (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | load_module (void) |
static const char * | str2desc (const char *string) |
static int | str2limit (const char *string) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Resource limits" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_ulimit |
Definition in file res_limit.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 217 of file res_limit.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 217 of file res_limit.c.
static char* complete_ulimit | ( | struct ast_cli_args * | a | ) | [static] |
Definition at line 88 of file res_limit.c.
References ARRAY_LEN, ast_strdup, ast_cli_args::n, ast_cli_args::pos, and ast_cli_args::word.
Referenced by handle_cli_ulimit().
00089 { 00090 int which = 0, i; 00091 int wordlen = strlen(a->word); 00092 00093 if (a->pos > 1) 00094 return NULL; 00095 for (i = 0; i < ARRAY_LEN(limits); i++) { 00096 if (!strncasecmp(limits[i].clicmd, a->word, wordlen)) { 00097 if (++which > a->n) 00098 return ast_strdup(limits[i].clicmd); 00099 } 00100 } 00101 return NULL; 00102 }
static char* handle_cli_ulimit | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Definition at line 104 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, ast_cli_entry::command, complete_ulimit(), desc, errno, ast_cli_args::fd, str2desc(), str2limit(), and ast_cli_entry::usage.
00105 { 00106 int resource; 00107 struct rlimit rlimit = { 0, 0 }; 00108 00109 switch (cmd) { 00110 case CLI_INIT: 00111 e->command = "ulimit"; 00112 e->usage = 00113 "Usage: ulimit {data|" 00114 #ifdef RLIMIT_RSS 00115 "limit|" 00116 #endif 00117 "file|" 00118 #ifdef RLIMIT_RSS 00119 "memory|" 00120 #endif 00121 "stack|time|" 00122 #ifdef RLIMIT_NPROC 00123 "processes|" 00124 #endif 00125 #ifdef VMEM_DEF 00126 "virtual|" 00127 #endif 00128 "core|descriptors} [<num>]\n" 00129 " Shows or sets the corresponding resource limit.\n" 00130 " data Process data segment [readonly]\n" 00131 #ifdef RLIMIT_RSS 00132 " lock Memory lock size [readonly]\n" 00133 #endif 00134 " file File size\n" 00135 #ifdef RLIMIT_RSS 00136 " memory Process resident memory [readonly]\n" 00137 #endif 00138 " stack Process stack size [readonly]\n" 00139 " time CPU usage [readonly]\n" 00140 #ifdef RLIMIT_NPROC 00141 " processes Child processes\n" 00142 #endif 00143 #ifdef VMEM_DEF 00144 " virtual Process virtual memory [readonly]\n" 00145 #endif 00146 " core Core dump file size\n" 00147 " descriptors Number of file descriptors\n"; 00148 return NULL; 00149 case CLI_GENERATE: 00150 return complete_ulimit(a); 00151 } 00152 00153 if (a->argc > 3) 00154 return CLI_SHOWUSAGE; 00155 00156 if (a->argc == 1) { 00157 char arg2[15]; 00158 const char * const newargv[2] = { "ulimit", arg2 }; 00159 for (resource = 0; resource < ARRAY_LEN(limits); resource++) { 00160 struct ast_cli_args newArgs = { .argv = newargv, .argc = 2 }; 00161 ast_copy_string(arg2, limits[resource].clicmd, sizeof(arg2)); 00162 handle_cli_ulimit(e, CLI_HANDLER, &newArgs); 00163 } 00164 return CLI_SUCCESS; 00165 } else { 00166 resource = str2limit(a->argv[1]); 00167 if (resource == -1) { 00168 ast_cli(a->fd, "Unknown resource\n"); 00169 return CLI_FAILURE; 00170 } 00171 00172 if (a->argc == 3) { 00173 int x; 00174 #ifdef RLIMIT_NPROC 00175 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) { 00176 #else 00177 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) { 00178 #endif 00179 ast_cli(a->fd, "Resource not permitted to be set\n"); 00180 return CLI_FAILURE; 00181 } 00182 00183 sscanf(a->argv[2], "%30d", &x); 00184 rlimit.rlim_max = rlimit.rlim_cur = x; 00185 setrlimit(resource, &rlimit); 00186 return CLI_SUCCESS; 00187 } else { 00188 if (!getrlimit(resource, &rlimit)) { 00189 char printlimit[32]; 00190 const char *desc; 00191 if (rlimit.rlim_max == RLIM_INFINITY) 00192 ast_copy_string(printlimit, "effectively unlimited", sizeof(printlimit)); 00193 else 00194 snprintf(printlimit, sizeof(printlimit), "limited to %d", (int) rlimit.rlim_cur); 00195 desc = str2desc(a->argv[1]); 00196 ast_cli(a->fd, "%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, a->argv[1], printlimit); 00197 } else 00198 ast_cli(a->fd, "Could not retrieve resource limits for %s: %s\n", str2desc(a->argv[1]), strerror(errno)); 00199 return CLI_SUCCESS; 00200 } 00201 } 00202 }
static int load_module | ( | void | ) | [static] |
Definition at line 212 of file res_limit.c.
References ast_cli_register(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, and cli_ulimit.
00213 { 00214 return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; 00215 }
static const char* str2desc | ( | const char * | string | ) | [static] |
Definition at line 78 of file res_limit.c.
References ARRAY_LEN.
Referenced by handle_cli_ulimit().
00079 { 00080 size_t i; 00081 for (i = 0; i < ARRAY_LEN(limits); i++) { 00082 if (!strcmp(string, limits[i].clicmd)) 00083 return limits[i].desc; 00084 } 00085 return "<unknown>"; 00086 }
static int str2limit | ( | const char * | string | ) | [static] |
Definition at line 68 of file res_limit.c.
References ARRAY_LEN.
Referenced by handle_cli_ulimit().
00069 { 00070 size_t i; 00071 for (i = 0; i < ARRAY_LEN(limits); i++) { 00072 if (!strcasecmp(string, limits[i].clicmd)) 00073 return limits[i].resource; 00074 } 00075 return -1; 00076 }
static int unload_module | ( | void | ) | [static] |
Definition at line 207 of file res_limit.c.
References ast_cli_unregister(), and cli_ulimit.
00208 { 00209 return ast_cli_unregister(&cli_ulimit); 00210 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Resource limits" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 217 of file res_limit.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 217 of file res_limit.c.
struct ast_cli_entry cli_ulimit [static] |
Initial value:
{ .handler = handle_cli_ulimit , .summary = "Set or show process resource limits" ,__VA_ARGS__ }
Definition at line 204 of file res_limit.c.
Referenced by load_module(), and unload_module().