+ PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name,
+ ret);
+ return ret;
+}
+
+static int server_socket;
+static struct command_task command_task_struct;
+static struct signal_task signal_task_struct;
+
+static void unregister_tasks(void)
+{
+ unregister_task(&command_task_struct.task);
+ unregister_task(&signal_task_struct.task);
+}
+
+static void close_afs_tables(enum osl_close_flags flags)
+{
+ PARA_NOTICE_LOG("closing afs_tables\n");
+ score_shutdown(flags);
+ attribute_shutdown(flags);
+ close_current_mood();
+ playlist_close();
+ moods_shutdown(flags);
+ playlists_shutdown(flags);
+ lyrics_shutdown(flags);
+ images_shutdown(flags);
+ aft_shutdown(flags);
+}
+
+static void signal_pre_select(struct sched *s, struct task *t)
+{
+ struct signal_task *st = t->private_data;
+ t->ret = 1;
+ para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+}
+
+static void signal_post_select(struct sched *s, struct task *t)
+{
+ struct signal_task *st = t->private_data;
+ t->ret = 1;
+ if (!FD_ISSET(st->fd, &s->rfds))
+ return;
+ st->signum = para_next_signal();
+ t->ret = 1;
+ if (st->signum == SIGUSR1)
+ return; /* ignore SIGUSR1 */
+ PARA_NOTICE_LOG("caught signal %d\n", st->signum);
+ t->ret = -E_SIGNAL_CAUGHT;
+ unregister_tasks();
+}
+
+static void register_signal_task(void)
+{
+ struct signal_task *st = &signal_task_struct;
+ st->fd = para_signal_init();
+ PARA_INFO_LOG("signal pipe: fd %d\n", st->fd);
+ para_install_sighandler(SIGINT);
+ para_install_sighandler(SIGTERM);
+ para_install_sighandler(SIGPIPE);
+
+ st->task.pre_select = signal_pre_select;
+ st->task.post_select = signal_post_select;
+ st->task.private_data = st;
+ sprintf(st->task.status, "signal task");
+ register_task(&st->task);
+}
+
+static void command_pre_select(struct sched *s, struct task *t)
+{
+ struct command_task *ct = t->private_data;
+ t->ret = 1;
+ para_fd_set(ct->fd, &s->rfds, &s->max_fileno);