audiod: Don't init slot info unless opening the receiver succeeds.
authorAndre Noll <maan@systemlinux.org>
Wed, 10 Mar 2010 07:56:55 +0000 (08:56 +0100)
committerAndre Noll <maan@systemlinux.org>
Wed, 10 Mar 2010 07:56:55 +0000 (08:56 +0100)
Currently we set the slot's audio format number even if the receiver could not
be opened. This confuses the slot clearing code as no writer is active in
this case which triggers the assertion

para_audiod: audiod.c:384: close_writers: Assertion `s->wns'

Fix it by not touching the slot info structure unless we have successfully started
the receiver. Also perform some minor cleanups while we're at it.

Thanks to Gerrit Renker for pointing out this bug.

audiod.c

index 1663dad..76a6af6 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -549,16 +549,13 @@ static int open_receiver(int format)
        int ret, slot_num;
        struct receiver *r = a->receiver;
        struct receiver_node *rn;
-       const struct timeval restart_delay = {2, 0};
 
+       tv_add(now, &(struct timeval)EMBRACE(2, 0), &a->restart_barrier);
        ret = get_empty_slot();
        if (ret < 0)
-               goto err;
+               return ret;
        slot_num = ret;
-       s = &slot[slot_num];
-       s->format = format;
-       s->receiver_node = para_calloc(sizeof(struct receiver_node));
-       rn = s->receiver_node;
+       rn = para_calloc(sizeof(*rn));
        rn->receiver = r;
        rn->conf = a->receiver_conf;
        rn->btrn = btr_new_node(&(struct btr_node_description)
@@ -567,21 +564,18 @@ static int open_receiver(int format)
        if (ret < 0) {
                btr_free_node(rn->btrn);
                free(rn);
-               s->receiver_node = NULL;
-               goto err;
+               return ret;
        }
+       s = &slot[slot_num];
+       s->format = format;
+       s->receiver_node = rn;
        PARA_NOTICE_LOG("started %s: %s receiver in slot %d\n",
-               audio_formats[s->format], r->name, slot_num);
+               audio_formats[format], r->name, slot_num);
        rn->task.pre_select = r->pre_select;
        rn->task.post_select = r->post_select;
        sprintf(rn->task.status, "%s receiver node", r->name);
        register_task(&rn->task);
-       ret = slot_num;
-err:
-       if (ret < 0)
-               PARA_ERROR_LOG("%s\n", para_strerror(-ret));
-       tv_add(now, &restart_delay, &afi[format].restart_barrier);
-       return ret;
+       return slot_num;
 }
 
 /* return: 0: Not running, 1: Running, -1: Running but eof (or error) */
@@ -1142,8 +1136,10 @@ static void start_stop_decoders(void)
        if (!must_start_decoder())
                return;
        ret = open_receiver(stat_task->current_audio_format_num);
-       if (ret < 0)
+       if (ret < 0) {
+               PARA_ERROR_LOG("%s\n", para_strerror(-ret));
                return;
+       }
        sl = slot + ret;
        a = afi + sl->format;
        if (a->num_filters)