commit 947b5a6a0aaa7c6eaa4012b082173a50cb89b5de
Author:     Quentin Rameau <[email protected]>
AuthorDate: Mon Jul 24 00:48:06 2017 +0200
Commit:     Laslo Hunhold <[email protected]>
CommitDate: Mon Jul 24 16:49:24 2017 +0200

    Register signal handlers in handlesignals()

diff --git a/quark.c b/quark.c
index fd78c1d..5ca7d34 100644
--- a/quark.c
+++ b/quark.c
@@ -890,6 +890,28 @@ getipsock(void)
        return insock;
 }
 
+static void
+cleanup(void)
+{
+       close(insock);
+       if (udsname) {
+               if (unlink(udsname) < 0)
+                       fprintf(stderr, "unlink: %s\n", strerror(errno));
+}
+
+static void
+sigcleanup(int sig)
+{
+       cleanup();
+       _exit(1);
+}
+
+static void
+handlesignals(void(*hdl)(int))
+{
+       signal(SIGINT, hdl);
+}
+
 static int
 getusock(char *udsname, uid_t uid, gid_t gid)
 {
@@ -934,23 +956,6 @@ getusock(char *udsname, uid_t uid, gid_t gid)
 }
 
 static void
-cleanup(void)
-{
-       close(insock);
-       if (udsname) {
-               if (unlink(udsname) < 0)
-                       fprintf(stderr, "unlink: %s\n", strerror(errno));
-       }
-}
-
-static void
-sigcleanup(int sig)
-{
-       cleanup();
-       _exit(1);
-}
-
-static void
 usage(void)
 {
        die("usage: %s [-l | -L] [-v | -V] [[[-h host] [-p port]] | [-U 
sockfile]] "
@@ -1005,12 +1010,6 @@ main(int argc, char *argv[])
                usage();
        }
 
-       if (signal(SIGINT, sigcleanup) == SIG_ERR) {
-               fprintf(stderr, "%s: signal: Failed to handle SIGINT\n",
-                       argv0);
-               return 1;
-       }
-
        /* compile and check the supplied vhost regexes */
        if (vhosts) {
                for (i = 0; i < LEN(vhost); i++) {
@@ -1038,6 +1037,8 @@ main(int argc, char *argv[])
                die("%s: invalid group %s\n", argv0, group);
        }
 
+       handlesignals(sigcleanup);
+
        /* bind socket */
        insock = udsname ? getusock(udsname, pwd->pw_uid, grp->gr_gid) :
                           getipsock();

Reply via email to