This function of filter_common.c calls exit(3) on errors. This is OK
for para_filter and para_audiod, but not for para_play because there
the function is called after readline has initialized the terminal for
its own use. If the function calls exit(3), the terminal settings are
not reset as they should have been. This can be observed for example
on the attempt to open an mp3 file with an para_play executable that
lacks mp3 support.
This commit changes the function to return an error code instead and
deals with the fallout in the three callers. Although play.c already
had error checking for calls to filter_setup(), it still needs a minor
tweak because we now have to deal with the fact that the filter and
writer node don't exist in eof_cleanup().
static int add_filter(int format, const char *cmdline)
{
struct audio_format_info *a = &afi[format];
static int add_filter(int format, const char *cmdline)
{
struct audio_format_info *a = &afi[format];
- int filter_num, nf = a->num_filters;
+ int ret, filter_num, nf = a->num_filters;
void *cfg;
struct lls_parse_result *flpr;
void *cfg;
struct lls_parse_result *flpr;
- filter_num = filter_setup(cmdline, &cfg, &flpr);
+ ret = filter_setup(cmdline, &cfg, &flpr);
+ if (ret < 0)
+ return ret;
+ filter_num = ret;
a->filter_lpr = arr_realloc(a->filter_lpr, nf + 1, sizeof(flpr));
a->filter_conf = arr_realloc(a->filter_conf, nf + 1, sizeof(void *));
a->filter_nums = arr_realloc(a->filter_nums, nf + 1, sizeof(unsigned));
a->filter_lpr = arr_realloc(a->filter_lpr, nf + 1, sizeof(flpr));
a->filter_conf = arr_realloc(a->filter_conf, nf + 1, sizeof(void *));
a->filter_nums = arr_realloc(a->filter_nums, nf + 1, sizeof(unsigned));
struct task_info ti;
fn = fns[i] = zalloc(sizeof(*fn));
struct task_info ti;
fn = fns[i] = zalloc(sizeof(*fn));
- fn->filter_num = filter_setup(fa, &fn->conf, &filter_lpr);
+ ret = filter_setup(fa, &fn->conf, &filter_lpr);
+ if (ret < 0)
+ goto teardown;
+ fn->filter_num = ret;
name = filter_name(fn->filter_num);
fn->lpr = filter_lpr;
PARA_DEBUG_LOG("filter #%d: %s\n", i, name);
name = filter_name(fn->filter_num);
fn->lpr = filter_lpr;
PARA_DEBUG_LOG("filter #%d: %s\n", i, name);
btr_log_tree(sit->btrn, LL_INFO);
ret = schedule(&s);
sched_shutdown(&s);
btr_log_tree(sit->btrn, LL_INFO);
ret = schedule(&s);
sched_shutdown(&s);
for (i--; i >= 0; i--) {
struct filter_node *fn = fns[i];
for (i--; i >= 0; i--) {
struct filter_node *fn = fns[i];
* filter, optionally followed by options for this filter. If yes, call the
* command line parser of that filter and its ->setup method.
*
* filter, optionally followed by options for this filter. If yes, call the
* command line parser of that filter and its ->setup method.
*
- * \return This function either succeeds or does not return. On success, the
- * number of the filter is returned and conf is initialized to point to the
- * filter configuration as returned by the filter's ->setup() method, if any.
- * Moreover, *lprp is initialized to contain the parsed command line options.
- * On errors, the function calls exit(EXIT_FAILURE).
+ * \return On success, the number of the filter is returned and conf is
+ * initialized to point to the filter configuration as returned by the filter's
+ * ->setup() method, if any. Moreover, *lprp is initialized to contain the
+ * parsed command line options. On errors a negative paraslash error code is
+ * returned.
*/
int filter_setup(const char *fa, void **conf, struct lls_parse_result **lprp)
{
*/
int filter_setup(const char *fa, void **conf, struct lls_parse_result **lprp)
{
const struct lls_command *cmd;
const struct filter *f;
const struct lls_command *cmd;
const struct filter *f;
ret = create_argv(fa, " \t\n", &argv);
if (ret < 0)
ret = create_argv(fa, " \t\n", &argv);
if (ret < 0)
argc = ret;
ret = lls(lls_lookup_subcmd(argv[0], filter_cmd_suite, &errctx));
if (ret < 0)
argc = ret;
ret = lls(lls_lookup_subcmd(argv[0], filter_cmd_suite, &errctx));
if (ret < 0)
free_argv(argv);
if (ret >= 0)
return ret;
free_argv(argv);
if (ret >= 0)
return ret;
if (errctx)
PARA_ERROR_LOG("%s\n", errctx);
free(errctx);
if (errctx)
PARA_ERROR_LOG("%s\n", errctx);
free(errctx);
- PARA_EMERG_LOG("%s\n", para_strerror(-ret));
- exit(EXIT_FAILURE);
int err;
if (!pt->wn.task)
int err;
if (!pt->wn.task)
err = task_status(pt->wn.task);
if (err >= 0)
return 0;
err = task_status(pt->wn.task);
if (err >= 0)
return 0;
decoder = filter_get(pt->fn.filter_num);
task_reap(&pt->fn.task);
decoder = filter_get(pt->fn.filter_num);
task_reap(&pt->fn.task);
+ if (decoder && decoder->close)
decoder->close(&pt->fn);
btr_remove_node(&pt->fn.btrn);
lls_free_parse_result(pt->fn.lpr, FILTER_CMD(pt->fn.filter_num));
decoder->close(&pt->fn);
btr_remove_node(&pt->fn.btrn);
lls_free_parse_result(pt->fn.lpr, FILTER_CMD(pt->fn.filter_num));