src/server/safs/cgi.c

changeset 519
857e5b92828b
parent 518
538a8a22f622
child 520
0b09f0cb6098
equal deleted inserted replaced
518:538a8a22f622 519:857e5b92828b
712 } 712 }
713 713
714 return REQ_PROCEED; 714 return REQ_PROCEED;
715 } 715 }
716 716
717 int cgi_close(CGIProcess *p) { 717 int cgi_close(CGIProcess *p) {
718 int status = -1;
719 waitpid(p->pid, &status, 0);
720
721 if(p->in[0] != -1) { 718 if(p->in[0] != -1) {
722 system_close(p->in[0]); 719 system_close(p->in[0]);
723 } 720 }
724 if(p->in[1] != -1) { 721 if(p->in[1] != -1) {
725 system_close(p->in[1]); 722 system_close(p->in[1]);
733 if(p->err[0] != -1) { 730 if(p->err[0] != -1) {
734 system_close(p->err[0]); 731 system_close(p->err[0]);
735 } 732 }
736 if(p->err[1] != -1) { 733 if(p->err[1] != -1) {
737 system_close(p->err[1]); 734 system_close(p->err[1]);
735 }
736
737 // TODO: Because of WNOHANG, waitpid could fail and the process
738 // is still running. In that case, another waitpid call should
739 // be done later somewhere.
740 int status = -1;
741 if(waitpid(p->pid, &status, WNOHANG) == 0) {
742 log_ereport(LOG_DEBUG, "cgi_close: waitpid returned 0: pid: %d", (int)p->pid);
743 // cgi process still running
744 // workaround: sleep 1 sec and try again, if that fails again
745 sleep(1);
746 if(waitpid(p->pid, &status, WNOHANG) == 0) {
747 log_ereport(LOG_DEBUG, "cgi_close: waitpid returned 0 again: pid: %d", (int)p->pid);
748 }
738 } 749 }
739 750
740 return status; 751 return status;
741 } 752 }
742 753

mercurial