Fix mood reload.
authorAndre Noll <maan@systemlinux.org>
Sun, 27 Jan 2013 18:12:57 +0000 (19:12 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 10 Feb 2013 15:58:12 +0000 (16:58 +0100)
There was some confusion about how to determine whether the dummy mode
is currently active. At some places we tested if current_mood is NULL,
at others if current_mood->name is NULL. In fact neither check works:

* if a playlist is open, current_mood is NULL (but the dummy
mood is not loaded),

* loading the dummy mood currently sets current_mood->name to
"(dummy)".

This patch makes the latter variant the official one and fixes up
the code accordingly.

This also fixes the critical log message

Jan 27 18:57:29 (5) (13487) afs_event: table moods, event 9: key not found in rbtree

which occured if the dummy mood was active while an event caused the
mood to be reloaded.

mood.c

diff --git a/mood.c b/mood.c
index e905f92cc64b4e99d55691d3d9e5805e3f3985d1..74b00d35b2ddc4efd07f2e8783d1a37fcc3117b4 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -77,6 +77,10 @@ struct mood {
        struct list_head score_list;
 };
 
+/*
+ * If current_mood is NULL then no mood is currently open. If
+ * current_mood->name is NULL, the dummy mood is currently open
+ */
 static struct mood *current_mood;
 
 /**
@@ -218,7 +222,8 @@ static void destroy_mood(struct mood *m)
 static struct mood *alloc_new_mood(const char *name)
 {
        struct mood *m = para_calloc(sizeof(struct mood));
-       m->name = para_strdup(name);
+       if (name)
+               m->name = para_strdup(name);
        INIT_LIST_HEAD(&m->accept_list);
        INIT_LIST_HEAD(&m->deny_list);
        INIT_LIST_HEAD(&m->score_list);
@@ -850,9 +855,9 @@ int change_current_mood(char *mood_name)
                        return ret;
                close_current_mood();
                current_mood = m;
-       } else {
+       } else { /* load dummy mood */
                close_current_mood();
-               current_mood = alloc_new_mood("dummy");
+               current_mood = alloc_new_mood(NULL);
        }
        aa.m = current_mood;
        PARA_NOTICE_LOG("computing statistics of admissible files\n");
@@ -867,7 +872,7 @@ int change_current_mood(char *mood_name)
                if (ret < 0)
                        goto out;
        }
-       PARA_NOTICE_LOG("loaded mood %s\n", current_mood->name);
+       PARA_NOTICE_LOG("loaded mood %s\n", mood_name? mood_name : "(dummy)");
        ret = statistics.num;
 out:
        free(aa.array);