MCPcopy Create free account
hub / github.com/apache/httpd / cgi_bucket_read

Function cgi_bucket_read

modules/generators/cgi_common.h:348–405  ·  view source on GitHub ↗

Read method of CGI bucket: polls on stderr and stdout of the child, * sending any stderr output immediately away to the error log. */

Source from the content-addressed store, hash-verified

346/* Read method of CGI bucket: polls on stderr and stdout of the child,
347 * sending any stderr output immediately away to the error log. */
348static apr_status_t cgi_bucket_read(apr_bucket *b, const char **str,
349 apr_size_t *len, apr_read_type_e block)
350{
351 struct cgi_bucket_data *data = b->data;
352 apr_interval_time_t timeout = 0;
353 apr_status_t rv;
354 int gotdata = 0;
355
356 if (block != APR_NONBLOCK_READ) {
357 timeout = data->timeout > 0 ? data->timeout : data->r->server->timeout;
358 }
359
360 do {
361 const apr_pollfd_t *results;
362 apr_int32_t num;
363
364 rv = apr_pollset_poll(data->pollset, timeout, &num, &results);
365 if (APR_STATUS_IS_TIMEUP(rv)) {
366 if (timeout) {
367 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, data->r, APLOGNO(01220)
368 "Timeout waiting for output from CGI script %s",
369 data->r->filename);
370 return rv;
371 }
372 else {
373 return APR_EAGAIN;
374 }
375 }
376 else if (APR_STATUS_IS_EINTR(rv)) {
377 continue;
378 }
379 else if (rv != APR_SUCCESS) {
380 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, data->r, APLOGNO(01221)
381 "poll failed waiting for CGI child");
382 return rv;
383 }
384
385 for (; num; num--, results++) {
386 if (results[0].client_data == (void *)1) {
387 /* stdout */
388 rv = cgi_read_stdout(b, results[0].desc.f, str, len);
389 if (APR_STATUS_IS_EOF(rv)) {
390 rv = APR_SUCCESS;
391 }
392 gotdata = 1;
393 } else {
394 /* stderr */
395 apr_status_t rv2 = log_script_err(data->r, results[0].desc.f);
396 if (APR_STATUS_IS_EOF(rv2)) {
397 apr_pollset_remove(data->pollset, &results[0]);
398 }
399 }
400 }
401
402 } while (!gotdata);
403
404 return rv;
405}

Callers

nothing calls this directly

Calls 2

cgi_read_stdoutFunction · 0.85
log_script_errFunction · 0.85

Tested by

no test coverage detected