]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - afs.c
para_server: Initialize the new afs.
[paraslash.git] / afs.c
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;