148:d861ee1455bf | 149:aa016efb9ad7 |
---|---|
30 | 30 |
31 #include <stdio.h> | 31 #include <stdio.h> |
32 #include <stdlib.h> | 32 #include <stdlib.h> |
33 #include <unistd.h> | 33 #include <unistd.h> |
34 | 34 |
35 #include <sys/types.h> | |
36 #include <signal.h> | |
37 #include <sys/wait.h> | |
38 | |
35 #include "../util/util.h" | 39 #include "../util/util.h" |
36 #include "../util/pblock.h" | 40 #include "../util/pblock.h" |
37 #include "../../ucx/string.h" | 41 #include "../../ucx/string.h" |
38 | 42 |
39 #include "../util/io.h" | 43 #include "../util/io.h" |
98 ssize_t n = 0; | 102 ssize_t n = 0; |
99 while(n < content_length) { | 103 while(n < content_length) { |
100 r = netbuf_getbytes(sn->inbuf, buf, 4096); | 104 r = netbuf_getbytes(sn->inbuf, buf, 4096); |
101 if(r <= 0) { | 105 if(r <= 0) { |
102 // TODO: handleerror | 106 // TODO: handleerror |
107 kill(cgip.pid, SIGTERM); | |
103 cgi_close(&cgip); | 108 cgi_close(&cgip); |
104 return REQ_ABORTED; | 109 return REQ_ABORTED; |
105 } | 110 } |
106 write(cgip.in[1], buf, r); | 111 write(cgip.in[1], buf, r); |
107 n += r; | 112 n += r; |
146 break; | 151 break; |
147 } | 152 } |
148 } | 153 } |
149 } | 154 } |
150 | 155 |
151 cgi_close(&cgip); | 156 cgi_close(&cgip); // TODO: check return value |
152 | 157 |
153 cgi_parser_free(parser); | 158 cgi_parser_free(parser); |
154 return result; | 159 return result; |
155 } | 160 } |
156 | 161 |
207 } | 212 } |
208 | 213 |
209 return REQ_PROCEED; | 214 return REQ_PROCEED; |
210 } | 215 } |
211 | 216 |
212 void cgi_close(CGIProcess *p) { | 217 int cgi_close(CGIProcess *p) { |
218 int status = -1; | |
219 waitpid(p->pid, &status, 0); | |
220 | |
213 if(p->in[0] != -1) { | 221 if(p->in[0] != -1) { |
214 close(p->in[0]); | 222 close(p->in[0]); |
215 } | 223 } |
216 if(p->in[1] != -1) { | 224 if(p->in[1] != -1) { |
217 close(p->in[1]); | 225 close(p->in[1]); |
220 close(p->out[0]); | 228 close(p->out[0]); |
221 } | 229 } |
222 if(p->out[1] != -1) { | 230 if(p->out[1] != -1) { |
223 close(p->out[1]); | 231 close(p->out[1]); |
224 } | 232 } |
233 | |
234 return 0; | |
225 } | 235 } |
226 | 236 |
227 CGIResponseParser* cgi_parser_new(Session *sn, Request *rq) { | 237 CGIResponseParser* cgi_parser_new(Session *sn, Request *rq) { |
228 CGIResponseParser* parser = pool_malloc(sn->pool, sizeof(CGIResponseParser)); | 238 CGIResponseParser* parser = pool_malloc(sn->pool, sizeof(CGIResponseParser)); |
229 parser->sn = sn; | 239 parser->sn = sn; |