adds more error handling and logging to send_cgi

Sat, 21 Jan 2017 15:31:17 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 21 Jan 2017 15:31:17 +0100
changeset 151
74d21dd5fd5d
parent 150
89af278b7dbb
child 152
8b85c5face66

adds more error handling and logging to send_cgi

src/server/safs/cgi.c file | annotate | diff | comparison | revisions
--- a/src/server/safs/cgi.c	Sat Jan 21 12:46:31 2017 +0100
+++ b/src/server/safs/cgi.c	Sat Jan 21 15:31:17 2017 +0100
@@ -103,12 +103,22 @@
         while(n < content_length) {
             r = netbuf_getbytes(sn->inbuf, buf, 4096);
             if(r <= 0) {
-                // TODO: handleerror
+                // TODO: handle error
+                log_ereport(LOG_FAILURE, "send-cgi: Cannot read request body");
                 kill(cgip.pid, SIGTERM);
                 cgi_close(&cgip);
-                return REQ_ABORTED; 
+                return REQ_ABORTED;
             }
-            write(cgip.in[1], buf, r);
+            ssize_t w = write(cgip.in[1], buf, r);
+            if(w <= 0) {
+                // TODO: handle error
+                log_ereport(
+                        LOG_FAILURE,
+                        "send-cgi: Cannot send request body to cgi process");
+                kill(cgip.pid, SIGTERM);
+                cgi_close(&cgip);
+                return REQ_ABORTED;
+            }
             n += r;
         }
     }
@@ -125,11 +135,12 @@
             size_t pos;
             ret = cgi_parse_response(parser, buf, r, &pos);
             if(ret == -1) {
+                log_ereport(
+                        LOG_FAILURE,
+                        "broken cgi script response: path: %s", path);
                 protocol_status(sn, rq, 500, NULL);
                 result = REQ_ABORTED;
                 break;
-            } else if(ret == 0) {
-                
             } else if(ret == 1) {
                 cgiheader = FALSE;
                 if(parser->status > 0) {

mercurial