applications/luci-samba: forgot to commit a change of #117
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-lua.c
index e88c42e..ab09841 100644 (file)
@@ -211,8 +211,6 @@ lua_State * uh_lua_init(const char *handler)
 
 void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
 {
-       pid_t pid;
-
        int i, data_sent;
        int content_length = 0;
        int buflen = 0;
@@ -226,9 +224,12 @@ void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
 
        char buf[UH_LIMIT_MSGHEAD];
 
+       pid_t child;
+
        fd_set reader;
        fd_set writer;
 
+       struct sigaction sa;
        struct timeval timeout;
 
 
@@ -247,7 +248,7 @@ void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
        }
 
 
-       switch( (pid = fork()) )
+       switch( (child = fork()) )
        {
                case -1:
                        uh_http_sendhf(cl, 500, "Internal Server Error",
@@ -255,7 +256,13 @@ void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
                        break;
 
                case 0:
-                       /* child */
+                       /* restore SIGTERM */
+                       sa.sa_flags = 0;
+                       sa.sa_handler = SIG_DFL;
+                       sigemptyset(&sa.sa_mask);
+                       sigaction(SIGTERM, &sa, NULL);
+
+                       /* close loose pipe ends */
                        close(rfd[0]);
                        close(wfd[1]);
 
@@ -519,7 +526,16 @@ void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
                        close(rfd[0]);
                        close(wfd[1]);
 
+                       if( !kill(child, 0) )
+                               kill(child, SIGTERM);
+
                        break;
        }
 }
 
+void uh_lua_close(lua_State *L)
+{
+       lua_close(L);
+}
+
+