]> git.tue.mpg.de Git - paraslash.git/commitdiff
para_server: Initialize the new afs.
authorAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 11:37:11 +0000 (13:37 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 11:37:11 +0000 (13:37 +0200)
27 files changed:
aac_afh.c
afs.c
afs.h
afs_common.c
aft.c
attribute.c
blob.c
command.c
dccp_send.c
http_send.c
mood.c
mp3_afh.c
mysql_selector.c
mysql_selector.cmd
ogg_afh.c
ortp_send.c
para.h
playlist.c
playlist_selector.c
playlist_selector.cmd
random_selector.c
random_selector.cmd
score.c
server.c
server.cmd
server.h
vss.c

index be301c5ce38f530bf29ddef4781f89c4d2b4926b..9bb4323cf4182abceb79f5aa7e57af99c9e7a59d 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -10,6 +10,8 @@
 
 /** \file aac_afh.c para_server's aac audio format handler */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "error.h"
 #include "string.h"
diff --git a/afs.c b/afs.c
index c5673c6542835d669691b36bb616f4e357748d11..5ccb17f91883e5a9374425fac3b667c9876f9579 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -1,4 +1,5 @@
 #include "para.h"
+#include "afh.h"
 #include "error.h"
 #include <dirent.h> /* readdir() */
 #include <sys/mman.h>
@@ -12,6 +13,8 @@
 
 /** \file afs.c Paraslash's audio file selector. */
 
+static uint32_t socket_cookie;
+
 /**
  * Compare two osl objects of string type.
  *
@@ -365,16 +368,6 @@ int stdin_command(struct osl_object *arg_obj, callback_function *f,
        return ret;
 }
 
-static void para_init_random_seed(void)
-{
-       struct timeval now;
-       unsigned int seed;
-
-       gettimeofday(&now, NULL);
-       seed = now.tv_usec;
-       srand(seed);
-}
-
 /**
  * Open the audio file with highest score.
  *
@@ -416,6 +409,7 @@ int close_audio_file(struct audio_file_data *afd)
        return para_munmap(afd->map.data, afd->map.size);
 }
 
+#if 0
 static void play_loop(enum play_mode current_play_mode)
 {
        int i, ret;
@@ -433,6 +427,8 @@ static void play_loop(enum play_mode current_play_mode)
                close_audio_file(&afd);
        }
 }
+#endif
+
 
 static enum play_mode init_admissible_files(void)
 {
@@ -463,18 +459,51 @@ static enum play_mode init_admissible_files(void)
        return PLAY_MODE_MOOD;
 }
 
-static int afs_init(void)
+int command_socket;
+
+static void setup_command_socket(void)
+{
+       int ret;
+       char *socket_name = "/tmp/afs_command_socket";
+       struct sockaddr_un unix_addr;
+
+       unlink(socket_name);
+       ret = create_local_socket(socket_name, &unix_addr,
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+       if (ret < 0)
+               exit(EXIT_FAILURE);
+       command_socket = ret;
+       if (listen(command_socket , 5) < 0) {
+               PARA_EMERG_LOG("%s", "can not listen on socket\n");
+               exit(EXIT_FAILURE);
+       }
+       PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name,
+               command_socket);
+}
+
+int server_socket;
+
+void shed(void)
+{
+       for (;;)
+               sleep(1);
+}
+
+__noreturn int afs_init(uint32_t cookie, int socket_fd)
 {
-       int ret, shmid;
-       void *shm_area;
+       int ret;
+//     void *shm_area;
        enum play_mode current_play_mode;
 
-       para_init_random_seed();
+       server_socket = socket_fd;
+       socket_cookie = cookie;
+       PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n",
+               server_socket, (unsigned) cookie);
+       setup_command_socket();
 
        ret = attribute_init(&afs_tables[TBLNUM_ATTRIBUTES]);
-       PARA_DEBUG_LOG("ret %d\n", ret);
        if (ret < 0)
-               return ret;
+               goto attribute_init_error;
        ret = moods_init(&afs_tables[TBLNUM_MOODS]);
        if (ret < 0)
                goto moods_init_error;
@@ -495,8 +524,9 @@ static int afs_init(void)
                goto aft_init_error;
 
        current_play_mode = init_admissible_files();
-       play_loop(current_play_mode);
+       shed();
 
+#if 0
        ret = shm_new(sizeof(struct callback_data));
        if (ret < 0)
                return ret;
@@ -518,7 +548,7 @@ static int afs_init(void)
                return ret;
        result_mutex = ret;
        mutex_lock(result_mutex);
-       return 1;
+#endif 
 aft_init_error:
        score_shutdown(OSL_MARK_CLEAN);
 score_init_error:
@@ -531,68 +561,10 @@ playlists_init_error:
        moods_shutdown(OSL_MARK_CLEAN);
 moods_init_error:
        attribute_shutdown(OSL_MARK_CLEAN);
-       return ret;
-}
-
-static uint32_t afs_socket_cookie;
-static int para_random(unsigned max)
-{
-       return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
-}
-
-int setup(void)
-{
-       int ret, afs_server_socket[2];
-
-       para_init_random_seed();
-       ret = socketpair(PF_UNIX, SOCK_DGRAM, 0, afs_server_socket);
-       if (ret < 0)
-               exit(EXIT_FAILURE);
-       afs_socket_cookie = para_random((uint32_t)-1);
-       ret = fork();
-       if (ret < 0)
-               exit(EXIT_FAILURE);
-       if (!ret) { /* child (afs) */
-               char *socket_name = "/tmp/afs_command_socket";
-               struct sockaddr_un unix_addr;
-               int fd;
-
-               unlink(socket_name);
-               ret = create_local_socket(socket_name, &unix_addr,
-                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
-               if (ret < 0)
-                       exit(EXIT_FAILURE);
-               fd = ret;
-               if (listen(fd , 5) < 0) {
-                       PARA_EMERG_LOG("%s", "can not listen on socket\n");
-                       exit(EXIT_FAILURE);
-               }
-               ret = afs_init();
-               if (ret < 0)
-                       exit(EXIT_FAILURE);
-               PARA_NOTICE_LOG("accepting\n");
-               ret = para_accept(fd, &unix_addr, sizeof(struct sockaddr_un));
-               return ret;
-       }
-       ret = fork();
-       if (ret < 0)
-               exit(EXIT_FAILURE);
-       if (!ret) { /* child (handler) */
-               PARA_NOTICE_LOG("reading stdin\n");
-               for (;;) {
-                       char buf[255];
-                       read(0, buf, 255);
-                       PARA_NOTICE_LOG("read: %s\n", buf);
-               }
-
-       }
-       for (;;) {
-               sleep(10);
-               PARA_NOTICE_LOG("sending next requerst\n");
-       }
+attribute_init_error:
+       exit(EXIT_FAILURE);
 }
 
-
 static int create_all_tables(void)
 {
        int i, ret;
@@ -816,9 +788,6 @@ out:
        mutex_unlock(result_mutex); /* wake up child */
 }
 
-static void dummy(__a_unused int s)
-{}
-
 static void afs_shutdown(enum osl_close_flags flags)
 {
        score_shutdown(flags);
@@ -832,12 +801,8 @@ static void afs_shutdown(enum osl_close_flags flags)
        aft_shutdown(flags);
 }
 
+#if 0
 static int got_sigchld;
-static void sigchld_handler(__a_unused int s)
-{
-       got_sigchld = 1;
-}
-
 static void server_loop(int child_pid)
 {
 //     int status;
@@ -860,7 +825,6 @@ static void server_loop(int child_pid)
        }
 }
 
-#if 0
 int main(int argc, const char **argv)
 {
        int i, ret = -E_AFS_SYNTAX;
diff --git a/afs.h b/afs.h
index fdc42f1f5aaa83e23645d32dacbd9eca89e1d2a0..0ba203a6944217ba50f9e811f42a93722f7062d5 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -1,6 +1,5 @@
 #include <regex.h>
 #include "osl.h"
-#include "afh.h"
 #include "hash.h"
 
 #define DATABASE_DIR "/home/maan/tmp/osl" /* FIXME */
@@ -94,6 +93,7 @@ struct audio_file_data {
 
 /* afs */
 typedef int callback_function(const struct osl_object *, struct osl_object *);
+__noreturn int afs_init(uint32_t cookie, int socket_fd);
 int send_callback_request(callback_function *f, struct osl_object *query,
        struct osl_object *result);
 int send_standard_callback_request(int argc, const char **argv,
index 36da960b30d70673b1dfef94c6068a71fa5687c8..72be6a9da47223b2849b28c97c1427a7cb22df59 100644 (file)
@@ -7,7 +7,9 @@
 
 /** \file afs_common.c Functions common to all audio file selectors. */
 
+#include "para.h"
 #include "server.cmdline.h"
+#include "afh.h"
 #include "server.h"
 #include "vss.h"
 #include <dirent.h> /* readdir() */
diff --git a/aft.c b/aft.c
index c2c3274607abfb89631b76c407d7d4c02efb905c..503105efabafb1cba792231d767c6c142197889a 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -2,6 +2,7 @@
 #include "error.h"
 #include <sys/mman.h>
 #include <fnmatch.h>
+#include "afh.h"
 #include "afs.h"
 #include "string.h"
 
index db38faddd3294f1d4eb483b40bb67369016023fa..d4a0bfaf8f48e0a14e21dc5065134e2ea6587be3 100644 (file)
@@ -1,5 +1,6 @@
 #include "para.h"
 #include "error.h"
+#include "afh.h"
 #include "afs.h"
 #include "string.h"
 
diff --git a/blob.c b/blob.c
index 25dd99e021a91e5ca137fac7cd069e8f117df27b..b970ab6517742f1ea38bd13bd4dab29bac21f530 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -1,5 +1,6 @@
 #include "para.h"
 #include "error.h"
+#include "afh.h"
 #include "afs.h"
 #include "string.h"
 
index ae4c700c787c57aabca85996b33fc54d93e325ea..ecadfc401e206f4697f3350bdd784eef59c15272 100644 (file)
--- a/command.c
+++ b/command.c
@@ -7,8 +7,11 @@
 /** \file command.c does client authentication and executes server commands */
 
 #include <sys/time.h> /* gettimeofday */
+#include "para.h" /* gettimeofday */
+
 #include "server.cmdline.h"
 #include "afs_common.h"
+#include "afh.h"
 #include "server.h"
 #include "vss.h"
 #include "send.h"
index 3d2511f7ef755e759a2d2f486d4060a785cff225..4394b33bf2c5707f1895716de490c3bafda12ece 100644 (file)
@@ -11,6 +11,8 @@
  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
  */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "net.h"
 #include "list.h"
index e7a9ae2bc50c201c52cf0d3b25f896ecec515dd9..8636d10d2d71e41419cd762328004e194f5ac7cb 100644 (file)
@@ -7,7 +7,9 @@
 /** \file http_send.c paraslash's http sender */
 
 
+#include "para.h"
 #include "server.cmdline.h"
+#include "afh.h"
 #include "server.h"
 #include "http.h"
 #include "vss.h"
diff --git a/mood.c b/mood.c
index b65561d582e84a8e12ef57daa8523cce660d878a..996b71fac99257758e2a5d8cad9d6c018cf1ba06 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -1,5 +1,6 @@
 #include "para.h"
 #include "error.h"
+#include "afh.h"
 #include "afs.h"
 #include "list.h"
 #include "string.h"
@@ -235,11 +236,6 @@ static int mm_is_set_score_function(const struct osl_row *row, void *bitnum)
        return -100;
 }
 
-static int para_random(unsigned max)
-{
-       return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
-}
-
 /* returns 1 if row matches score item, -1 otherwise */
 static int add_item_score(const void *row, struct mood_item *item, long *score,
                long *score_arg_sum)
index dde71c505f8180d103d03d387e366a0427ccec4c..46fcfbca6102ab37be3b071c014a078fb738a46c 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -16,6 +16,8 @@
  *                      Johannes Overmann <overmann@iname.com>
  */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "error.h"
 #include "string.h"
index 46fc65b88b432bdba89fa6b892b3c180ba720a0e..702e08d3478a4f2c4c995ba4bc6dda68210a0b04 100644 (file)
 #define MEDIUM_BLOB_SIZE 16777220 /*  (2**24 + 4) */
 #define BLOB_SIZE 65539 /* (2**16 + 3) */
 /** \endcond */
+
+#include "para.h"
 #include "server.cmdline.h"
+#include "afh.h"
 #include "server.h"
 #include "vss.h"
 #include "afs_common.h"
index 6cabd4f104d9472da08964cd218a21e6c9172026..652ac53a122b5283e33851f266a619a85ae1e22f 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: server user_list
+IN: para afh server user_list
 SN: list of mysql selector commands
 ---
 N: cam
index a9b07a3c676515f610dc678ad06aa5cfcbb06435..1c0c63234e0837457fc3e8e79138c11367884494 100644 (file)
--- a/ogg_afh.c
+++ b/ogg_afh.c
@@ -10,6 +10,8 @@
 #include <vorbis/codec.h>
 #include <vorbis/vorbisfile.h>
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "error.h"
 #include "string.h"
index 18b5edd345fe66c048ee1dc0f2eaa4911e617fbe..e17c84746ea4215d833dba399c3e423a64789afb 100644 (file)
@@ -10,6 +10,8 @@
 #include <ortp/port.h>
 
 #include "server.cmdline.h"
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "vss.h"
 #include "send.h"
diff --git a/para.h b/para.h
index f41e8b67acfcf90fe07745fa30b4723245e8e8dd..eb99ec68e6f2609da70f8d75d3dc038c1c4ea59e 100644 (file)
--- a/para.h
+++ b/para.h
@@ -200,3 +200,9 @@ __printf_2_3 void para_log(int, const char*, ...);
                p = para_realloc(p, size); \
        } \
 }
+
+static inline int para_random(unsigned max)
+{
+       return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
+}
+
index 9153bf1f849246379e68b4605c749474fce2c656..6f952e65c1372b3a21ffba4819fd3bae34dbd2f5 100644 (file)
@@ -1,5 +1,6 @@
 #include "para.h"
 #include "error.h"
+#include "afh.h"
 #include "afs.h"
 #include "string.h"
 
index 8372dacc342def63b740032a0a5826bd49531731..9eb6305a9f5e26915b2eb6c07f4768943a14dda0 100644 (file)
@@ -6,6 +6,8 @@
 
 /** \file playlist_selector.c The playlist audio file selector of paraslash  */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include "afs_common.h"
 #include "error.h"
index 294adef4d7df8bb2dd1d2c1f4e19ce1b6dc4a871..2006647d1bded6e87799c2e2ba939a8c73d49c7d 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: server user_list
+IN: para afh server user_list
 SN: list of playlist selector commands
 ---
 N: ppl
index c3d7e9b0be860fdd635bbe54f64e6dd02ec8f493..36d4d5807ffe8416c6c6cf271ee285c8f08d581f 100644 (file)
@@ -7,7 +7,9 @@
 /** \file random_selector.c An audio file selector which chooses files by random */
 
 #include <sys/time.h> /* gettimeofday */
+#include "para.h"
 #include "server.cmdline.h"
+#include "afh.h"
 #include "server.h"
 #include "afs_common.h"
 #include "error.h"
index f1901f88d78934041af9993584adcf2bff2f54cf..578c4470022ed1a83bc81ae200f3345628b77f9e 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: server user_list
+IN: para afh server user_list
 SN: list of random selector commands
 ---
 N: random_info
diff --git a/score.c b/score.c
index 2cfadf86fd2835b47ba244cc53a12935cc0c9806..6c15a0f571e8cd79647493910f64edc7679c947c 100644 (file)
--- a/score.c
+++ b/score.c
@@ -7,6 +7,7 @@
 /** \file score.c Scoring functions to determine the audio file streaming order. */
 #include "para.h"
 #include "error.h"
+#include "afh.h"
 #include "afs.h"
 #include "list.h"
 #include "string.h"
index e39354e769ec04dc629c63f0bd590df30893dc8d..94e6564b783371fb8cd77e9f8c0a96eb55093f6f 100644 (file)
--- a/server.c
+++ b/server.c
  */
 
 
-
+#include "para.h"
 #include "server.cmdline.h"
 #include "afs_common.h"
+#include "afh.h"
 #include "server.h"
 #include "vss.h"
 #include "config.h"
@@ -32,6 +33,7 @@
 #include "fd.h"
 #include "signal.h"
 #include "user_list.h"
+#include "afs.h"
 
 /** define the array of error lists needed by para_server */
 INIT_SERVER_ERRLISTS;
@@ -344,6 +346,30 @@ out:
        exit(EXIT_FAILURE);
 }
 
+static uint32_t afs_socket_cookie;
+static int afs_socket;
+pid_t afs_pid;
+
+static void init_afs(void)
+{
+       int ret, afs_server_socket[2];
+
+       ret = socketpair(PF_UNIX, SOCK_DGRAM, 0, afs_server_socket);
+       if (ret < 0)
+               exit(EXIT_FAILURE);
+       afs_socket_cookie = para_random((uint32_t)-1);
+       afs_pid = fork();
+       if (afs_pid < 0)
+               exit(EXIT_FAILURE);
+       if (!afs_pid) /* child (afs) */
+               afs_init(afs_socket_cookie, afs_server_socket[1]);
+       close(afs_server_socket[1]);
+       afs_socket = afs_server_socket[0];
+       PARA_INFO_LOG("afs_socket: %d, afs_socket_cookie: %u\n", afs_socket,
+               (unsigned) afs_socket_cookie);
+}
+
+
 static unsigned do_inits(int argc, char **argv)
 {
        /* connector's address information */
@@ -369,6 +395,7 @@ static unsigned do_inits(int argc, char **argv)
        vss_init();
        mmd->server_pid = getpid();
        setup_signal_handling();
+       init_afs();
        mmd_lock();
        /* init network socket */
        PARA_NOTICE_LOG("%s", "initializing tcp command socket\n");
@@ -492,23 +519,34 @@ repeat:
        status_refresh();
        if (FD_ISSET(signal_pipe, &rfds)) {
                int sig;
+               pid_t pid;
                sig = para_next_signal();
                switch (sig) {
                case SIGHUP:
                        handle_sighup();
                        break;
                case SIGCHLD:
-                       para_reap_children();
+                       for (;;) {
+                               pid = para_reap_child();
+                               if (pid <= 0)
+                                       break;
+                               if (pid != afs_pid)
+                                       continue;
+                               PARA_EMERG_LOG("fatal: afs died\n");
+                               goto genocide;
+                       }
                        break;
                /* die on sigint/sigterm. Kill all children too. */
                case SIGINT:
                case SIGTERM:
                        PARA_EMERG_LOG("terminating on signal %d\n", sig);
+genocide:
                        kill(0, SIGTERM);
                        selectors[mmd->selector_num].shutdown();
                        mutex_destroy(mmd_mutex);
                        shm_detach(mmd);
                        shm_destroy(mmd_shm_id);
+
                        exit(EXIT_FAILURE);
                }
        }
index d9134693ebf362e43a024576adfc98e25b7244e0..b3755094776682b228473c7854b3c4117e51772e 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: server user_list
+IN: para afh server user_list
 SN: list of server commands
 ---
 N: chs
index 08fa11b19e8379b2e91649094d19704f3be9c752..0cdd0e609c907ccb1cb8e58b0502413f86079ce6 100644 (file)
--- a/server.h
+++ b/server.h
@@ -6,8 +6,6 @@
 
 /** \file server.h common server data structures */
 
-#include "para.h"
-#include "afh.h"
 
 /** size of the selector_info and audio_file info strings of struct misc_meta_data */
 #define MMD_INFO_SIZE 16384
diff --git a/vss.c b/vss.c
index 859fd6119a524589fd17f1e316aba4a7942fa600..d0f57aec9a9cda035b58f561af8855a10dacbc05 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -11,6 +11,8 @@
  * senders.
  */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include <sys/mman.h> /* mmap */
 #include <sys/time.h> /* gettimeofday */