src/server/safs/cgi.c

changeset 497
8827517054ec
parent 451
edbbb3000494
child 498
0d80f8a2b29f
equal deleted inserted replaced
496:d511c13ba68d 497:8827517054ec
238 if(wr < 0) { 238 if(wr < 0) {
239 if(errno == EWOULDBLOCK) { 239 if(errno == EWOULDBLOCK) {
240 // copy remaining bytes to the write buffer 240 // copy remaining bytes to the write buffer
241 // we assume there are no remaining bytes in writebuf 241 // we assume there are no remaining bytes in writebuf
242 size_t remaining = size-pos; 242 size_t remaining = size-pos;
243 if(remaining <= handler->writebuf_alloc) { 243 if(remaining > handler->writebuf_alloc) {
244 memcpy(handler->writebuf, buf+pos, remaining);
245 } else {
246 handler->writebuf_alloc = size > 4096 ? size : 4096; 244 handler->writebuf_alloc = size > 4096 ? size : 4096;
247 handler->writebuf = pool_realloc(sn->pool, handler->writebuf, handler->writebuf_alloc); 245 handler->writebuf = pool_realloc(sn->pool, handler->writebuf, handler->writebuf_alloc);
248 if(!handler->writebuf) { 246 if(!handler->writebuf) {
249 handler->result = REQ_ABORTED; 247 handler->result = REQ_ABORTED;
250 return 1; 248 return 1;
251 } 249 }
252 } 250 }
251 memcpy(handler->writebuf, buf+pos, remaining);
253 handler->writebuf_size = remaining; 252 handler->writebuf_size = remaining;
254 handler->writebuf_pos = 0; 253 handler->writebuf_pos = 0;
255 254
256 // initialize poll, if it isn't already active 255 // initialize poll, if it isn't already active
257 if(!handler->poll_out) { 256 if(!handler->poll_out) {
259 handler->result = REQ_ABORTED; 258 handler->result = REQ_ABORTED;
260 return 1; 259 return 1;
261 } 260 }
262 handler->poll_out = TRUE; 261 handler->poll_out = TRUE;
263 } 262 }
264 return 1; 263 } else {
265 } 264 handler->result = REQ_ABORTED;
266 handler->result = REQ_ABORTED; 265 }
267 return 1; 266 return 1;
268 } 267 }
269 268
270 return 0; 269 return 0;
271 } 270 }
291 Request *rq = parser->rq; 290 Request *rq = parser->rq;
292 291
293 // try to flush handler->writebuf 292 // try to flush handler->writebuf
294 // if writebuf is empty, this does nothing and returns 0 293 // if writebuf is empty, this does nothing and returns 0
295 if(cgi_try_write_flush(handler, sn)) { 294 if(cgi_try_write_flush(handler, sn)) {
295 log_ereport(LOG_DEBUG, "cgi-send: req: %p write failed: abort", rq);
296 return handler->result == REQ_ABORTED ? 0 : 1; 296 return handler->result == REQ_ABORTED ? 0 : 1;
297 } 297 }
298 298
299 char buf[4096]; // I/O buffer 299 char buf[4096]; // I/O buffer
300 ssize_t r; 300 ssize_t r;
459 CGIHandler *handler = event->cookie; 459 CGIHandler *handler = event->cookie;
460 CGIResponseParser *parser = handler->parser; 460 CGIResponseParser *parser = handler->parser;
461 Session *sn = parser->sn; 461 Session *sn = parser->sn;
462 Request *rq = parser->rq; 462 Request *rq = parser->rq;
463 463
464 log_ereport(LOG_DEBUG, "cgi-send: req: %p event-finish", rq);
464 if(handler->result == REQ_ABORTED) { 465 if(handler->result == REQ_ABORTED) {
465 log_ereport(LOG_FAILURE, "cgi-send: kill script: %s", handler->path); 466 log_ereport(LOG_FAILURE, "cgi-send: kill script: %s", handler->path);
466 kill(handler->process.pid, SIGKILL); 467 kill(handler->process.pid, SIGKILL);
467 } 468 }
468 469
505 } 506 }
506 507
507 net_setnonblock(sn->csd, 0); 508 net_setnonblock(sn->csd, 0);
508 509
509 // return to nsapi loop 510 // return to nsapi loop
511 log_ereport(LOG_DEBUG, "cgi-send: req: %p event-finish nsapi return", rq);
510 nsapi_function_return(sn, rq, handler->result); 512 nsapi_function_return(sn, rq, handler->result);
511 return 0; 513 return 0;
512 } 514 }
513 515
514 int cgi_start(CGIProcess *p, char *path, char *const argv[], char *const envp[]) { 516 int cgi_start(CGIProcess *p, char *path, char *const argv[], char *const envp[]) {

mercurial