Register signal handlers in handlesignals()

This commit is contained in:
Quentin Rameau 2017-07-24 00:48:06 +02:00 committed by Laslo Hunhold
parent 3373992ca5
commit 947b5a6a0a

47
quark.c
View file

@ -890,6 +890,28 @@ getipsock(void)
return insock; 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 static int
getusock(char *udsname, uid_t uid, gid_t gid) getusock(char *udsname, uid_t uid, gid_t gid)
{ {
@ -933,23 +955,6 @@ getusock(char *udsname, uid_t uid, gid_t gid)
return insock; 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 static void
usage(void) usage(void)
{ {
@ -1005,12 +1010,6 @@ main(int argc, char *argv[])
usage(); 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 */ /* compile and check the supplied vhost regexes */
if (vhosts) { if (vhosts) {
for (i = 0; i < LEN(vhost); i++) { for (i = 0; i < LEN(vhost); i++) {
@ -1038,6 +1037,8 @@ main(int argc, char *argv[])
die("%s: invalid group %s\n", argv0, group); die("%s: invalid group %s\n", argv0, group);
} }
handlesignals(sigcleanup);
/* bind socket */ /* bind socket */
insock = udsname ? getusock(udsname, pwd->pw_uid, grp->gr_gid) : insock = udsname ? getusock(udsname, pwd->pw_uid, grp->gr_gid) :
getipsock(); getipsock();