+ struct audio_file_data afd;
+ int ret, shmid;
+ char buf[8];
+ long score;
+again:
+ PARA_NOTICE_LOG("getting next audio file\n");
+ ret = score_get_best(&aft_row, &score);
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ goto no_admissible_files;
+ }
+ ret = open_and_update_audio_file(aft_row, score, &afd);
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ ret = score_delete(aft_row);
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ goto no_admissible_files;
+ }
+ goto again;
+ }
+ shmid = ret;
+ if (!write_ok(server_socket)) {
+ ret = -E_AFS_SOCKET;
+ goto destroy;
+ }
+ *(uint32_t *)buf = NEXT_AUDIO_FILE;
+ *(uint32_t *)(buf + 4) = (uint32_t)shmid;
+ ret = pass_afd(afd.fd, buf, 8);
+ close(afd.fd);
+ if (ret >= 0)
+ return ret;
+destroy:
+ shm_destroy(shmid);
+ return ret;
+no_admissible_files:
+ *(uint32_t *)buf = NO_ADMISSIBLE_FILES;
+ *(uint32_t *)(buf + 4) = (uint32_t)0;
+ return send_bin_buffer(server_socket, buf, 8);
+}
+
+/* Never fails if arg == NULL */
+static int activate_mood_or_playlist(char *arg, int *num_admissible)
+{
+ enum play_mode mode;