commit 947b5a6a0aaa7c6eaa4012b082173a50cb89b5de
parent 3373992ca5b7ea51900a4a821379235b20e308b8
Author: Quentin Rameau <quinq@fifth.space>
Date: Mon, 24 Jul 2017 00:48:06 +0200
Register signal handlers in handlesignals()
Diffstat:
M | quark.c | | | 47 | ++++++++++++++++++++++++----------------------- |
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git 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();