fix cgi pipes not closed in some error case + minor improvements

Sun, 04 Dec 2022 09:09:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 04 Dec 2022 09:09:55 +0100
changeset 450
d7b276de183b
parent 449
a28a5ccc894b
child 451
edbbb3000494

fix cgi pipes not closed in some error case + minor improvements

src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.h file | annotate | diff | comparison | revisions
src/server/safs/cgi.c file | annotate | diff | comparison | revisions
src/server/util/system.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/vfs.c	Sat Dec 03 18:00:35 2022 +0100
+++ b/src/server/daemon/vfs.c	Sun Dec 04 09:09:55 2022 +0100
@@ -780,6 +780,12 @@
     return 0;
 }
 
+NSAPI_PUBLIC int vfs_is_sys(VFS *vfs) {
+    if(!vfs) return 1;
+    if(vfs == &sys_vfs) return 1;
+    return 0;
+}
+
 // AIO API
 
 NSAPI_PUBLIC int system_aio_read(aiocb_s *aiocb) {
--- a/src/server/daemon/vfs.h	Sat Dec 03 18:00:35 2022 +0100
+++ b/src/server/daemon/vfs.h	Sun Dec 04 09:09:55 2022 +0100
@@ -92,6 +92,8 @@
 int sys_unlink(VFSContext *ctx, const char *path, SysACL *sysacl);
 int sys_rmdir(VFSContext *ctx, const char *path, SysACL *sysacl);
 
+NSAPI_PUBLIC int vfs_is_sys(VFS *vfs);
+
 void vfs_queue_aio(aiocb_s *aiocb, VFSAioOp op);
 
 #ifdef	__cplusplus
--- a/src/server/safs/cgi.c	Sat Dec 03 18:00:35 2022 +0100
+++ b/src/server/safs/cgi.c	Sun Dec 04 09:09:55 2022 +0100
@@ -41,6 +41,7 @@
 #include "../util/util.h"
 #include "../util/pblock.h"
 #include "../daemon/netsite.h"
+#include "../daemon/vfs.h"
 #include "../util/io.h"
 #include "../daemon/event.h"
 
@@ -66,6 +67,12 @@
         }
     }
     
+    // using stat, not vfs_stat, because running scripts/executables works only
+    // with the sys fs
+    if(!vfs_is_sys(rq->vfs)) {
+        log_ereport(LOG_WARN, "send-cgi: VFS setting ignored");
+    }
+    
     struct stat s;
     if(stat(path, &s)) {
         int statuscode = util_errno2status(errno);
@@ -115,7 +122,6 @@
         while(n < content_length) {
             r = netbuf_getbytes(sn->inbuf, buf, 4096);
             if(r <= 0) {
-                // TODO: handle error
                 log_ereport(
                         LOG_FAILURE,
                         "send-cgi: script: %s: cannot read request body",
@@ -126,7 +132,6 @@
             }
             ssize_t w = write(handler->process.in[1], buf, r);
             if(w <= 0) {
-                // TODO: handle error
                 log_ereport(
                         LOG_FAILURE,
                         "send-cgi: script: %s: cannot send request body to cgi process",
@@ -196,6 +201,7 @@
         log_ereport(LOG_FAILURE, "cgi-send: kill script: %s", path);
         kill(handler->process.pid, SIGKILL);
         cgi_parser_free(handler->parser);
+        cgi_close(&handler->process);
         return REQ_ABORTED;
     }
     
--- a/src/server/util/system.c	Sat Dec 03 18:00:35 2022 +0100
+++ b/src/server/util/system.c	Sun Dec 04 09:09:55 2022 +0100
@@ -333,7 +333,7 @@
         if(errno != EINTR) {
             return -1;
         } else {
-            log_ereport(LOG_VERBOSE, "close interrupted by signal"); // TODO: use debug log level
+            log_ereport(LOG_DEBUG, "close interrupted by signal");
         }
     }
     return 0;

mercurial