101 if(content_length > 0) { |
101 if(content_length > 0) { |
102 ssize_t n = 0; |
102 ssize_t n = 0; |
103 while(n < content_length) { |
103 while(n < content_length) { |
104 r = netbuf_getbytes(sn->inbuf, buf, 4096); |
104 r = netbuf_getbytes(sn->inbuf, buf, 4096); |
105 if(r <= 0) { |
105 if(r <= 0) { |
106 // TODO: handleerror |
106 // TODO: handle error |
|
107 log_ereport(LOG_FAILURE, "send-cgi: Cannot read request body"); |
107 kill(cgip.pid, SIGTERM); |
108 kill(cgip.pid, SIGTERM); |
108 cgi_close(&cgip); |
109 cgi_close(&cgip); |
109 return REQ_ABORTED; |
110 return REQ_ABORTED; |
110 } |
111 } |
111 write(cgip.in[1], buf, r); |
112 ssize_t w = write(cgip.in[1], buf, r); |
|
113 if(w <= 0) { |
|
114 // TODO: handle error |
|
115 log_ereport( |
|
116 LOG_FAILURE, |
|
117 "send-cgi: Cannot send request body to cgi process"); |
|
118 kill(cgip.pid, SIGTERM); |
|
119 cgi_close(&cgip); |
|
120 return REQ_ABORTED; |
|
121 } |
112 n += r; |
122 n += r; |
113 } |
123 } |
114 } |
124 } |
115 close(cgip.in[1]); |
125 close(cgip.in[1]); |
116 cgip.in[1] = -1; |
126 cgip.in[1] = -1; |
123 while((r = read(cgip.out[0], buf, 4096)) > 0) { |
133 while((r = read(cgip.out[0], buf, 4096)) > 0) { |
124 if(cgiheader) { |
134 if(cgiheader) { |
125 size_t pos; |
135 size_t pos; |
126 ret = cgi_parse_response(parser, buf, r, &pos); |
136 ret = cgi_parse_response(parser, buf, r, &pos); |
127 if(ret == -1) { |
137 if(ret == -1) { |
|
138 log_ereport( |
|
139 LOG_FAILURE, |
|
140 "broken cgi script response: path: %s", path); |
128 protocol_status(sn, rq, 500, NULL); |
141 protocol_status(sn, rq, 500, NULL); |
129 result = REQ_ABORTED; |
142 result = REQ_ABORTED; |
130 break; |
143 break; |
131 } else if(ret == 0) { |
|
132 |
|
133 } else if(ret == 1) { |
144 } else if(ret == 1) { |
134 cgiheader = FALSE; |
145 cgiheader = FALSE; |
135 if(parser->status > 0) { |
146 if(parser->status > 0) { |
136 protocol_status(sn, rq, parser->status, parser->msg); |
147 protocol_status(sn, rq, parser->status, parser->msg); |
137 } |
148 } |