#include "asterisk.h"#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <ctype.h>#include <sys/time.h>#include <sys/resource.h>#include <errno.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 |
| #define | RLIMIT_AS RLIMIT_VMEM |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static char * | complete_ulimit (const char *line, const char *word, int pos, int state) |
| static int | load_module (void) |
| static int | my_ulimit (int fd, int argc, char **argv) |
| 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 | AST_MODFLAG_BUILDSUM, .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_cli_entry | cli_ulimit |
| static char | ulimit_usage [] |
| #define _XOPEN_SOURCE 600 |
Definition at line 19 of file res_limit.c.
| #define RLIMIT_AS RLIMIT_VMEM |
| static void __reg_module | ( | void | ) | [static] |
Definition at line 164 of file res_limit.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 164 of file res_limit.c.
| static char* complete_ulimit | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 122 of file res_limit.c.
References ast_strdup.
00123 { 00124 int which = 0, i; 00125 int wordlen = strlen(word); 00126 00127 if (pos > 2) 00128 return NULL; 00129 for (i = 0; i < sizeof(limits) / sizeof(limits[0]); i++) { 00130 if (!strncasecmp(limits[i].limit, word, wordlen)) { 00131 if (++which > state) 00132 return ast_strdup(limits[i].limit); 00133 } 00134 } 00135 return NULL; 00136 }
| static int load_module | ( | void | ) | [static] |
Definition at line 159 of file res_limit.c.
References ast_cli_register(), AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.
00160 { 00161 return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; 00162 }
| static int my_ulimit | ( | int | fd, | |
| int | argc, | |||
| char ** | argv | |||
| ) | [static] |
Definition at line 73 of file res_limit.c.
References ast_cli(), ast_copy_string(), desc, errno, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, str2desc(), and str2limit().
00074 { 00075 int resource; 00076 struct rlimit rlimit = { 0, 0 }; 00077 if (argc > 3) 00078 return RESULT_SHOWUSAGE; 00079 00080 if (argc == 1) { 00081 char arg2[3]; 00082 char *newargv[2] = { "ulimit", arg2 }; 00083 for (resource = 0; resource < sizeof(limits) / sizeof(limits[0]); resource++) { 00084 ast_copy_string(arg2, limits[resource].limit, sizeof(arg2)); 00085 my_ulimit(fd, 2, newargv); 00086 } 00087 return RESULT_SUCCESS; 00088 } else { 00089 resource = str2limit(argv[1]); 00090 if (resource == -1) { 00091 ast_cli(fd, "Unknown resource\n"); 00092 return RESULT_FAILURE; 00093 } 00094 00095 if (argc == 3) { 00096 if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) { 00097 ast_cli(fd, "Resource not permitted to be set\n"); 00098 return RESULT_FAILURE; 00099 } 00100 00101 sscanf(argv[2], "%d", (int *) &rlimit.rlim_cur); 00102 rlimit.rlim_max = rlimit.rlim_cur; 00103 setrlimit(resource, &rlimit); 00104 return RESULT_SUCCESS; 00105 } else { 00106 if (!getrlimit(resource, &rlimit)) { 00107 char printlimit[32]; 00108 const char *desc; 00109 if (rlimit.rlim_max == RLIM_INFINITY) 00110 ast_copy_string(printlimit, "effectively unlimited", sizeof(printlimit)); 00111 else 00112 snprintf(printlimit, sizeof(printlimit), "limited to %d", (int) rlimit.rlim_cur); 00113 desc = str2desc(argv[1]); 00114 ast_cli(fd, "%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, argv[1], printlimit); 00115 } else 00116 ast_cli(fd, "Could not retrieve resource limits for %s: %s\n", str2desc(argv[1]), strerror(errno)); 00117 return RESULT_SUCCESS; 00118 } 00119 } 00120 }
| static const char* str2desc | ( | const char * | string | ) | [static] |
Definition at line 63 of file res_limit.c.
References desc.
Referenced by my_ulimit().
00064 { 00065 size_t i; 00066 for (i = 0; i < sizeof(limits) / sizeof(limits[0]); i++) { 00067 if (!strcmp(string, limits[i].limit)) 00068 return limits[i].desc; 00069 } 00070 return "<unknown>"; 00071 }
| static int str2limit | ( | const char * | string | ) | [static] |
Definition at line 53 of file res_limit.c.
Referenced by my_ulimit().
00054 { 00055 size_t i; 00056 for (i = 0; i < sizeof(limits) / sizeof(limits[0]); i++) { 00057 if (!strcasecmp(string, limits[i].limit)) 00058 return limits[i].resource; 00059 } 00060 return -1; 00061 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 154 of file res_limit.c.
References ast_cli_unregister().
00155 { 00156 return ast_cli_unregister(&cli_ulimit); 00157 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 164 of file res_limit.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 164 of file res_limit.c.
struct ast_cli_entry cli_ulimit [static] |
Initial value:
{
{"ulimit", NULL}, my_ulimit,
"Set or show process resource limits", ulimit_usage, complete_ulimit
}
Definition at line 149 of file res_limit.c.
char ulimit_usage[] [static] |
Definition at line 138 of file res_limit.c.
1.5.9