uhttpd: deliver SIGTERM to child when parent leaves I/O loop
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-cgi.c
index a6e5d99e07ab7485bf882d709aa1ed08d6c910c6..a239c8bc992ae30a0930defdfd93f89c7d20da16 100644 (file)
@@ -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;
        }
 }