Assorted typo fixes in comments.
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index 2f9df84581ee53685bbdb2282b6398a133fbf37f..68afec6c1c3a0a8b0b58b5ec74993dffa73e314c 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -1,15 +1,20 @@
 /*
- * Copyright (C) 2007-2013 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2014 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file afs.c Paraslash's audio file selector. */
 
+#include <netinet/in.h>
+#include <sys/socket.h>
 #include <regex.h>
 #include <signal.h>
 #include <fnmatch.h>
 #include <osl.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+#include <netdb.h>
 
 #include "server.cmdline.h"
 #include "para.h"
@@ -76,7 +81,7 @@ struct command_task {
         */
        uint32_t cookie;
        /** The associated task structure. */
-       struct task task;
+       struct task *task;
 };
 
 extern int mmd_mutex;
@@ -714,13 +719,13 @@ static int open_afs_tables(void)
        return ret;
 }
 
-static void signal_pre_select(struct sched *s, struct task *t)
+static void signal_pre_select(struct sched *s, void *context)
 {
-       struct signal_task *st = container_of(t, struct signal_task, task);
+       struct signal_task *st = context;
        para_fd_set(st->fd, &s->rfds, &s->max_fileno);
 }
 
-static int afs_signal_post_select(struct sched *s, __a_unused struct task *t)
+static int afs_signal_post_select(struct sched *s, __a_unused void *context)
 {
        int signum, ret;
 
@@ -757,15 +762,18 @@ static void register_signal_task(struct sched *s)
        para_install_sighandler(SIGTERM);
        para_install_sighandler(SIGHUP);
 
-       st->task.pre_select = signal_pre_select;
-       st->task.post_select = afs_signal_post_select;
-       sprintf(st->task.status, "signal task");
-       register_task(s, &st->task);
+       st->task = task_register(&(struct task_info) {
+               .name = "signal",
+               .pre_select = signal_pre_select,
+               .post_select = afs_signal_post_select,
+               .context = st,
+
+       }, s);
 }
 
 static struct list_head afs_client_list;
 
-/** Describes on connected afs client. */
+/** Describes one connected afs client. */
 struct afs_client {
        /** Position in the afs client list. */
        struct list_head node;
@@ -775,9 +783,9 @@ struct afs_client {
        struct timeval connect_time;
 };
 
-static void command_pre_select(struct sched *s, struct task *t)
+static void command_pre_select(struct sched *s, void *context)
 {
-       struct command_task *ct = container_of(t, struct command_task, task);
+       struct command_task *ct = context;
        struct afs_client *client;
 
        para_fd_set(server_socket, &s->rfds, &s->max_fileno);
@@ -912,14 +920,14 @@ err:
 /** Shutdown connection if query has not arrived until this many seconds. */
 #define AFS_CLIENT_TIMEOUT 3
 
-static int command_post_select(struct sched *s, struct task *t)
+static int command_post_select(struct sched *s, void *context)
 {
-       struct command_task *ct = container_of(t, struct command_task, task);
+       struct command_task *ct = context;
        struct sockaddr_un unix_addr;
        struct afs_client *client, *tmp;
        int fd, ret;
 
-       ret = task_get_notification(t);
+       ret = task_get_notification(ct->task);
        if (ret < 0)
                return ret;
        ret = execute_server_command(&s->rfds);
@@ -967,10 +975,12 @@ static void register_command_task(uint32_t cookie, struct sched *s)
        ct->fd = setup_command_socket_or_die();
        ct->cookie = cookie;
 
-       ct->task.pre_select = command_pre_select;
-       ct->task.post_select = command_post_select;
-       sprintf(ct->task.status, "afs command task");
-       register_task(s, &ct->task);
+       ct->task = task_register(&(struct task_info) {
+               .name = "afs command",
+               .pre_select = command_pre_select,
+               .post_select = command_post_select,
+               .context = ct,
+       }, s);
 }
 
 /**
@@ -1002,6 +1012,7 @@ __noreturn void afs_init(uint32_t cookie, int socket_fd)
        s.default_timeout.tv_sec = 0;
        s.default_timeout.tv_usec = 999 * 1000;
        ret = schedule(&s);
+       sched_shutdown(&s);
 out_close:
        close_afs_tables();
 out: