#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 |
Defines | |
#define | _XOPEN_SOURCE 600 |
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_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_ulimit |
Definition in file res_limit.c.
#define _XOPEN_SOURCE 600 |
Definition at line 26 of file res_limit.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 215 of file res_limit.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 215 of file res_limit.c.
static char* complete_ulimit | ( | struct ast_cli_args * | a | ) | [static] |
Definition at line 86 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().
00087 { 00088 int which = 0, i; 00089 int wordlen = strlen(a->word); 00090 00091 if (a->pos > 1) 00092 return NULL; 00093 for (i = 0; i < ARRAY_LEN(limits); i++) { 00094 if (!strncasecmp(limits[i].limit, a->word, wordlen)) { 00095 if (++which > a->n) 00096 return ast_strdup(limits[i].limit); 00097 } 00098 } 00099 return NULL; 00100 }
static char* handle_cli_ulimit | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
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, ast_cli_entry::command, complete_ulimit(), desc, errno, ast_cli_args::fd, str2desc(), str2limit(), and ast_cli_entry::usage.
00103 { 00104 int resource; 00105 struct rlimit rlimit = { 0, 0 }; 00106 00107 switch (cmd) { 00108 case CLI_INIT: 00109 e->command = "ulimit"; 00110 e->usage = 00111 "Usage: ulimit {-d|" 00112 #ifdef RLIMIT_RSS 00113 "-l|" 00114 #endif 00115 "-f|" 00116 #ifdef RLIMIT_RSS 00117 "-m|" 00118 #endif 00119 "-s|-t|" 00120 #ifdef RLIMIT_NPROC 00121 "-u|" 00122 #endif 00123 #ifdef VMEM_DEF 00124 "-v|" 00125 #endif 00126 "-c|-n} [<num>]\n" 00127 " Shows or sets the corresponding resource limit.\n" 00128 " -d Process data segment [readonly]\n" 00129 #ifdef RLIMIT_RSS 00130 " -l Memory lock size [readonly]\n" 00131 #endif 00132 " -f File size\n" 00133 #ifdef RLIMIT_RSS 00134 " -m Process resident memory [readonly]\n" 00135 #endif 00136 " -s Process stack size [readonly]\n" 00137 " -t CPU usage [readonly]\n" 00138 #ifdef RLIMIT_NPROC 00139 " -u Child processes\n" 00140 #endif 00141 #ifdef VMEM_DEF 00142 " -v Process virtual memory [readonly]\n" 00143 #endif 00144 " -c Core dump file size\n" 00145 " -n Number of file descriptors\n"; 00146 return NULL; 00147 case CLI_GENERATE: 00148 return complete_ulimit(a); 00149 } 00150 00151 if (a->argc > 3) 00152 return CLI_SHOWUSAGE; 00153 00154 if (a->argc == 1) { 00155 char arg2[3]; 00156 char *newargv[2] = { "ulimit", arg2 }; 00157 for (resource = 0; resource < ARRAY_LEN(limits); resource++) { 00158 struct ast_cli_args newArgs = { .argv = newargv, .argc = 2 }; 00159 ast_copy_string(arg2, limits[resource].limit, sizeof(arg2)); 00160 handle_cli_ulimit(e, CLI_HANDLER, &newArgs); 00161 } 00162 return CLI_SUCCESS; 00163 } else { 00164 resource = str2limit(a->argv[1]); 00165 if (resource == -1) { 00166 ast_cli(a->fd, "Unknown resource\n"); 00167 return CLI_FAILURE; 00168 } 00169 00170 if (a->argc == 3) { 00171 int x; 00172 #ifdef RLIMIT_NPROC 00173 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) { 00174 #else 00175 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) { 00176 #endif 00177 ast_cli(a->fd, "Resource not permitted to be set\n"); 00178 return CLI_FAILURE; 00179 } 00180 00181 sscanf(a->argv[2], "%d", &x); 00182 rlimit.rlim_max = rlimit.rlim_cur = x; 00183 setrlimit(resource, &rlimit); 00184 return CLI_SUCCESS; 00185 } else { 00186 if (!getrlimit(resource, &rlimit)) { 00187 char printlimit[32]; 00188 const char *desc; 00189 if (rlimit.rlim_max == RLIM_INFINITY) 00190 ast_copy_string(printlimit, "effectively unlimited", sizeof(printlimit)); 00191 else 00192 snprintf(printlimit, sizeof(printlimit), "limited to %d", (int) rlimit.rlim_cur); 00193 desc = str2desc(a->argv[1]); 00194 ast_cli(a->fd, "%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, a->argv[1], printlimit); 00195 } else 00196 ast_cli(a->fd, "Could not retrieve resource limits for %s: %s\n", str2desc(a->argv[1]), strerror(errno)); 00197 return CLI_SUCCESS; 00198 } 00199 } 00200 }
static int load_module | ( | void | ) | [static] |
Definition at line 210 of file res_limit.c.
References ast_cli_register(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, and cli_ulimit.
00211 { 00212 return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; 00213 }
static const char* str2desc | ( | const char * | string | ) | [static] |
Definition at line 76 of file res_limit.c.
References ARRAY_LEN.
Referenced by handle_cli_ulimit().
00077 { 00078 size_t i; 00079 for (i = 0; i < ARRAY_LEN(limits); i++) { 00080 if (!strcmp(string, limits[i].limit)) 00081 return limits[i].desc; 00082 } 00083 return "<unknown>"; 00084 }
static int str2limit | ( | const char * | string | ) | [static] |
Definition at line 66 of file res_limit.c.
References ARRAY_LEN.
Referenced by handle_cli_ulimit().
00067 { 00068 size_t i; 00069 for (i = 0; i < ARRAY_LEN(limits); i++) { 00070 if (!strcasecmp(string, limits[i].limit)) 00071 return limits[i].resource; 00072 } 00073 return -1; 00074 }
static int unload_module | ( | void | ) | [static] |
Definition at line 205 of file res_limit.c.
References ast_cli_unregister(), and cli_ulimit.
00206 { 00207 return ast_cli_unregister(&cli_ulimit); 00208 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 215 of file res_limit.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 215 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 202 of file res_limit.c.
Referenced by load_module(), and unload_module().