summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'daemon')
-rw-r--r--daemon/httpauthd.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c
index 8897d5f..d3efbe9 100644
--- a/daemon/httpauthd.c
+++ b/daemon/httpauthd.c
@@ -299,8 +299,11 @@ int main(int argc, char* argv[])
/* Handle some signals */
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
-/* signal(SIGINT, on_quit);
- signal(SIGTERM, on_quit); */
+ signal(SIGINT, on_quit);
+ signal(SIGTERM, on_quit);
+
+ siginterrupt(SIGINT, 1);
+ siginterrupt(SIGTERM, 1);
/* Open the system log */
openlog("httpauthd", 0, LOG_AUTHPRIV);
@@ -312,7 +315,7 @@ int main(int argc, char* argv[])
{
int fd;
- fd = accept(sock, 0, 0);
+ fd = accept(sock, NULL, NULL);
if(fd == -1)
{
switch(errno)
@@ -331,6 +334,9 @@ int main(int argc, char* argv[])
break;
};
+ if(g_quit)
+ break;
+
continue;
}
@@ -391,7 +397,12 @@ int main(int argc, char* argv[])
{
/* Clean up quit threads */
if(threads[i].tid != 0)
+ {
+ if(threads[i].fd != -1)
+ shutdown(threads[i].fd, SHUT_RDWR);
+
pthread_join(threads[i].tid, NULL);
+ }
}
r = 0;
@@ -422,7 +433,7 @@ finally:
pthread_mutex_destroy(&g_mutex);
pthread_mutexattr_destroy(&g_mutexattr);
- ha_messagex(LOG_DEBUG, "done");
+ ha_messagex(LOG_DEBUG, "stopped");
return r == -1 ? 1 : 0;
}
@@ -430,6 +441,7 @@ finally:
static void on_quit(int signal)
{
g_quit = 1;
+ fprintf(stderr, "httpauthd: got signal to quit\n");
}
static int usage()
@@ -461,6 +473,9 @@ static void* httpauth_thread(void* arg)
httpauth_thread_t* thread = (httpauth_thread_t*)arg;
int r;
+ siginterrupt(SIGINT, 1);
+ siginterrupt(SIGTERM, 1);
+
ASSERT(thread);
ASSERT(thread->fd != -1);
@@ -1037,15 +1052,12 @@ static int httpauth_processor(int ifd, int ofd)
}
/* Now loop and handle the commands */
- while(result == -1 && !g_quit)
+ while(result == -1)
{
ha_bufreset(&buf);
r = httpauth_read(ifd, &req, &buf);
- if(g_quit)
- continue;
-
if(ha_buferr(&buf))
r = HA_CRITERROR;
@@ -1086,9 +1098,6 @@ static int httpauth_processor(int ifd, int ofd)
break;
};
- if(g_quit)
- continue;
-
if(ha_buferr(&buf))
r = HA_CRITERROR;