]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - server.c
web/index.html: Fix link to man pages.
[paraslash.git] / server.c
index 244c1ecd25da7959cf3ce6b9dcff3d9e814b2ad0..7da05898b69b528563fc0e902f0568c0728752a8 100644 (file)
--- a/server.c
+++ b/server.c
@@ -107,15 +107,17 @@ struct server_args_info conf;
 /** A random value used in child context for authentication. */
 uint32_t afs_socket_cookie;
 
+/** The mutex protecting the shared memory area containing the mmd struct. */
+int mmd_mutex;
+
 /* global variables for server-internal use */
 static FILE *logfile;
 /** The file containing user information (public key, permissions). */
 static char *user_list_file = NULL;
-static int mmd_mutex, mmd_shm_id;
-static pid_t afs_pid;
+static int mmd_shm_id;
 
 
-/** The task resposible for server command handling. */
+/** The task responsible for server command handling. */
 struct server_command_task {
        /** TCP port on which para_server listens for connections. */
        int listen_fd;
@@ -194,27 +196,6 @@ err_out:
        exit(EXIT_FAILURE);
 }
 
-/**
- * Lock the shared memory area containing the mmd struct.
- *
- * \sa semop(2), struct misc_meta_data.
- */
-void mmd_lock(void)
-{
-       mutex_lock(mmd_mutex);
-}
-
-/**
- * Unlock the shared memory area containing the mmd struct.
- *
- * \sa semop(2), struct misc_meta_data.
- */
-
-void mmd_unlock(void)
-{
-       mutex_unlock(mmd_mutex);
-}
-
 static void parse_config(int override)
 {
        char *home = para_homedir();
@@ -278,8 +259,8 @@ static void handle_sighup(void)
        logfile = NULL;
        parse_config(1); /* reopens log */
        init_user_list(user_list_file); /* reload user list */
-       if (afs_pid)
-               kill(afs_pid, SIGHUP);
+       if (mmd->afs_pid)
+               kill(mmd->afs_pid, SIGHUP);
 }
 
 static void signal_post_select(struct sched *s, struct task *t)
@@ -300,7 +281,7 @@ static void signal_post_select(struct sched *s, struct task *t)
                        int ret = para_reap_child(&pid);
                        if (ret <= 0)
                                break;
-                       if (pid != afs_pid)
+                       if (pid != mmd->afs_pid)
                                continue;
                        PARA_EMERG_LOG("fatal: afs died\n");
                        goto genocide;
@@ -466,10 +447,10 @@ static int init_afs(void)
        if (ret < 0)
                exit(EXIT_FAILURE);
        afs_socket_cookie = para_random((uint32_t)-1);
-       afs_pid = fork();
-       if (afs_pid < 0)
+       mmd->afs_pid = fork();
+       if (mmd->afs_pid < 0)
                exit(EXIT_FAILURE);
-       if (!afs_pid) { /* child (afs) */
+       if (!mmd->afs_pid) { /* child (afs) */
                close(afs_server_socket[0]);
                afs_init(afs_socket_cookie, afs_server_socket[1]);
        }
@@ -511,7 +492,6 @@ static void server_init(int argc, char **argv)
                daemon_init();
        PARA_NOTICE_LOG("initializing audio format handlers\n");
        afh_init();
-       mmd->server_pid = getpid();
        init_signal_task();
        PARA_NOTICE_LOG("initializing the audio file selector\n");
        afs_socket = init_afs();
@@ -552,9 +532,9 @@ static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds,
        int ret;
 
        status_refresh();
-       mmd_unlock();
+       mutex_unlock(mmd_mutex);
        ret = para_select(max_fileno + 1, readfds, writefds, timeout_tv);
-       mmd_lock();
+       mutex_lock(mmd_mutex);
        return ret;
 }
 
@@ -577,7 +557,7 @@ int main(int argc, char *argv[])
                .select_function = server_select
        };
        server_init(argc, argv);
-       mmd_lock();
+       mutex_lock(mmd_mutex);
        ret = schedule(&s);
        if (ret < 0) {
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));