about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-01-24 03:28:51 +0000
committerEric Wong <normalperson@yhbt.net>2013-01-31 02:10:38 +0000
commit80aef1b3c8e9a20ec047dcf040e594a5e2a23811 (patch)
treeba893dfb1776dddc8f716d89533a527828a81660
parent25d7a82d9851c204e6ca47ab8af35fdab9bbd37c (diff)
downloadcmogstored-80aef1b3c8e9a20ec047dcf040e594a5e2a23811.tar.gz
No need to clutter up the main file with graceful exit
functionality.
-rw-r--r--Makefile.am1
-rw-r--r--cmogstored.c46
-rw-r--r--exit.c51
3 files changed, 53 insertions, 45 deletions
diff --git a/Makefile.am b/Makefile.am
index c60c960..d7f0b4e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,6 +31,7 @@ mog_src += defaults.h
 mog_src += dev.c
 mog_src += digest.c
 mog_src += digest.h
+mog_src += exit.c
 mog_src += fadvise.h
 mog_src += fdmap.c
 mog_src += fdmap.h
diff --git a/cmogstored.c b/cmogstored.c
index efe5f2b..b21f20f 100644
--- a/cmogstored.c
+++ b/cmogstored.c
@@ -5,6 +5,7 @@
 #include "cmogstored.h"
 #include "cfg.h"
 #include "nostd/setproctitle.h"
+_Noreturn void cmogstored_exit(void);
 #define THIS "cmogstored"
 #define DESC "alternative mogstored implementation for MogileFS"
 static char summary[] = THIS " -- "DESC;
@@ -308,51 +309,6 @@ static bool svc_start_each(void *svcptr, void *qptr)
         return true;
 }
 
-static void acceptor_quit(int fd)
-{
-        if (fd >= 0) {
-                struct mog_fd *mfd = mog_fd_get(fd);
-                struct mog_accept *ac = &mfd->as.accept;
-
-                mog_thrpool_quit(&ac->thrpool, NULL);
-                mog_fd_put(mfd);
-        }
-}
-
-static bool svc_quit_accept_i(void *svcptr, void *ignored)
-{
-        struct mog_svc *svc = svcptr;
-
-        acceptor_quit(svc->mgmt_fd);
-        acceptor_quit(svc->http_fd);
-        acceptor_quit(svc->httpget_fd);
-
-        return true;
-}
-
-static bool svc_queue_set(void *svcptr, void *queue)
-{
-        struct mog_svc *svc = svcptr;
-
-        svc->queue = queue;
-
-        return true;
-}
-
-_Noreturn static void cmogstored_exit(void)
-{
-        /* call atexit() handlers and make valgrind happy */
-        setproctitle("cmogstored, shutting down");
-        mog_svc_each(svc_quit_accept_i, NULL);
-        mog_svc_dev_shutdown();
-        mog_queue_stop(mog_notify_queue);
-        mog_svc_dev_shutdown();
-        mog_svc_each(svc_queue_set, mog_notify_queue);
-        mog_fdmap_requeue(mog_notify_queue);
-        mog_queue_quit_loop(mog_notify_queue);
-        exit(EXIT_SUCCESS);
-}
-
 static void worker_wakeup_handler(int signum)
 {
         switch (signum) {
diff --git a/exit.c b/exit.c
new file mode 100644
index 0000000..d558501
--- /dev/null
+++ b/exit.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012-2013, Eric Wong <normalperson@yhbt.net>
+ * License: GPLv3 or later (see COPYING for details)
+ */
+#include "cmogstored.h"
+#include "nostd/setproctitle.h"
+
+static void acceptor_quit(int fd)
+{
+        if (fd >= 0) {
+                struct mog_fd *mfd = mog_fd_get(fd);
+                struct mog_accept *ac = &mfd->as.accept;
+
+                mog_thrpool_quit(&ac->thrpool, NULL);
+                mog_fd_put(mfd);
+        }
+}
+
+static bool svc_quit_accept_i(void *svcptr, void *ignored)
+{
+        struct mog_svc *svc = svcptr;
+
+        acceptor_quit(svc->mgmt_fd);
+        acceptor_quit(svc->http_fd);
+        acceptor_quit(svc->httpget_fd);
+
+        return true;
+}
+
+static bool svc_queue_set(void *svcptr, void *queue)
+{
+        struct mog_svc *svc = svcptr;
+
+        svc->queue = queue;
+
+        return true;
+}
+
+_Noreturn void cmogstored_exit(void)
+{
+        /* call atexit() handlers and make valgrind happy */
+        setproctitle("cmogstored, shutting down");
+        mog_svc_each(svc_quit_accept_i, NULL);
+        mog_svc_dev_shutdown();
+        mog_queue_stop(mog_notify_queue);
+        mog_svc_dev_shutdown();
+        mog_svc_each(svc_queue_set, mog_notify_queue);
+        mog_fdmap_requeue(mog_notify_queue);
+        mog_queue_quit_loop(mog_notify_queue);
+        exit(EXIT_SUCCESS);
+}