From: Andre Noll Date: Mon, 7 Mar 2022 19:21:59 +0000 (+0100) Subject: afs.c: Improve activate_mood_or_playlist(). X-Git-Tag: v0.7.2~14^2~15 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=aa8cb0f79df3e69b3853552e3ab0ae9e4383e0a7;p=paraslash.git 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. --- 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; }