uhttpd: deliver SIGTERM to child when parent leaves I/O loop
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-cgi.c
index 5df045e..a239c8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * uhttpd - Tiny non-forking httpd - CGI handler
+ * uhttpd - Tiny single-threaded httpd - CGI handler
  *
  *   Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
  *
@@ -150,6 +150,8 @@ void uh_cgi_request(struct client *cl, struct http_request *req, struct path_inf
        char buf[UH_LIMIT_MSGHEAD];
        char hdr[UH_LIMIT_MSGHEAD];
 
+       pid_t child;
+
        fd_set reader;
        fd_set writer;
 
@@ -172,7 +174,7 @@ void uh_cgi_request(struct client *cl, struct http_request *req, struct path_inf
        }
 
        /* fork off child process */
-       switch( fork() )
+       switch( (child = fork()) )
        {
                /* oops */
                case -1:
@@ -543,6 +545,9 @@ void uh_cgi_request(struct client *cl, struct http_request *req, struct path_inf
                        close(rfd[0]);
                        close(wfd[1]);
 
+                       if( !kill(child, 0) )
+                               kill(child, SIGTERM);
+
                        break;
        }
 }