aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-11 19:03:06 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-10-11 19:03:06 +0000
commit13b9c5237c9f5b8b3d72634d575665b1d1147ba3 (patch)
tree44dcb2c14abed6932db4f248b17626a01a38f59b /res
parenta8506328befc2a11643cea88772609610ec11c33 (diff)
Merge a ton of NEW_CLI conversions. Thanks to everyone that helped out! :)
(closes issue #10724) Reported by: eliel Patches: chan_skinny.c.patch uploaded by eliel (license 64) chan_oss.c.patch uploaded by eliel (license 64) chan_mgcp.c.patch2 uploaded by eliel (license 64) pbx_config.c.patch uploaded by seanbright (license 71) iax2-provision.c.patch uploaded by eliel (license 64) chan_gtalk.c.patch uploaded by eliel (license 64) pbx_ael.c.patch uploaded by seanbright (license 71) file.c.patch uploaded by seanbright (license 71) image.c.patch uploaded by seanbright (license 71) cli.c.patch uploaded by moy (license 222) astobj2.c.patch uploaded by moy (license 222) asterisk.c.patch uploaded by moy (license 222) res_limit.c.patch uploaded by seanbright (license 71) res_convert.c.patch uploaded by seanbright (license 71) res_crypto.c.patch uploaded by seanbright (license 71) app_osplookup.c.patch uploaded by seanbright (license 71) app_rpt.c.patch uploaded by seanbright (license 71) app_mixmonitor.c.patch uploaded by seanbright (license 71) channel.c.patch uploaded by seanbright (license 71) translate.c.patch uploaded by seanbright (license 71) udptl.c.patch uploaded by seanbright (license 71) threadstorage.c.patch uploaded by seanbright (license 71) db.c.patch uploaded by seanbright (license 71) cdr.c.patch uploaded by moy (license 222) pbd_dundi.c.patch uploaded by moy (license 222) app_osplookup-rev83558.patch uploaded by moy (license 222) res_clioriginate.c.patch uploaded by moy (license 222) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@85460 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_clioriginate.c135
-rw-r--r--res/res_convert.c58
-rw-r--r--res/res_crypto.c64
-rw-r--r--res/res_limit.c159
4 files changed, 227 insertions, 189 deletions
diff --git a/res/res_clioriginate.c b/res/res_clioriginate.c
index 8497f6387..7a9245aba 100644
--- a/res/res_clioriginate.c
+++ b/res/res_clioriginate.c
@@ -43,61 +43,35 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
/*! The timeout for originated calls, in seconds */
#define TIMEOUT 30
-static char orig_help[] =
-" There are two ways to use this command. A call can be originated between a\n"
-"channel and a specific application, or between a channel and an extension in\n"
-"the dialplan. This is similar to call files or the manager originate action.\n"
-"Calls originated with this command are given a timeout of 30 seconds.\n\n"
-
-"Usage1: originate <tech/data> application <appname> [appdata]\n"
-" This will originate a call between the specified channel tech/data and the\n"
-"given application. Arguments to the application are optional. If the given\n"
-"arguments to the application include spaces, all of the arguments to the\n"
-"application need to be placed in quotation marks.\n\n"
-
-"Usage2: originate <tech/data> extension [exten@][context]\n"
-" This will originate a call between the specified channel tech/data and the\n"
-"given extension. If no context is specified, the 'default' context will be\n"
-"used. If no extension is given, the 's' extension will be used.\n";
-
-static int handle_orig(int fd, int argc, char *argv[]);
-static char *complete_orig(const char *line, const char *word, int pos, int state);
-
-struct ast_cli_entry cli_cliorig[] = {
- { { "originate", NULL },
- handle_orig, "Originate a call",
- orig_help, complete_orig },
-};
-
/*!
* \brief orginate a call from the CLI
* \param fd file descriptor for cli
* \param chan channel to create type/data
* \param app application you want to run
* \param appdata data for application
- * \retval RESULT_SUCCESS on success.
- * \retval RESULT_SHOWUSAGE on failure.
+ * \retval CLI_SUCCESS on success.
+ * \retval CLI_SHOWUSAGE on failure.
*/
-static int orig_app(int fd, const char *chan, const char *app, const char *appdata)
+static char *orig_app(int fd, const char *chan, const char *app, const char *appdata)
{
char *chantech;
char *chandata;
int reason = 0;
if (ast_strlen_zero(app))
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
chandata = ast_strdupa(chan);
chantech = strsep(&chandata, "/");
if (!chandata) {
ast_cli(fd, "*** No data provided after channel type! ***\n");
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL, NULL);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*!
@@ -105,10 +79,10 @@ static int orig_app(int fd, const char *chan, const char *app, const char *appda
* \param fd file descriptor for cli
* \param chan channel to create type/data
* \param data contains exten\@context
- * \retval RESULT_SUCCESS on success.
- * \retval RESULT_SHOWUSAGE on failure.
+ * \retval CLI_SUCCESS on success.
+ * \retval CLI_SHOWUSAGE on failure.
*/
-static int orig_exten(int fd, const char *chan, const char *data)
+static char *orig_exten(int fd, const char *chan, const char *data)
{
char *chantech;
char *chandata;
@@ -121,7 +95,7 @@ static int orig_exten(int fd, const char *chan, const char *data)
chantech = strsep(&chandata, "/");
if (!chandata) {
ast_cli(fd, "*** No data provided after channel type! ***\n");
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
if (!ast_strlen_zero(data)) {
@@ -136,63 +110,74 @@ static int orig_exten(int fd, const char *chan, const char *data)
ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL, NULL);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*!
* \brief handle for orgination app or exten.
- * \param fd file descriptor
- * \param argc no of arguements
- * \param argv contains either application or extension arguements
- * \retval RESULT_SUCCESS on success.
- * \retval RESULT_SHOWUSAGE on failure.
+ * \param e pointer to the CLI structure to initialize
+ * \param cmd operation to execute
+ * \param a structure that contains either application or extension arguements
+ * \retval CLI_SUCCESS on success.
+ * \retval CLI_SHOWUSAGE on failure.
*/
-static int handle_orig(int fd, int argc, char *argv[])
+static char *handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- int res;
+ static char *choices[] = { "application", "extension", NULL };
+ char *res;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "originate";
+ e->usage =
+ " There are two ways to use this command. A call can be originated between a\n"
+ "channel and a specific application, or between a channel and an extension in\n"
+ "the dialplan. This is similar to call files or the manager originate action.\n"
+ "Calls originated with this command are given a timeout of 30 seconds.\n\n"
+
+ "Usage1: originate <tech/data> application <appname> [appdata]\n"
+ " This will originate a call between the specified channel tech/data and the\n"
+ "given application. Arguments to the application are optional. If the given\n"
+ "arguments to the application include spaces, all of the arguments to the\n"
+ "application need to be placed in quotation marks.\n\n"
+
+ "Usage2: originate <tech/data> extension [exten@][context]\n"
+ " This will originate a call between the specified channel tech/data and the\n"
+ "given extension. If no context is specified, the 'default' context will be\n"
+ "used. If no extension is given, the 's' extension will be used.\n";
+ return NULL;
+ case CLI_GENERATE:
+ if (a->pos != 2)
+ return NULL;
+
+ /* ugly, can be removed when CLI entries have ast_module pointers */
+ ast_module_ref(ast_module_info->self);
+ res = ast_cli_complete(a->word, choices, a->n);
+ ast_module_unref(ast_module_info->self);
- if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2]))
- return RESULT_SHOWUSAGE;
+ return res;
+ }
+
+ if (ast_strlen_zero(a->argv[1]) || ast_strlen_zero(a->argv[2]))
+ return CLI_SHOWUSAGE;
/* ugly, can be removed when CLI entries have ast_module pointers */
ast_module_ref(ast_module_info->self);
- if (!strcasecmp("application", argv[2])) {
- res = orig_app(fd, argv[1], argv[3], argv[4]);
- } else if (!strcasecmp("extension", argv[2])) {
- res = orig_exten(fd, argv[1], argv[3]);
+ if (!strcasecmp("application", a->argv[2])) {
+ res = orig_app(a->fd, a->argv[1], a->argv[3], a->argv[4]);
+ } else if (!strcasecmp("extension", a->argv[2])) {
+ res = orig_exten(a->fd, a->argv[1], a->argv[3]);
} else
- res = RESULT_SHOWUSAGE;
+ res = CLI_SHOWUSAGE;
ast_module_unref(ast_module_info->self);
return res;
}
-/*!
- * \brief complete suggestions for orginate command
- * \param line
- * \param word to be completed word
- * \param pos position
- * \param state
- * \retval completed word
- * \retval NULL on failure
-*/
-static char *complete_orig(const char *line, const char *word, int pos, int state)
-{
- static char *choices[] = { "application", "extension", NULL };
- char *ret;
-
- if (pos != 2)
- return NULL;
-
- /* ugly, can be removed when CLI entries have ast_module pointers */
- ast_module_ref(ast_module_info->self);
- ret = ast_cli_complete(word, choices, state);
- ast_module_unref(ast_module_info->self);
-
- return ret;
-}
+static struct ast_cli_entry cli_cliorig[] = {
+ NEW_CLI(handle_orig, "Originate a call"),
+};
/*! \brief Unload orginate module */
static int unload_module(void)
diff --git a/res/res_convert.c b/res/res_convert.c
index 34606ac24..2e514b111 100644
--- a/res/res_convert.c
+++ b/res/res_convert.c
@@ -61,45 +61,60 @@ static int split_ext(char *filename, char **name, char **ext)
* \param fd file descriptor
* \param argc no arguements
* \param argv list of arguements
- * \retval RESULT_SUCCESS on success.
- * \retval RESULT_SHOWUSAGE on failure.
+ * \retval CLI_SUCCESS on success.
+ * \retval CLI_SHOWUSAGE or CLI_FAILURE on failure.
*/
-static int cli_audio_convert(int fd, int argc, char *argv[])
+static char *handle_cli_file_convert(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- int ret = RESULT_FAILURE;
+ char *ret = CLI_FAILURE;
struct ast_filestream *fs_in = NULL, *fs_out = NULL;
struct ast_frame *f;
struct timeval start;
int cost;
char *file_in = NULL, *file_out = NULL;
char *name_in, *ext_in, *name_out, *ext_out;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "file convert";
+ e->usage =
+ "Usage: file convert <file_in> <file_out>\n"
+ " Convert from file_in to file_out. If an absolute path\n"
+ " is not given, the default Asterisk sounds directory\n"
+ " will be used.\n\n"
+ " Example:\n"
+ " file convert tt-weasels.gsm tt-weasels.ulaw\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
/* ugly, can be removed when CLI entries have ast_module pointers */
ast_module_ref(ast_module_info->self);
- if (argc != 4 || ast_strlen_zero(argv[2]) || ast_strlen_zero(argv[3])) {
- ret = RESULT_SHOWUSAGE;
+ if (a->argc != 4 || ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3])) {
+ ret = CLI_SHOWUSAGE;
goto fail_out;
}
- file_in = ast_strdupa(argv[2]);
- file_out = ast_strdupa(argv[3]);
+ file_in = ast_strdupa(a->argv[2]);
+ file_out = ast_strdupa(a->argv[3]);
if (split_ext(file_in, &name_in, &ext_in)) {
- ast_cli(fd, "'%s' is an invalid filename!\n", argv[2]);
+ ast_cli(a->fd, "'%s' is an invalid filename!\n", a->argv[2]);
goto fail_out;
}
if (!(fs_in = ast_readfile(name_in, ext_in, NULL, O_RDONLY, 0, 0))) {
- ast_cli(fd, "Unable to open input file: %s\n", argv[2]);
+ ast_cli(a->fd, "Unable to open input file: %s\n", a->argv[2]);
goto fail_out;
}
if (split_ext(file_out, &name_out, &ext_out)) {
- ast_cli(fd, "'%s' is an invalid filename!\n", argv[3]);
+ ast_cli(a->fd, "'%s' is an invalid filename!\n", a->argv[3]);
goto fail_out;
}
if (!(fs_out = ast_writefile(name_out, ext_out, NULL, O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
- ast_cli(fd, "Unable to open output file: %s\n", argv[3]);
+ ast_cli(a->fd, "Unable to open output file: %s\n", a->argv[3]);
goto fail_out;
}
@@ -107,19 +122,19 @@ static int cli_audio_convert(int fd, int argc, char *argv[])
while ((f = ast_readframe(fs_in))) {
if (ast_writestream(fs_out, f)) {
- ast_cli(fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
+ ast_cli(a->fd, "Failed to convert %s.%s to %s.%s!\n", name_in, ext_in, name_out, ext_out);
goto fail_out;
}
}
cost = ast_tvdiff_ms(ast_tvnow(), start);
- ast_cli(fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
- ret = RESULT_SUCCESS;
+ ast_cli(a->fd, "Converted %s.%s to %s.%s in %dms\n", name_in, ext_in, name_out, ext_out, cost);
+ ret = CLI_SUCCESS;
fail_out:
if (fs_out) {
ast_closestream(fs_out);
- if (ret != RESULT_SUCCESS)
+ if (ret != CLI_SUCCESS)
ast_filedelete(name_out, ext_out);
}
@@ -131,17 +146,8 @@ fail_out:
return ret;
}
-static char usage_audio_convert[] =
-"Usage: file convert <file_in> <file_out>\n"
-" Convert from file_in to file_out. If an absolute path is not given, the\n"
-"default Asterisk sounds directory will be used.\n\n"
-"Example:\n"
-" file convert tt-weasels.gsm tt-weasels.ulaw\n";
-
static struct ast_cli_entry cli_convert[] = {
- { { "file", "convert" , NULL },
- cli_audio_convert, "Convert audio file",
- usage_audio_convert },
+ NEW_CLI(handle_cli_file_convert, "Convert audio file")
};
static int unload_module(void)
diff --git a/res/res_crypto.c b/res/res_crypto.c
index 65c5b768d..b0b34bd7c 100644
--- a/res/res_crypto.c
+++ b/res/res_crypto.c
@@ -499,27 +499,43 @@ static void md52sum(char *sum, unsigned char *md5)
* \param argv list of arguements
* \return RESULT_SUCCESS
*/
-static int show_keys(int fd, int argc, char *argv[])
+static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
+#define FORMAT "%-18s %-8s %-16s %-33s\n"
+
struct ast_key *key;
char sum[16 * 2 + 1];
int count_keys = 0;
- ast_cli(fd, "%-18s %-8s %-16s %-33s\n", "Key Name", "Type", "Status", "Sum");
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "keys show";
+ e->usage =
+ "Usage: keys show\n"
+ " Displays information about RSA keys known by Asterisk\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ ast_cli(a->fd, FORMAT, "Key Name", "Type", "Status", "Sum");
+ ast_cli(a->fd, FORMAT, "------------------", "--------", "----------------", "--------------------------------");
AST_RWLIST_RDLOCK(&keys);
AST_RWLIST_TRAVERSE(&keys, key, list) {
md52sum(sum, key->digest);
- ast_cli(fd, "%-18s %-8s %-16s %-33s\n", key->name,
+ ast_cli(a->fd, FORMAT, key->name,
(key->ktype & 0xf) == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE",
key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum);
count_keys++;
}
AST_RWLIST_UNLOCK(&keys);
- ast_cli(fd, "%d known RSA keys.\n", count_keys);
+ ast_cli(a->fd, "\n%d known RSA keys.\n", count_keys);
+
+ return CLI_SUCCESS;
- return RESULT_SUCCESS;
+#undef FORMAT
}
/*!
@@ -529,43 +545,45 @@ static int show_keys(int fd, int argc, char *argv[])
* \param argv list of arguements
* \return RESULT_SUCCESS
*/
-static int init_keys(int fd, int argc, char *argv[])
+static char *handle_cli_keys_init(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_key *key;
int ign;
char *kn, tmp[256] = "";
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "keys init";
+ e->usage =
+ "Usage: keys init\n"
+ " Initializes private keys (by reading in pass code from\n"
+ " the user)\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
+
AST_RWLIST_WRLOCK(&keys);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
/* Reload keys that need pass codes now */
if (key->ktype & KEY_NEEDS_PASSCODE) {
kn = key->fn + strlen(ast_config_AST_KEY_DIR) + 1;
ast_copy_string(tmp, kn, sizeof(tmp));
- try_load_key((char *)ast_config_AST_KEY_DIR, tmp, fd, fd, &ign);
+ try_load_key((char *) ast_config_AST_KEY_DIR, tmp, a->fd, a->fd, &ign);
}
}
AST_RWLIST_TRAVERSE_SAFE_END
AST_RWLIST_UNLOCK(&keys);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static const char show_key_usage[] =
-"Usage: keys show\n"
-" Displays information about RSA keys known by Asterisk\n";
-
-static const char init_keys_usage[] =
-"Usage: keys init\n"
-" Initializes private keys (by reading in pass code from the user)\n";
-
static struct ast_cli_entry cli_crypto[] = {
- { { "keys", "show", NULL },
- show_keys, "Displays RSA key information",
- show_key_usage },
-
- { { "keys", "init", NULL },
- init_keys, "Initialize RSA key passcodes",
- init_keys_usage },
+ NEW_CLI(handle_cli_keys_show, "Displays RSA key information"),
+ NEW_CLI(handle_cli_keys_init, "Initialize RSA key passcodes")
};
/*! \brief initialise the res_crypto module */
diff --git a/res/res_limit.c b/res/res_limit.c
index ca2211836..fcaf03b86 100644
--- a/res/res_limit.c
+++ b/res/res_limit.c
@@ -49,21 +49,21 @@ static struct limits {
char limit[3];
char desc[40];
} limits[] = {
- { RLIMIT_CPU, "-t", "cpu time" },
- { RLIMIT_FSIZE, "-f", "file size" },
- { RLIMIT_DATA, "-d", "program data segment" },
- { RLIMIT_STACK, "-s", "program stack size" },
- { RLIMIT_CORE, "-c", "core file size" },
+ { RLIMIT_CPU, "-t", "cpu time" },
+ { RLIMIT_FSIZE, "-f", "file size" },
+ { RLIMIT_DATA, "-d", "program data segment" },
+ { RLIMIT_STACK, "-s", "program stack size" },
+ { RLIMIT_CORE, "-c", "core file size" },
#ifdef RLIMIT_RSS
- { RLIMIT_RSS, "-m", "resident memory" },
+ { RLIMIT_RSS, "-m", "resident memory" },
{ RLIMIT_MEMLOCK, "-l", "amount of memory locked into RAM" },
#endif
#ifdef RLIMIT_NPROC
- { RLIMIT_NPROC, "-u", "number of processes" },
+ { RLIMIT_NPROC, "-u", "number of processes" },
#endif
- { RLIMIT_NOFILE, "-n", "number of file descriptors" },
+ { RLIMIT_NOFILE, "-n", "number of file descriptors" },
#ifdef VMEM_DEF
- { VMEM_DEF, "-v", "virtual memory" },
+ { VMEM_DEF, "-v", "virtual memory" },
#endif
};
@@ -87,43 +87,105 @@ static const char *str2desc(const char *string)
return "<unknown>";
}
-static int my_ulimit(int fd, int argc, char **argv)
+static char *complete_ulimit(struct ast_cli_args *a)
+{
+ int which = 0, i;
+ int wordlen = strlen(a->word);
+
+ if (a->pos > 1)
+ return NULL;
+ for (i = 0; i < sizeof(limits) / sizeof(limits[0]); i++) {
+ if (!strncasecmp(limits[i].limit, a->word, wordlen)) {
+ if (++which > a->n)
+ return ast_strdup(limits[i].limit);
+ }
+ }
+ return NULL;
+}
+
+static char *handle_cli_ulimit(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int resource;
struct rlimit rlimit = { 0, 0 };
- if (argc > 3)
- return RESULT_SHOWUSAGE;
- if (argc == 1) {
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ulimit";
+ e->usage =
+ "Usage: ulimit {-d|"
+#ifdef RLIMIT_RSS
+ "-l|"
+#endif
+ "-f|"
+#ifdef RLIMIT_RSS
+ "-m|"
+#endif
+ "-s|-t|"
+#ifdef RLIMIT_NPROC
+ "-u|"
+#endif
+#ifdef VMEM_DEF
+ "-v|"
+#endif
+ "-c|-n} [<num>]\n"
+ " Shows or sets the corresponding resource limit.\n"
+ " -d Process data segment [readonly]\n"
+#ifdef RLIMIT_RSS
+ " -l Memory lock size [readonly]\n"
+#endif
+ " -f File size\n"
+#ifdef RLIMIT_RSS
+ " -m Process resident memory [readonly]\n"
+#endif
+ " -s Process stack size [readonly]\n"
+ " -t CPU usage [readonly]\n"
+#ifdef RLIMIT_NPROC
+ " -u Child processes\n"
+#endif
+#ifdef VMEM_DEF
+ " -v Process virtual memory [readonly]\n"
+#endif
+ " -c Core dump file size\n"
+ " -n Number of file descriptors\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_ulimit(a);
+ }
+
+ if (a->argc > 3)
+ return CLI_SHOWUSAGE;
+
+ if (a->argc == 1) {
char arg2[3];
char *newargv[2] = { "ulimit", arg2 };
for (resource = 0; resource < sizeof(limits) / sizeof(limits[0]); resource++) {
+ struct ast_cli_args newArgs = { .argv = newargv, .argc = 2 };
ast_copy_string(arg2, limits[resource].limit, sizeof(arg2));
- my_ulimit(fd, 2, newargv);
+ handle_cli_ulimit(e, CLI_HANDLER, &newArgs);
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
} else {
- resource = str2limit(argv[1]);
+ resource = str2limit(a->argv[1]);
if (resource == -1) {
- ast_cli(fd, "Unknown resource\n");
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Unknown resource\n");
+ return CLI_FAILURE;
}
- if (argc == 3) {
+ if (a->argc == 3) {
int x;
#ifdef RLIMIT_NPROC
if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_NPROC && resource != RLIMIT_FSIZE) {
#else
- if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) {
+ if (resource != RLIMIT_NOFILE && resource != RLIMIT_CORE && resource != RLIMIT_FSIZE) {
#endif
- ast_cli(fd, "Resource not permitted to be set\n");
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Resource not permitted to be set\n");
+ return CLI_FAILURE;
}
- sscanf(argv[2], "%d", &x);
+ sscanf(a->argv[2], "%d", &x);
rlimit.rlim_max = rlimit.rlim_cur = x;
setrlimit(resource, &rlimit);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
} else {
if (!getrlimit(resource, &rlimit)) {
char printlimit[32];
@@ -131,51 +193,18 @@ static int my_ulimit(int fd, int argc, char **argv)
if (rlimit.rlim_max == RLIM_INFINITY)
ast_copy_string(printlimit, "effectively unlimited", sizeof(printlimit));
else
- snprintf(printlimit, sizeof(printlimit), "limited to %d", (int)rlimit.rlim_cur);
- desc = str2desc(argv[1]);
- ast_cli(fd, "%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, argv[1], printlimit);
+ snprintf(printlimit, sizeof(printlimit), "limited to %d", (int) rlimit.rlim_cur);
+ desc = str2desc(a->argv[1]);
+ ast_cli(a->fd, "%c%s (%s) is %s.\n", toupper(desc[0]), desc + 1, a->argv[1], printlimit);
} else
- ast_cli(fd, "Could not retrieve resource limits for %s: %s\n", str2desc(argv[1]), strerror(errno));
- return RESULT_SUCCESS;
- }
- }
-}
-
-static char *complete_ulimit(const char *line, const char *word, int pos, int state)
-{
- int which = 0, i;
- int wordlen = strlen(word);
-
- if (pos > 2)
- return NULL;
- for (i = 0; i < sizeof(limits) / sizeof(limits[0]); i++) {
- if (!strncasecmp(limits[i].limit, word, wordlen)) {
- if (++which > state)
- return ast_strdup(limits[i].limit);
+ ast_cli(a->fd, "Could not retrieve resource limits for %s: %s\n", str2desc(a->argv[1]), strerror(errno));
+ return CLI_SUCCESS;
}
}
- return NULL;
}
-static const char ulimit_usage[] =
-"Usage: ulimit {-d|-l|-f|-m|-s|-t|-u|-v|-c|-n} [<num>]\n"
-" Shows or sets the corresponding resource limit.\n"
-" -d Process data segment [readonly]\n"
-" -l Memory lock size [readonly]\n"
-" -f File size\n"
-" -m Process resident memory [readonly]\n"
-" -s Process stack size [readonly]\n"
-" -t CPU usage [readonly]\n"
-" -u Child processes\n"
-#ifdef VMEM_DEF
-" -v Process virtual memory [readonly]\n"
-#endif
-" -c Core dump file size\n"
-" -n Number of file descriptors\n";
-
-static struct ast_cli_entry cli_ulimit = {
- { "ulimit", NULL }, my_ulimit,
- "Set or show process resource limits", ulimit_usage, complete_ulimit };
+static struct ast_cli_entry cli_ulimit =
+ NEW_CLI(handle_cli_ulimit, "Set or show process resource limits");
static int unload_module(void)
{
@@ -184,7 +213,7 @@ static int unload_module(void)
static int load_module(void)
{
- return ast_cli_register(&cli_ulimit)? AST_MODULE_LOAD_FAILURE: AST_MODULE_LOAD_SUCCESS;
+ return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Resource limits");