From c252837b853b35f06fffe637b2a6bf16419da954 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 8 Sep 2007 15:49:05 +0200 Subject: [PATCH] Make struct signal_task generic and make afs use it. --- afs.c | 85 +++++++++++++++++++++++++++++++++++-------- audiod.c | 12 ------ command.c | 1 + configure.ac | 2 +- gui.c | 2 + mood.c | 4 +- mysql_selector.c | 1 + mysql_selector.cmd | 2 +- playlist_selector.c | 1 + playlist_selector.cmd | 2 +- random_selector.cmd | 2 +- server.c | 2 + server.cmd | 2 +- signal.h | 12 ++++++ user_list.c | 1 + user_list.h | 1 - 16 files changed, 95 insertions(+), 37 deletions(-) diff --git a/afs.c b/afs.c index 5ccb17f9..71a9f1ce 100644 --- a/afs.c +++ b/afs.c @@ -10,6 +10,10 @@ #include "afs.h" #include "ipc.h" #include "string.h" +#include "list.h" +#include "sched.h" +#include "signal.h" +#include "fd.h" /** \file afs.c Paraslash's audio file selector. */ @@ -481,19 +485,78 @@ static void setup_command_socket(void) command_socket); } -int server_socket; +static int server_socket; -void shed(void) +void loop(void) { for (;;) sleep(1); } +static void afs_shutdown(enum osl_close_flags flags) +{ + PARA_NOTICE_LOG("cleaning up\n"); + score_shutdown(flags); + attribute_shutdown(flags); + mood_close(); + 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(); + PARA_NOTICE_LOG("caught signal %d\n", st->signum); + t->ret = 1; + if (st->signum == SIGUSR1) + return; /* ignore SIGUSR1 */ + afs_shutdown(OSL_MARK_CLEAN); + t->ret = -E_SIGNAL_CAUGHT; +} + +static void register_signal_task(void) +{ + static struct signal_task signal_task_struct; + 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); +} + +void register_tasks(void) +{ + register_signal_task(); +} + __noreturn int afs_init(uint32_t cookie, int socket_fd) { int ret; // void *shm_area; enum play_mode current_play_mode; + struct sched s; server_socket = socket_fd; socket_cookie = cookie; @@ -524,7 +587,10 @@ __noreturn int afs_init(uint32_t cookie, int socket_fd) goto aft_init_error; current_play_mode = init_admissible_files(); - shed(); + register_tasks(); + s.default_timeout.tv_sec = 0; + s.default_timeout.tv_usec = 99 * 1000; + sched(&s); #if 0 ret = shm_new(sizeof(struct callback_data)); @@ -788,19 +854,6 @@ out: mutex_unlock(result_mutex); /* wake up child */ } -static void afs_shutdown(enum osl_close_flags flags) -{ - score_shutdown(flags); - attribute_shutdown(flags); - mood_close(); - playlist_close(); - moods_shutdown(flags); - playlists_shutdown(flags); - lyrics_shutdown(flags); - images_shutdown(flags); - aft_shutdown(flags); -} - #if 0 static int got_sigchld; static void server_loop(int child_pid) diff --git a/audiod.c b/audiod.c index d4abb3b2..ccb23318 100644 --- a/audiod.c +++ b/audiod.c @@ -104,18 +104,6 @@ struct command_task { struct task task; }; -/** - * task for signal handling - */ -struct signal_task { - /** the signal pipe */ - int fd; - /** the number of the most recent signal */ - int signum; - /** the associated task structure */ - struct task task; -}; - /** iterate over all supported audio formats */ #define FOR_EACH_AUDIO_FORMAT(af) for (af = 0; af < NUM_AUDIO_FORMATS; af++) diff --git a/command.c b/command.c index ecadfc40..9873fdd3 100644 --- a/command.c +++ b/command.c @@ -22,6 +22,7 @@ #include "daemon.h" #include "string.h" #include "fd.h" +#include "list.h" #include "user_list.h" #include "server_command_list.h" diff --git a/configure.ac b/configure.ac index 316adf19..7449cde1 100644 --- a/configure.ac +++ b/configure.ac @@ -110,7 +110,7 @@ server_cmdline_objs="server.cmdline server_command_list random_selector_command_ server_errlist_objs="server mp3_afh vss command net string signal random_selector time daemon stat crypt http_send afs_common close_on_fork playlist_selector ipc dccp dccp_send fd user_list chunk_queue afs osl aft mood score attribute - blob playlist sha1 rbtree" + blob playlist sha1 rbtree sched" server_ldflags="" server_audio_formats=" mp3" diff --git a/gui.c b/gui.c index 37d0d8e9..28291a86 100644 --- a/gui.c +++ b/gui.c @@ -14,6 +14,8 @@ #include "gui_common.h" #include "fd.h" #include "error.h" +#include "list.h" +#include "sched.h" #include "signal.h" /** define the array of error lists needed by para_gui */ diff --git a/mood.c b/mood.c index 996b71fa..decc77fc 100644 --- a/mood.c +++ b/mood.c @@ -273,10 +273,8 @@ static int compute_mood_score(const void *row, long *result) /* reject if there is no matching entry in the accept list */ if (!match && !list_empty(¤t_mood->accept_list)) return -E_NOT_ADMISSIBLE; - list_for_each_entry(item, ¤t_mood->score_list, mood_item_node) { - PARA_INFO_LOG("random: %d\n", para_random(100)); + list_for_each_entry(item, ¤t_mood->score_list, mood_item_node) add_item_score(row, item, &score, &score_arg_sum); - } if (score_arg_sum) score /= score_arg_sum; *result = score; diff --git a/mysql_selector.c b/mysql_selector.c index 702e08d3..0635f855 100644 --- a/mysql_selector.c +++ b/mysql_selector.c @@ -23,6 +23,7 @@ #include "error.h" #include "net.h" #include "string.h" +#include "list.h" #include "user_list.h" #include "mysql_selector_command_list.h" #include "ipc.h" diff --git a/mysql_selector.cmd b/mysql_selector.cmd index 652ac53a..5bfcc957 100644 --- a/mysql_selector.cmd +++ b/mysql_selector.cmd @@ -3,7 +3,7 @@ SF: mysql_selector.c HC: prototypes for the commands of the mysql audio file selector CC: array of commands for the mysql audio file selector AT: server_command -IN: para afh server user_list +IN: para afh server list user_list SN: list of mysql selector commands --- N: cam diff --git a/playlist_selector.c b/playlist_selector.c index 9eb6305a..0da63ad1 100644 --- a/playlist_selector.c +++ b/playlist_selector.c @@ -14,6 +14,7 @@ #include "net.h" #include "string.h" #include "ipc.h" +#include "list.h" #include "user_list.h" #include "playlist_selector_command_list.h" diff --git a/playlist_selector.cmd b/playlist_selector.cmd index 2006647d..188b16e1 100644 --- a/playlist_selector.cmd +++ b/playlist_selector.cmd @@ -3,7 +3,7 @@ SF: playlist_selector.c HC: prototypes for the commands of the playlist audio file selector CC: array of commands for the playlist audio file selector AT: server_command -IN: para afh server user_list +IN: para afh server list user_list SN: list of playlist selector commands --- N: ppl diff --git a/random_selector.cmd b/random_selector.cmd index 578c4470..ef68cff4 100644 --- a/random_selector.cmd +++ b/random_selector.cmd @@ -3,7 +3,7 @@ SF: random_selector.c HC: prototypes for the commands of the random audio file selector CC: array of commands for the random audio file selector AT: server_command -IN: para afh server user_list +IN: para afh server list user_list SN: list of random selector commands --- N: random_info diff --git a/server.c b/server.c index 94e6564b..a63aeefc 100644 --- a/server.c +++ b/server.c @@ -31,6 +31,8 @@ #include "string.h" #include "ipc.h" #include "fd.h" +#include "list.h" +#include "sched.h" #include "signal.h" #include "user_list.h" #include "afs.h" diff --git a/server.cmd b/server.cmd index b3755094..fe6328f6 100644 --- a/server.cmd +++ b/server.cmd @@ -3,7 +3,7 @@ SF: command.c HC: prototypes for the server command handlers CC: array of server commands AT: server_command -IN: para afh server user_list +IN: para afh server list user_list SN: list of server commands --- N: chs diff --git a/signal.h b/signal.h index 50c5f636..92144830 100644 --- a/signal.h +++ b/signal.h @@ -6,6 +6,18 @@ /** \file signal.h exported symbols from signal.c */ +/** + * Task for signal handling. + */ +struct signal_task { + /** The signal pipe. */ + int fd; + /** The number of the most recent signal. */ + int signum; + /** The associated task structure. */ + struct task task; +}; + int para_signal_init(void); int para_install_sighandler(int); void para_reap_children(void); diff --git a/user_list.c b/user_list.c index be369817..18df94b4 100644 --- a/user_list.c +++ b/user_list.c @@ -10,6 +10,7 @@ #include "error.h" #include "fd.h" #include "string.h" +#include "list.h" #include "user_list.h" static struct list_head user_list; diff --git a/user_list.h b/user_list.h index 7e9ac9f3..fbe07995 100644 --- a/user_list.h +++ b/user_list.h @@ -6,7 +6,6 @@ /** \file user_list.h exported functions from user_list.c */ -#include "list.h" #include "crypt.h" /** -- 2.39.5