From 64a9cf5877ab9ecf6410596d657914f26830d3f7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 20 Feb 2011 19:41:09 +0100 Subject: [PATCH] para_write: Return proper error code. Currently the exit code of para_write is always the value returned by schedule(). This is zero unless the call to select() fails, usually does not happen, so errors resulting from the writers do not cause para_write to exit with a non-zero exit code. In particular, para_write exits successfully if the underlying writer(s) nodes could not open their sound device or unregistered their task due to other errors. Fix this by investigating each writer node's t->error value after schedule() has returned. If this value does not correspond to an end of file condition, the strerror text of this error code is written to stderr, and para_write exits non-zero. --- alsa_write.c | 2 +- error.h | 4 +--- oss_write.c | 2 +- write.c | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index ae3bbfba..8cf5cfd2 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -214,7 +214,7 @@ again: bytes = btr_next_buffer(btrn, &data); if (ret < 0 || bytes < wn->min_iqs) { /* eof */ assert(btr_no_parent(btrn)); - ret = -E_ALSA_EOF; + ret = -E_WRITE_COMMON_EOF; if (!pad) goto err; /* wait until pending frames are played */ diff --git a/error.h b/error.h index e35952bd..de5dacf2 100644 --- a/error.h +++ b/error.h @@ -103,7 +103,6 @@ extern const char **para_errlist[]; PARA_ERROR(BAD_SAMPLE_FORMAT, "sample format not supported"), \ PARA_ERROR(BAD_CHANNEL_COUNT, "channel count not supported"), \ PARA_ERROR(BAD_SAMPLERATE, "sample rate not supported"), \ - PARA_ERROR(OSS_EOF, "oss: end of file"), \ #define COMPRESS_FILTER_ERRORS \ @@ -412,12 +411,11 @@ extern const char **para_errlist[]; PARA_ERROR(SET_RATE, "snd_pcm_hw_params_set_rate_near failed"), \ PARA_ERROR(START_THRESHOLD, "snd_pcm_sw_params_set_start_threshold() failed"), \ PARA_ERROR(STOP_THRESHOLD, "snd_pcm_sw_params_set_stop_threshold() failed"), \ - PARA_ERROR(ALSA_EOF, "alsa: end of file"), \ - #define WRITE_COMMON_ERRORS \ PARA_ERROR(WRITE_COMMON_SYNTAX, "syntax error in write option"), \ + PARA_ERROR(WRITE_COMMON_EOF, "end of file"), \ #define AACDEC_FILTER_ERRORS \ diff --git a/oss_write.c b/oss_write.c index 70a58203..e79ea6ce 100644 --- a/oss_write.c +++ b/oss_write.c @@ -185,7 +185,7 @@ static void oss_post_select(__a_unused struct sched *s, bytes = btr_next_buffer(btrn, &data); frames = bytes / powd->bytes_per_frame; if (!frames) { /* eof and less than a single frame available */ - ret = -E_OSS_EOF; + ret = -E_WRITE_COMMON_EOF; goto out; } ret = 0; diff --git a/write.c b/write.c index 2ea9d213..b3824a08 100644 --- a/write.c +++ b/write.c @@ -209,6 +209,20 @@ static int main_btr(struct sched *s) s->default_timeout.tv_sec = 10; s->default_timeout.tv_usec = 50000; ret = schedule(s); + if (ret >= 0) { + int j; + for (j = 0; j < i; j++) { + struct task *t = &wns[j].task; + assert(t->error < 0); + if (t->error != -E_WRITE_COMMON_EOF + && t->error != -E_BTR_EOF) { + PARA_ERROR_LOG("%s: %s\n", t->status, + para_strerror(-t->error)); + if (ret >= 0) + ret = t->error; + } + } + } out: for (i--; i >= 0; i--) { struct writer_node *wn = wns + i; -- 2.39.5