struct task task;
};
+extern struct misc_meta_data *mmd;
+
static int server_socket;
static struct command_task command_task_struct;
static struct signal_task signal_task_struct;
static enum play_mode current_play_mode;
+static char *current_mop; /* mode or playlist specifier. NULL means dummy mooe */
+
/**
* A random number used to "authenticate" the connection.
return ret;
}
-int pass_afd(int fd, char *buf, size_t size)
+static int pass_afd(int fd, char *buf, size_t size)
{
struct msghdr msg = {.msg_iov = NULL};
struct cmsghdr *cmsg;
/**
* Open the audio file with highest score.
*
- * \param afd Audio file data is returned here.
- *
- * This stores all information for streaming the "best" audio file
- * in the \a afd structure.
+ * This stores all information for streaming the "best" audio file in a shared
+ * memory area. The id of that area and an open file descriptor for the next
+ * audio file are passed to the server process.
*
- * \return Positive on success, negative on errors.
+ * \return Standard.
*
- * \sa close_audio_file(), open_and_update_audio_file().
+ * \sa open_and_update_audio_file().
*/
int open_next_audio_file(void)
{
*(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;
PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
return ret;
}
-static char *current_mop; /* mode or playlist specifier. NULL means dummy mooe */
-
/* Never fails if arg == NULL */
static int activate_mood_or_playlist(char *arg, int *num_admissible)
{
current_play_mode = mode;
if (arg != current_mop) {
free(current_mop);
- if (arg)
+ if (arg) {
current_mop = para_strdup(arg);
- else
+ mmd_lock();
+ strcpy(mmd->afs_mode_string, arg); /* FIXME: check length */
+ mmd_unlock();
+ } else {
+ mmd_lock();
+ strcpy(mmd->afs_mode_string, "dummy");
+ mmd_unlock();
current_mop = NULL;
+ }
}
return 1;
}
ret = activate_mood_or_playlist(current_mop, &num_admissible);
if (ret < 0) {
para_printf(&pb, "failed, switching to dummy\n");
- change_current_mood(NULL); /* always successful */
+ activate_mood_or_playlist(NULL, &num_admissible);
}
}
para_printf(&pb, "activated %s (%d admissible files)\n", current_mop?
continue;
PARA_ERROR_LOG("%s init: %s\n", afs_tables[i].name,
PARA_STRERROR(-ret));
+ break;
}
if (ret >= 0)
return ret;
- do
- afs_tables[i].close();
- while (i--);
+ while (i)
+ afs_tables[--i].close();
return ret;
}
static void signal_post_select(struct sched *s, struct task *t)
{
struct signal_task *st = t->private_data;
+ t->ret = -E_AFS_PARENT_DIED;
+ if (getppid() == 1)
+ goto err;
t->ret = 1;
if (!FD_ISSET(st->fd, &s->rfds))
return;
if (st->signum == SIGHUP) {
close_afs_tables();
t->ret = open_afs_tables();
+ /* FIXME: Restore current mood or playlist */
+ if (t->ret < 0)
+ goto err;
return;
}
- PARA_NOTICE_LOG("caught signal %d\n", st->signum);
t->ret = -E_AFS_SIGNAL;
+err:
+ PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret));
unregister_tasks();
}