static int com_help(int fd, struct lls_parse_result *lpr)
{
char *buf;
- int ret;
+ int ret, ret2;
const struct lls_opt_result *r =
lls_opt_result(LSG_AUDIOD_CMD_HELP_OPT_LONG, lpr);
bool long_help = lls_opt_given(r);
- lsu_com_help(long_help, lpr, audiod_cmd_suite, NULL, &buf, NULL);
- ret = client_write(fd, buf);
+ ret = lsu_com_help(long_help, lpr, audiod_cmd_suite, NULL, &buf, NULL);
+ ret2 = client_write(fd, buf);
free(buf);
- return ret < 0? ret : 0;
+ return ret < 0? ret : ret2;
}
EXPORT_AUDIOD_CMD_HANDLER(help)
static int com_help(struct command_context *cc, struct lls_parse_result *lpr)
{
char *buf;
- int ret;
unsigned n;
bool long_help = SERVER_CMD_OPT_GIVEN(HELP, LONG, lpr);
-
- lsu_com_help(long_help, lpr, server_cmd_suite, aux_info_cb, &buf, &n);
- ret = send_sb(&cc->scc, buf, n, SBD_OUTPUT, false);
- return ret;
+ int ret, ret2;
+ uint8_t band;
+
+ ret = lsu_com_help(long_help, lpr, server_cmd_suite, aux_info_cb,
+ &buf, &n);
+ band = ret < 0? SBD_ERROR_LOG : SBD_OUTPUT;
+ ret2 = send_sb(&cc->scc, buf, n, band, false);
+ return ret >= 0? ret2 : ret;
}
EXPORT_SERVER_CMD_HANDLER(help);
#include "lsu.h"
#include "fd.h"
-static int lsu_lopsub_error(int ret, char **errctx, char **result, unsigned *num_chars)
+static void lsu_error(const char *etype, char **errctx, char **result,
+ unsigned *num_chars)
{
- const char *se = para_strerror(-ret);
- unsigned n;
-
- if (*errctx)
- n = xasprintf(result, "%s: %s\n", *errctx, se);
- else
- n = xasprintf(result, "lopsub error: %s\n", se);
+ /* *errctx is NULL if the lopsub function failed to allocate memory. */
+ unsigned n = xasprintf(result, "lopsub %s error: %s\n", etype,
+ *errctx? *errctx : "out of memory");
free(*errctx);
*errctx = NULL;
if (num_chars)
*num_chars = n;
- return ret;
}
static void lsu_get_subcommand_summary(bool long_summary,
const struct lls_command *cmd;
ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx));
- if (ret < 0)
- return lsu_lopsub_error(ret, &errctx, result, num_chars);
+ if (ret < 0) {
+ lsu_error("arg count", &errctx, result, num_chars);
+ return ret;
+ }
if (lls_num_inputs(lpr) == 0) {
lsu_get_subcommand_summary(long_help, suite,
aux_info_cb, result, num_chars);
}
arg = lls_input(0, lpr);
ret = lls(lls_lookup_subcmd(arg, suite, &errctx));
- if (ret < 0)
- return lsu_lopsub_error(ret, &errctx, result, num_chars);
+ if (ret < 0) {
+ lsu_error("lookup", &errctx, result, num_chars);
+ return ret;
+ }
cmd = lls_cmd(ret, suite);
tmp = long_help? lls_long_help(cmd) : lls_short_help(cmd);
if (aux_info_cb)
static int com_help(struct lls_parse_result *lpr)
{
- int i;
+ int i, ret;
char *buf;
size_t sz;
unsigned n;
}
return 0;
}
- lsu_com_help(long_help, lpr, play_cmd_suite, NULL, &buf, &n);
- btr_add_output(buf, n, pt->btrn);
- return 0;
+ ret = lsu_com_help(long_help, lpr, play_cmd_suite, NULL, &buf, &n);
+ if (ret < 0) {
+ PARA_WARNING_LOG("%s", buf); /* no \n needed */
+ free(buf);
+ } else
+ btr_add_output(buf, n, pt->btrn);
+ return ret;
}
EXPORT_PLAY_CMD_HANDLER(help);