41a6c3
--- a/modules/generators/mod_cgid.c	2014/07/14 20:16:45	1610511
41a6c3
+++ b/modules/generators/mod_cgid.c	2014/07/14 20:18:26	1610512
41a6c3
@@ -97,6 +97,10 @@
41a6c3
 static pid_t parent_pid;
41a6c3
 static ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 };
41a6c3
 
41a6c3
+typedef struct { 
41a6c3
+    apr_interval_time_t timeout;
41a6c3
+} cgid_dirconf;
41a6c3
+
41a6c3
 /* The APR other-child API doesn't tell us how the daemon exited
41a6c3
  * (SIGSEGV vs. exit(1)).  The other-child maintenance function
41a6c3
  * needs to decide whether to restart the daemon after a failure
41a6c3
@@ -968,7 +972,14 @@
41a6c3
     return overrides->logname ? overrides : base;
41a6c3
 }
41a6c3
 
41a6c3
+static void *create_cgid_dirconf(apr_pool_t *p, char *dummy)
41a6c3
+{
41a6c3
+    cgid_dirconf *c = (cgid_dirconf *) apr_pcalloc(p, sizeof(cgid_dirconf));
41a6c3
+    return c;
41a6c3
+}
41a6c3
+
41a6c3
 static const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
41a6c3
+
41a6c3
 {
41a6c3
     server_rec *s = cmd->server;
41a6c3
     cgid_server_conf *conf = ap_get_module_config(s->module_config,
41a6c3
@@ -1021,7 +1032,16 @@
41a6c3
 
41a6c3
     return NULL;
41a6c3
 }
41a6c3
+static const char *set_script_timeout(cmd_parms *cmd, void *dummy, const char *arg)
41a6c3
+{
41a6c3
+    cgid_dirconf *dc = dummy;
41a6c3
 
41a6c3
+    if (ap_timeout_parameter_parse(arg, &dc->timeout, "s") != APR_SUCCESS) { 
41a6c3
+        return "CGIDScriptTimeout has wrong format";
41a6c3
+    }
41a6c3
+ 
41a6c3
+    return NULL;
41a6c3
+}
41a6c3
 static const command_rec cgid_cmds[] =
41a6c3
 {
41a6c3
     AP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
41a6c3
@@ -1033,6 +1053,10 @@
41a6c3
     AP_INIT_TAKE1("ScriptSock", set_script_socket, NULL, RSRC_CONF,
41a6c3
                   "the name of the socket to use for communication with "
41a6c3
                   "the cgi daemon."),
41a6c3
+    AP_INIT_TAKE1("CGIDScriptTimeout", set_script_timeout, NULL, RSRC_CONF | ACCESS_CONF,
41a6c3
+                  "The amount of time to wait between successful reads from "
41a6c3
+                  "the CGI script, in seconds."),
41a6c3
+                  
41a6c3
     {NULL}
41a6c3
 };
41a6c3
 
41a6c3
@@ -1356,12 +1380,16 @@
41a6c3
     apr_file_t *tempsock;
41a6c3
     struct cleanup_script_info *info;
41a6c3
     apr_status_t rv;
41a6c3
+    cgid_dirconf *dc;
41a6c3
 
41a6c3
     if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
41a6c3
         return DECLINED;
41a6c3
     }
41a6c3
 
41a6c3
     conf = ap_get_module_config(r->server->module_config, &cgid_module);
41a6c3
+    dc = ap_get_module_config(r->per_dir_config, &cgid_module);
41a6c3
+
41a6c3
+    
41a6c3
     is_included = !strcmp(r->protocol, "INCLUDED");
41a6c3
 
41a6c3
     if ((argv0 = strrchr(r->filename, '/')) != NULL) {
41a6c3
@@ -1441,6 +1469,12 @@
41a6c3
      */
41a6c3
 
41a6c3
     apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
41a6c3
+    if (dc->timeout > 0) { 
41a6c3
+        apr_file_pipe_timeout_set(tempsock, dc->timeout);
41a6c3
+    }
41a6c3
+    else { 
41a6c3
+        apr_file_pipe_timeout_set(tempsock, r->server->timeout);
41a6c3
+    }
41a6c3
     apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
41a6c3
 
41a6c3
     /* Transfer any put/post args, CERN style...
41a6c3
@@ -1517,6 +1551,10 @@
41a6c3
             if (rv != APR_SUCCESS) {
41a6c3
                 /* silly script stopped reading, soak up remaining message */
41a6c3
                 child_stopped_reading = 1;
41a6c3
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02651)
41a6c3
+                              "Error writing request body to script %s", 
41a6c3
+                              r->filename);
41a6c3
+
41a6c3
             }
41a6c3
         }
41a6c3
         apr_brigade_cleanup(bb);
41a6c3
@@ -1610,7 +1648,13 @@
41a6c3
             return HTTP_MOVED_TEMPORARILY;
41a6c3
         }
41a6c3
 
41a6c3
-        ap_pass_brigade(r->output_filters, bb);
41a6c3
+        rv = ap_pass_brigade(r->output_filters, bb);
41a6c3
+        if (rv != APR_SUCCESS) { 
41a6c3
+            /* APLOG_ERR because the core output filter message is at error,
41a6c3
+             * but doesn't know it's passing CGI output 
41a6c3
+             */
41a6c3
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02550) "Failed to flush CGI output to client");
41a6c3
+        }
41a6c3
     }
41a6c3
 
41a6c3
     if (nph) {
41a6c3
@@ -1741,6 +1785,8 @@
41a6c3
     request_rec *r = f->r;
41a6c3
     cgid_server_conf *conf = ap_get_module_config(r->server->module_config,
41a6c3
                                                   &cgid_module);
41a6c3
+    cgid_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgid_module);
41a6c3
+
41a6c3
     struct cleanup_script_info *info;
41a6c3
 
41a6c3
     add_ssi_vars(r);
41a6c3
@@ -1770,6 +1816,13 @@
41a6c3
      * get rid of the cleanup we registered when we created the socket.
41a6c3
      */
41a6c3
     apr_os_pipe_put_ex(&tempsock, &sd, 1, r->pool);
41a6c3
+    if (dc->timeout > 0) {
41a6c3
+        apr_file_pipe_timeout_set(tempsock, dc->timeout);
41a6c3
+    }
41a6c3
+    else {
41a6c3
+        apr_file_pipe_timeout_set(tempsock, r->server->timeout);
41a6c3
+    }
41a6c3
+
41a6c3
     apr_pool_cleanup_kill(r->pool, (void *)((long)sd), close_unix_socket);
41a6c3
 
41a6c3
     APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pipe_create(tempsock,
41a6c3
@@ -1875,7 +1928,7 @@
41a6c3
 
41a6c3
 AP_DECLARE_MODULE(cgid) = {
41a6c3
     STANDARD20_MODULE_STUFF,
41a6c3
-    NULL, /* dir config creater */
41a6c3
+    create_cgid_dirconf, /* dir config creater */
41a6c3
     NULL, /* dir merger --- default is to override */
41a6c3
     create_cgid_config, /* server config */
41a6c3
     merge_cgid_config, /* merge server config */