src/server/safs/cgi.c

changeset 450
d7b276de183b
parent 433
39fe86ae4db0
child 451
edbbb3000494
equal deleted inserted replaced
449:a28a5ccc894b 450:d7b276de183b
39 #include <cx/string.h> 39 #include <cx/string.h>
40 40
41 #include "../util/util.h" 41 #include "../util/util.h"
42 #include "../util/pblock.h" 42 #include "../util/pblock.h"
43 #include "../daemon/netsite.h" 43 #include "../daemon/netsite.h"
44 #include "../daemon/vfs.h"
44 #include "../util/io.h" 45 #include "../util/io.h"
45 #include "../daemon/event.h" 46 #include "../daemon/event.h"
46 47
47 #include "cgiutils.h" 48 #include "cgiutils.h"
48 49
64 protocol_status(sn, rq, 400, NULL); 65 protocol_status(sn, rq, 400, NULL);
65 return REQ_ABORTED; 66 return REQ_ABORTED;
66 } 67 }
67 } 68 }
68 69
70 // using stat, not vfs_stat, because running scripts/executables works only
71 // with the sys fs
72 if(!vfs_is_sys(rq->vfs)) {
73 log_ereport(LOG_WARN, "send-cgi: VFS setting ignored");
74 }
75
69 struct stat s; 76 struct stat s;
70 if(stat(path, &s)) { 77 if(stat(path, &s)) {
71 int statuscode = util_errno2status(errno); 78 int statuscode = util_errno2status(errno);
72 protocol_status(sn, rq, statuscode, NULL); 79 protocol_status(sn, rq, statuscode, NULL);
73 return REQ_ABORTED; 80 return REQ_ABORTED;
113 if(content_length > 0) { 120 if(content_length > 0) {
114 ssize_t n = 0; 121 ssize_t n = 0;
115 while(n < content_length) { 122 while(n < content_length) {
116 r = netbuf_getbytes(sn->inbuf, buf, 4096); 123 r = netbuf_getbytes(sn->inbuf, buf, 4096);
117 if(r <= 0) { 124 if(r <= 0) {
118 // TODO: handle error
119 log_ereport( 125 log_ereport(
120 LOG_FAILURE, 126 LOG_FAILURE,
121 "send-cgi: script: %s: cannot read request body", 127 "send-cgi: script: %s: cannot read request body",
122 path); 128 path);
123 kill(handler->process.pid, SIGTERM); 129 kill(handler->process.pid, SIGTERM);
124 cgi_close(&handler->process); 130 cgi_close(&handler->process);
125 return REQ_ABORTED; 131 return REQ_ABORTED;
126 } 132 }
127 ssize_t w = write(handler->process.in[1], buf, r); 133 ssize_t w = write(handler->process.in[1], buf, r);
128 if(w <= 0) { 134 if(w <= 0) {
129 // TODO: handle error
130 log_ereport( 135 log_ereport(
131 LOG_FAILURE, 136 LOG_FAILURE,
132 "send-cgi: script: %s: cannot send request body to cgi process", 137 "send-cgi: script: %s: cannot send request body to cgi process",
133 path); 138 path);
134 kill(handler->process.pid, SIGKILL); 139 kill(handler->process.pid, SIGKILL);
194 199
195 if(error) { 200 if(error) {
196 log_ereport(LOG_FAILURE, "cgi-send: kill script: %s", path); 201 log_ereport(LOG_FAILURE, "cgi-send: kill script: %s", path);
197 kill(handler->process.pid, SIGKILL); 202 kill(handler->process.pid, SIGKILL);
198 cgi_parser_free(handler->parser); 203 cgi_parser_free(handler->parser);
204 cgi_close(&handler->process);
199 return REQ_ABORTED; 205 return REQ_ABORTED;
200 } 206 }
201 207
202 return REQ_PROCESSING; 208 return REQ_PROCESSING;
203 } 209 }

mercurial