You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brad Nicholes <BN...@novell.com> on 2002/06/05 21:49:24 UTC

Re: [PATCH] - Add a "detached" parameter to ap_cgi_build_command() for CGI...

   I took the build parameters and put them into a cgi_exec_info_t
structure that is passed to the build_command function.  This cleans up
the parameter list.

Brad
 
--- \tempapache\httpd-2.0\modules\generators\mod_cgi.h	Wed Apr 17
08:18:42 2002
+++ mod_cgi.h	Wed Jun 05 13:18:52 2002
@@ -59,7 +59,23 @@
 #ifndef _MOD_CGI_H
 #define _MOD_CGI_H 1
 
+#include "../filters/mod_include.h"
 
+typedef enum {RUN_AS_SSI, RUN_AS_CGI} prog_types;
+
+typedef struct {
+    apr_int32_t          in_pipe;
+    apr_int32_t          out_pipe;
+    apr_int32_t          err_pipe;
+    int                  process_cgi;
+    apr_cmdtype_e        cmd_type;
+    apr_int32_t          detached;
+    prog_types           prog_type;
+    apr_bucket_brigade **bb;
+    include_ctx_t       *ctx;
+    ap_filter_t         *next;
+} cgi_exec_info_t;
+
 /**
  * Registerable optional function to override CGI behavior;
  * Reprocess the command and arguments to execute the given CGI
script.
@@ -71,6 +87,7 @@
  *                    as a CGI invocation, otherwise false
  * @param type Set to APR_SHELLCMD or APR_PROGRAM on entry, may be
  *             changed to invoke the program with alternate
semantics.
+ * @param detach Should the child start in detached state?  Default is
no. 
  * @remark This callback may be registered by the os-specific module 
  * to correct the command and arguments for apr_proc_create
invocation
  * on a given os.  mod_cgi will call the function if registered.
@@ -78,6 +95,6 @@
 APR_DECLARE_OPTIONAL_FN(apr_status_t, ap_cgi_build_command, 
                         (const char **cmd, const char ***argv,
                          request_rec *r, apr_pool_t *p, 
-                         int process_cgi, apr_cmdtype_e *type));
+                         cgi_exec_info_t *e_info));
 
 #endif /* _MOD_CGI_H */

--- \tempapache\httpd-2.0\modules\generators\mod_cgi.c	Thu May 30
08:49:40 2002
+++ mod_cgi.c	Wed Jun 05 13:15:11 2002
@@ -93,7 +93,6 @@
 #include "util_script.h"
 #include "ap_mpm.h"
 #include "mod_core.h"
-#include "../filters/mod_include.h"
 #include "mod_cgi.h"
 
 module AP_MODULE_DECLARE_DATA cgi_module;
@@ -103,19 +102,6 @@
 static APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgi_pfn_ps;
 static APR_OPTIONAL_FN_TYPE(ap_cgi_build_command) *cgi_build_command;
 
-typedef enum {RUN_AS_SSI, RUN_AS_CGI} prog_types;
-
-typedef struct {
-    apr_int32_t          in_pipe;
-    apr_int32_t          out_pipe;
-    apr_int32_t          err_pipe;
-    apr_cmdtype_e        cmd_type;
-    prog_types           prog_type;
-    apr_bucket_brigade **bb;
-    include_ctx_t       *ctx;
-    ap_filter_t         *next;
-} exec_info;
-
 /* Read and discard the data in the brigade produced by a CGI script
*/
 static void discard_script_output(apr_bucket_brigade *bb);
 
@@ -401,7 +387,7 @@
                                   const char * const argv[],
                                   request_rec *r,
                                   apr_pool_t *p,
-                                  exec_info *e_info)
+                                  cgi_exec_info_t *e_info)
 {
     const char * const *env;
     apr_procattr_t *procattr;
@@ -471,7 +457,10 @@
                                       conf->limit_nproc)) !=
APR_SUCCESS) ||
 #endif
         ((rc = apr_procattr_cmdtype_set(procattr,
-                                        e_info->cmd_type)) !=
APR_SUCCESS)) {
+                                        e_info->cmd_type)) !=
APR_SUCCESS) ||
+
+        ((rc = apr_procattr_detach_set(procattr,
+                                        e_info->detached)) !=
APR_SUCCESS)) {
         /* Something bad happened, tell the world. */
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                       "couldn't set child process attributes: %s",
r->filename);
@@ -530,13 +519,13 @@
 
 static apr_status_t default_build_command(const char **cmd, const char
***argv,
                                           request_rec *r, apr_pool_t
*p,
-                                          int process_cgi,
apr_cmdtype_e * type)
+                                          cgi_exec_info_t *e_info)
 {
     int numwords, x, idx;
     char *w;
     const char *args = NULL;
 
-    if (process_cgi) {
+    if (e_info->process_cgi) {
         /* Allow suexec's "/" check to succeed */
         const char *argv0 = strrchr(r->filename, '/');
         if (argv0 != NULL)
@@ -613,7 +602,7 @@
     apr_pool_t *p;
     cgi_server_conf *conf;
     apr_status_t rv;
-    exec_info e_info;
+    cgi_exec_info_t e_info;
 
     if(strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler,
"cgi-script"))
         return DECLINED;
@@ -664,18 +653,19 @@
 */
     ap_add_common_vars(r);
 
-    e_info.cmd_type  = APR_PROGRAM;
-    e_info.in_pipe   = APR_CHILD_BLOCK;
-    e_info.out_pipe  = APR_CHILD_BLOCK;
-    e_info.err_pipe  = APR_CHILD_BLOCK;
-    e_info.prog_type = RUN_AS_CGI;
-    e_info.bb        = NULL;
-    e_info.ctx       = NULL;
-    e_info.next      = NULL;
+    e_info.process_cgi = 1;
+    e_info.cmd_type    = APR_PROGRAM;
+    e_info.detached    = 0;
+    e_info.in_pipe     = APR_CHILD_BLOCK;
+    e_info.out_pipe    = APR_CHILD_BLOCK;
+    e_info.err_pipe    = APR_CHILD_BLOCK;
+    e_info.prog_type   = RUN_AS_CGI;
+    e_info.bb          = NULL;
+    e_info.ctx         = NULL;
+    e_info.next        = NULL;
 
     /* build the command line */
-    if ((rv = cgi_build_command(&command, &argv, r, p, 1,
&e_info.cmd_type)) 
-            != APR_SUCCESS) {
+    if ((rv = cgi_build_command(&command, &argv, r, p, &e_info)) !=
APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                       "don't know how to spawn child process: %s", 
                       r->filename);
@@ -932,24 +922,25 @@
 static int include_cmd(include_ctx_t *ctx, apr_bucket_brigade **bb,
                        const char *command, request_rec *r,
ap_filter_t *f)
 {
-    exec_info      e_info;
+    cgi_exec_info_t  e_info;
     const char   **argv;
     apr_file_t    *script_out = NULL, *script_in = NULL, *script_err =
NULL;
     apr_bucket_brigade *bcgi;
     apr_bucket *b;
     apr_status_t rv;
 
-    e_info.cmd_type  = APR_SHELLCMD;
-    e_info.in_pipe   = APR_NO_PIPE;
-    e_info.out_pipe  = APR_FULL_BLOCK;
-    e_info.err_pipe  = APR_NO_PIPE;
-    e_info.prog_type = RUN_AS_SSI;
-    e_info.bb        = bb;
-    e_info.ctx       = ctx;
-    e_info.next      = f->next;
+    e_info.process_cgi = 0;
+    e_info.cmd_type    = APR_SHELLCMD;
+    e_info.detached    = 0;
+    e_info.in_pipe     = APR_NO_PIPE;
+    e_info.out_pipe    = APR_FULL_BLOCK;
+    e_info.err_pipe    = APR_NO_PIPE;
+    e_info.prog_type   = RUN_AS_SSI;
+    e_info.bb          = bb;
+    e_info.ctx         = ctx;
+    e_info.next        = f->next;
 
-    if ((rv = cgi_build_command(&command, &argv, r, r->pool, 0,
-                                &e_info.cmd_type)) != APR_SUCCESS) {
+    if ((rv = cgi_build_command(&command, &argv, r, r->pool, &e_info))
!= APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                       "don't know how to spawn cmd child process: %s",

                       r->filename);


Brad Nicholes
Senior Software Engineer
Novell, Inc., a leading provider of Net business solutions
http://www.novell.com 

>>> wrowe@rowe-clan.net Wednesday, June 05, 2002 11:41:42 AM >>>
Although win32 shares the same issue...  still...  ick...

Suppose it is time that we stuff the exec_info (renamed ap_exec_info_t)
in 
place
of the apr_cmdtype_e, and allow the ap_cgi_build_command() integrator
to modify
any of the flags/fields in that structure?

Bill

At 12:10 PM 6/5/2002, Brad Nicholes wrote:
>     This patch adds the "detached" parameter to the
>ap_cgi_build_command() optional function.  This allows the OS to
specify
>whether the CGI binary should be spawned detached or not. 
Specifically
>for NetWare this allows us to determine wheither a CGI NLM should be
>executed in the same address space as Apache or a new address space.
>
>Brad
>


Re: [PATCH] - Add a "detached" parameter to ap_cgi_build_command() for CGI...

Posted by Cliff Woolley <jw...@virginia.edu>.
On Wed, 5 Jun 2002, William A. Rowe, Jr. wrote:

> Since we've already bit the mmn bump hurdle, this is a no-brainer for
> inclusion -before- we roll 2.0.37

+1 to getting this settled before 2.0.37 (though I haven't looked at the
patch in detail yet).

--Cliff


Re: [PATCH] - Add a "detached" parameter to ap_cgi_build_command() for CGI...

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 02:49 PM 6/5/2002, you wrote:
>    I took the build parameters and put them into a cgi_exec_info_t
>structure that is passed to the build_command function.  This cleans up
>the parameter list.

+1 to this patch.  Feel free to apply [although you might wait for another
plus one... I'm afraid not many folks are watching this corner of the server.]

I was going to spout off about ap_ decorating the type, until I noted that
this header simply won't be included by the average module.  Chance of
type collision is pretty minor.

I'm happy to fix arch/win32/mod_win32, or if you would like to attack it
at the same time [I'm guessing you have already investigated or considered
borrowing bits of that code] that would be terrific.

Since we've already bit the mmn bump hurdle, this is a no-brainer for
inclusion -before- we roll 2.0.37

Bill