]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Make struct signal_task generic and make afs use it.
authorAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 13:49:05 +0000 (15:49 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 13:49:05 +0000 (15:49 +0200)
16 files changed:
afs.c
audiod.c
command.c
configure.ac
gui.c
mood.c
mysql_selector.c
mysql_selector.cmd
playlist_selector.c
playlist_selector.cmd
random_selector.cmd
server.c
server.cmd
signal.h
user_list.c
user_list.h

diff --git a/afs.c b/afs.c
index 5ccb17f91883e5a9374425fac3b667c9876f9579..71a9f1ce6fc2d2d1b481b688e1b060a430158c94 100644 (file)
--- a/afs.c
+++ b/afs.c
 #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)
index d4abb3b2ba3a2e01d3da64dd7834aecae40dd2e1..ccb233180e750b5077ba2cda6d2f622fd2cbad9b 100644 (file)
--- 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++)
 
index ecadfc401e206f4697f3350bdd784eef59c15272..9873fdd34867d01efab9cfa84a8b755c48f8a3fa 100644 (file)
--- 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"
 
index 316adf198b150fe163c5b7a3cc69272299dea47c..7449cde186b8178f86dedde43e8ea0a71d4e7ea7 100644 (file)
@@ -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 37d0d8e9ec205f0f3992d21b3a97519b277fc7af..28291a867fd99aea2f6d4abeb96c7e671abc8fc3 100644 (file)
--- 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 996b71fac99257758e2a5d8cad9d6c018cf1ba06..decc77fc74f407b901ac13b59e18afe32da308e5 100644 (file)
--- 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(&current_mood->accept_list))
                return -E_NOT_ADMISSIBLE;
-       list_for_each_entry(item, &current_mood->score_list, mood_item_node) {
-               PARA_INFO_LOG("random: %d\n", para_random(100));
+       list_for_each_entry(item, &current_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;
index 702e08d3478a4f2c4c995ba4bc6dda68210a0b04..0635f855f73833f64eabb10e5cd0660960586965 100644 (file)
@@ -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"
index 652ac53a122b5283e33851f266a619a85ae1e22f..5bfcc957da3ff10c75217e5191e8f626fc8357aa 100644 (file)
@@ -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
index 9eb6305a9f5e26915b2eb6c07f4768943a14dda0..0da63ad1f1444f86d42d3cf2c660108a8c32d9c2 100644 (file)
@@ -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"
 
index 2006647d1bded6e87799c2e2ba939a8c73d49c7d..188b16e11799d9c408faeff6b97d3e95406b437a 100644 (file)
@@ -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
index 578c4470022ed1a83bc81ae200f3345628b77f9e..ef68cff4338a7dd7b9bc8440729d5d9cd3459ce8 100644 (file)
@@ -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
index 94e6564b783371fb8cd77e9f8c0a96eb55093f6f..a63aeefc357fe95e54386414390a5a951f2dc91f 100644 (file)
--- 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"
index b3755094776682b228473c7854b3c4117e51772e..fe6328f63adfd8cce014f0a794f2609a72f64bab 100644 (file)
@@ -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
index 50c5f636a84168f637ae26db9a41086d5177580f..921448305764109d83907981826e498853e68fbf 100644 (file)
--- 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);
index be369817bf0c47dc6f4d38bd88165fc6fdef8196..18df94b4c117f0c1aab5093101d214a93e48cb87 100644 (file)
@@ -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;
index 7e9ac9f33e0340eaf223dd3c1a13c5be8ee9e303..fbe07995e3b7f37897a3637f4821d01c97d7ff5d 100644 (file)
@@ -6,7 +6,6 @@
 
 /** \file user_list.h exported functions from user_list.c */
 
-#include "list.h"
 #include "crypt.h"
 
 /**