]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
afs.c: Improve activate_mood_or_playlist().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 7 Mar 2022 19:21:59 +0000 (20:21 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Oct 2022 18:36:21 +0000 (20:36 +0200)
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

diff --git a/afs.c b/afs.c
index 0aa81cface17c1e7665561a24d2115312c9baf6e..72e7acccf3284fd4bb7d94697eb3d2ce70217d29 100644 (file)
--- 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;
 }