Fixing the socket handling and add signals to clients. - geomyidae - A small C-based gopherd.
Log
Files
Refs
README
LICENSE
---
commit dde23cfc01e8301d4263976f711f616f156932f7
parent 8e2c7276d2fa5fd44602707bd0621e0a91646bb8
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 21 Jul 2012 20:58:29 +0200

Fixing the socket handling and add signals to clients.

Diffstat:
  handlr.c                            |       4 ----
  main.c                              |       9 ++++++++-

2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/handlr.c b/handlr.c
@@ -163,8 +163,6 @@ handlecgi(int sock, char *file, char *port, char *base, char *args,
                 wait(NULL);
                 if (path != nil)
                         free(path);
-                shutdown(sock, SHUT_RDWR);
-                close(sock);
                 break;
         }
 }
@@ -228,8 +226,6 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
                 wait(NULL);
                 if (path != nil)
                         free(path);
-                shutdown(sock, SHUT_RDWR);
-                close(sock);
                 break;
         }
 }
diff --git a/main.c b/main.c
@@ -421,9 +421,15 @@ main(int argc, char *argv[])
                 switch(fork()) {
                 case -1:
                         perror("fork");
-                        close(sock);
+                        shutdown(sock, SHUT_RDWR);
                         break;
                 case 0:
+                        signal(SIGHUP, SIG_DFL);
+                        signal(SIGQUIT, SIG_DFL);
+                        signal(SIGINT, SIG_DFL);
+                        signal(SIGTERM, SIG_DFL);
+                        signal(SIGALRM, SIG_DFL);
+
                         handlerequest(sock, base, ohost, sport, clienth,
                                                 clientp);
                         shutdown(sock, SHUT_RDWR);
@@ -432,6 +438,7 @@ main(int argc, char *argv[])
                 default:
                         break;
                 }
+                close(sock);
         }
 
         shutdown(listfd, SHUT_RDWR);