From aa8cb0f79df3e69b3853552e3ab0ae9e4383e0a7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 7 Mar 2022 20:21:59 +0100 Subject: [PATCH] afs.c: Improve activate_mood_or_playlist(). Merge the two conditional branches to simplify the code and increase the event counter to notify the server also in the SIGHUP case. This is the right thing to do because we did (re)load the mood or playlist. --- afs.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/afs.c b/afs.c index 0aa81cfa..72e7accc 100644 --- a/afs.c +++ b/afs.c @@ -462,22 +462,15 @@ static int activate_mood_or_playlist(const char *arg, int *num_admissible, */ if (arg != current_mop) { free(current_mop); - if (arg) { - current_mop = para_strdup(arg); - mutex_lock(mmd_mutex); - strncpy(mmd->afs_mode_string, arg, - sizeof(mmd->afs_mode_string)); - mmd->afs_mode_string[sizeof(mmd->afs_mode_string) - 1] = '\0'; - mmd->events++; - mutex_unlock(mmd_mutex); - } else { - mutex_lock(mmd_mutex); - strcpy(mmd->afs_mode_string, "dummy"); - mmd->events++; - mutex_unlock(mmd_mutex); - current_mop = NULL; - } + current_mop = arg? para_strdup(arg) : NULL; } + /* Notify the server about the mood/playlist change. */ + mutex_lock(mmd_mutex); + strncpy(mmd->afs_mode_string, arg? arg: "dummy", + sizeof(mmd->afs_mode_string)); + mmd->afs_mode_string[sizeof(mmd->afs_mode_string) - 1] = '\0'; + mmd->events++; + mutex_unlock(mmd_mutex); return 1; } -- 2.39.5