From ff47d38b16a15f57ac8804ae599c8d020de8b2f3 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 27 Jan 2013 19:12:57 +0100 Subject: [PATCH] Fix mood reload. 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mood.c b/mood.c index e905f92c..74b00d35 100644 --- 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); -- 2.39.5