Introduction
Introduction Statistics Contact Development Disclaimer Help
Cleaning up signal handling. - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit cb73df5b7e3746edcb70fd57b462161efec5385a
parent 0fbb73a1590a323d17ac96dad034c608b891e56c
Author: Christoph Lohmann <[email protected]>
Date: Sun, 27 Feb 2011 10:56:56 +0100
Cleaning up signal handling.
Diffstat:
M main.c | 42 +++++++++++++++++++++++------…
1 file changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/main.c b/main.c
@@ -33,6 +33,8 @@ enum {
int glfd = -1;
int loglvl = 15;
+int running = 1;
+char *logfile = nil;
char *argv0;
char *stdbase = "/var/gopher";
@@ -57,7 +59,6 @@ char *htredir = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
int
dropprivileges(struct group *gr, struct passwd *pw)
{
-
if(gr != nil)
if(setgroups(1, &gr->gr_gid) != 0 || setgid(gr->gr_gid) != 0)
return -1;
@@ -194,19 +195,41 @@ handlerequest(int sock, char *base, char *ohost, char *po…
}
void
-hndlsigchld(int signo)
+sighandler(int sig)
{
- int status;
-
- while(waitpid(-1, &status, WNOHANG) > 0);
+ switch(sig) {
+ case SIGCHLD:
+ while(waitpid(-1, NULL, WNOHANG) > 0);
+ break;
+ case SIGHUP:
+ case SIGINT:
+ case SIGQUIT:
+ case SIGABRT:
+ case SIGTERM:
+ if(logfile != nil)
+ stoplogging(glfd);
+ running = 0;
+ break;
+ default:
+ break;
+ }
+}
- return;
+void
+initsignals(void)
+{
+ signal(SIGCHLD, sighandler);
+ signal(SIGHUP, sighandler);
+ signal(SIGINT, sighandler);
+ signal(SIGQUIT, sighandler);
+ signal(SIGABRT, sighandler);
+ signal(SIGTERM, sighandler);
+ signal(SIGKILL, sighandler);
}
void
usage(void)
{
-
tprintf(2, "usage: %s [-d] [-l logfile] [-v loglvl] [-b base]"
" [-p port] [-o sport] [-u user] [-g group] [-h host]"
" [-i IP]\n",
@@ -222,7 +245,7 @@ main(int argc, char *argv[])
struct sockaddr_storage clt;
socklen_t cltlen;
int sock, list, opt, dofork;
- char *port, *base, *logfile, clienth[NI_MAXHOST], clientp[NI_MAXSERV];
+ char *port, *base, clienth[NI_MAXHOST], clientp[NI_MAXSERV];
char *user, *group, *bindip, *ohost, *sport;
struct passwd *us;
struct group *gr;
@@ -230,7 +253,6 @@ main(int argc, char *argv[])
base = stdbase;
port = stdport;
dofork = 1;
- logfile = nil;
user = nil;
group = nil;
us = nil;
@@ -349,7 +371,7 @@ main(int argc, char *argv[])
signal(SIGCHLD, hndlsigchld);
cltlen = sizeof(clt);
- for(;;) {
+ while(running) {
sock = accept(list, (struct sockaddr *)&clt, &cltlen);
if(sock < 0) {
perror("accept");
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.