X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=audiod_command.c;h=40f918569f389239b72d96b4968edde2b915334e;hb=27879fbdef3653aa7ba66eda97dc7cd731f2ce26;hp=cb4363b15bc12507af12c07ed0d0f3978da2ac55;hpb=2031b9cab9304b02c0372f73eef54d9501277031;p=paraslash.git diff --git a/audiod_command.c b/audiod_command.c index cb4363b1..40f91856 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -13,6 +13,7 @@ #include "audiod.lsg.h" #include "para.h" +#include "lsu.h" #include "audiod_cmd.lsg.h" #include "list.h" #include "sched.h" @@ -224,62 +225,56 @@ __malloc static char *audiod_status_string(void) return para_strdup(status); } -static int dump_commands(int fd) +static int com_help(int fd, struct lls_parse_result *lpr) { - char *buf = para_strdup(""), *tmp = NULL; - int i; - ssize_t ret; - const struct lls_command *cmd; + char *buf; + int ret; + const struct lls_opt_result *r = + lls_opt_result(LSG_AUDIOD_CMD_HELP_OPT_LONG, lpr); + bool long_help = lls_opt_given(r); - for (i = 1; (cmd = lls_cmd(i, audiod_cmd_suite)); i++) { - tmp = make_message("%s%s\t%s\n", buf, lls_command_name(cmd), - lls_purpose(cmd)); - free(buf); - buf = tmp; - } + lsu_com_help(long_help, lpr, audiod_cmd_suite, NULL, &buf, NULL); ret = client_write(fd, buf); free(buf); - return ret; + return ret < 0? ret : 0; } +EXPORT_AUDIOD_CMD_HANDLER(help) -static int com_help(int fd, struct lls_parse_result *lpr) +static int com_ll(int fd, struct lls_parse_result *lpr) { - int ret; - char *buf, *errctx; - const struct lls_command *cmd; + unsigned ll; + char *errctx; + const char *sev[] = {SEVERITIES}; + const char *arg; + int ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx)); - ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx)); if (ret < 0) { - if (errctx) { - buf = make_message("%s\n", errctx); - client_write(fd, buf); - free(buf); - free(errctx); - } + char *tmp = make_message("%s\n", errctx); + free(errctx); + client_write(fd, tmp); + free(tmp); return ret; } - if (lls_num_inputs(lpr) == 0) - return dump_commands(fd); - ret = lls(lls_lookup_subcmd(lls_input(0, lpr), audiod_cmd_suite, - &errctx)); - if (ret < 0) { - buf = make_message("%s: %s\nAvailable commands:\n", errctx? - errctx : lls_input(0, lpr), para_strerror(-ret)); - if (client_write(fd, buf) >= 0) - dump_commands(fd); - free(errctx); - free(buf); - goto out; + if (lls_num_inputs(lpr) == 0) { + char *msg; + ll = daemon_get_loglevel(); + msg = make_message("%s\n", sev[ll]); + ret = client_write(fd, msg); + free(msg); + return ret; } - cmd = lls_cmd(ret, audiod_cmd_suite); - buf = lls_long_help(cmd); - assert(buf); - ret = client_write(fd, buf); - free(buf); -out: - return ret < 0? ret : 0; + arg = lls_input(0, lpr); + for (ll = 0; ll < NUM_LOGLEVELS; ll++) { + if (!strcmp(arg, sev[ll])) + break; + } + if (ll >= NUM_LOGLEVELS) + return -ERRNO_TO_PARA_ERROR(EINVAL); + PARA_INFO_LOG("new log level: %s\n", sev[ll]); + daemon_set_loglevel(ll); + return 1; } -EXPORT_AUDIOD_CMD_HANDLER(help) +EXPORT_AUDIOD_CMD_HANDLER(ll) static int com_tasks(int fd, __a_unused struct lls_parse_result *lpr) {