src/server/safs/cgi.c

changeset 171
af7e2d80dee6
parent 164
6f47eb624665
child 254
4784c14aa639
equal deleted inserted replaced
169:76c96ee18221 171:af7e2d80dee6
37 #include <sys/wait.h> 37 #include <sys/wait.h>
38 38
39 #include "../util/util.h" 39 #include "../util/util.h"
40 #include "../util/pblock.h" 40 #include "../util/pblock.h"
41 #include "../../ucx/string.h" 41 #include "../../ucx/string.h"
42 42 #include "../daemon/netsite.h"
43 #include "../util/io.h" 43 #include "../util/io.h"
44 44
45 #include "cgiutils.h" 45 #include "cgiutils.h"
46 46
47 #define CGI_VARS 32 47 #define CGI_VARS 32
124 return REQ_ABORTED; 124 return REQ_ABORTED;
125 } 125 }
126 n += r; 126 n += r;
127 } 127 }
128 } 128 }
129 close(cgip.in[1]); 129 system_close(cgip.in[1]);
130 cgip.in[1] = -1; 130 cgip.in[1] = -1;
131 131
132 // read from child 132 // read from child
133 CGIResponseParser *parser = cgi_parser_new(sn, rq); 133 CGIResponseParser *parser = cgi_parser_new(sn, rq);
134 WSBool cgiheader = TRUE; 134 WSBool cgiheader = TRUE;
236 exit(EXIT_FAILURE); 236 exit(EXIT_FAILURE);
237 } 237 }
238 238
239 // we need to close this unused pipe 239 // we need to close this unused pipe
240 // otherwise stdin cannot reach EOF 240 // otherwise stdin cannot reach EOF
241 close(p->in[1]); 241 system_close(p->in[1]);
242 242
243 // execute program 243 // execute program
244 exit(execve(script.ptr, argv, envp)); 244 exit(execve(script.ptr, argv, envp));
245 } else { 245 } else {
246 // parent 246 // parent
247 close(p->out[1]); 247 system_close(p->out[1]);
248 p->out[1] = -1; 248 p->out[1] = -1;
249 } 249 }
250 250
251 return REQ_PROCEED; 251 return REQ_PROCEED;
252 } 252 }
254 int cgi_close(CGIProcess *p) { 254 int cgi_close(CGIProcess *p) {
255 int status = -1; 255 int status = -1;
256 waitpid(p->pid, &status, 0); 256 waitpid(p->pid, &status, 0);
257 257
258 if(p->in[0] != -1) { 258 if(p->in[0] != -1) {
259 close(p->in[0]); 259 system_close(p->in[0]);
260 } 260 }
261 if(p->in[1] != -1) { 261 if(p->in[1] != -1) {
262 close(p->in[1]); 262 system_close(p->in[1]);
263 } 263 }
264 if(p->out[0] != -1) { 264 if(p->out[0] != -1) {
265 close(p->out[0]); 265 system_close(p->out[0]);
266 } 266 }
267 if(p->out[1] != -1) { 267 if(p->out[1] != -1) {
268 close(p->out[1]); 268 system_close(p->out[1]);
269 } 269 }
270 270
271 return 0; 271 return 0;
272 } 272 }
273 273

mercurial