You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@hyperreal.org on 1998/05/20 00:49:05 UTC

cvs commit: apache-1.3/src/modules/standard mod_include.c mod_log_agent.c mod_log_referer.c mod_mime_magic.c

brian       98/05/19 15:49:05

  Modified:    .        STATUS
               src      CHANGES
               src/modules/standard mod_include.c mod_log_agent.c
                        mod_log_referer.c mod_mime_magic.c
  Log:
  Two things: replaced the use of spawn_child with ap_spawn_child_err_buff
  in various modules (to be "safe" under Win32) and modified the agent and
  referer logging modules to use ap_open_piped_logs rather than try and do
  it on their own.
  
  I'm not sure that uncompress_child in mod_mime_magic is correct; could
  someone look at it?
  
  Also, Ralf, mod_rewrite.c needs similar treatment.  I was off to do it but
  it looked more complex than the other changes, and I'm sure once you see
  the changes made here you can understand which mod_rewrite changes to make.
  
  Revision  Changes    Path
  1.402     +9 -10     apache-1.3/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/STATUS,v
  retrieving revision 1.401
  retrieving revision 1.402
  diff -u -r1.401 -r1.402
  --- STATUS	1998/05/16 16:35:33	1.401
  +++ STATUS	1998/05/19 22:48:52	1.402
  @@ -17,14 +17,11 @@
   	for buffer overflow, someone should rewrite or verify
   	they're safe
   
  -	* SSI: mod_include has had "cmd" disabled pending rewrite to use
  -	new Win32 spawning.
  +    * CGI: chdir() needs to be reinstated for CGI.
   
  -	* CGI: chdir() needs to be reinstated for CGI.
  +    * Child process: eliminate spawn_child() and spawn_child_err() which
  +      are unsafe in mod_rewrite.c
   
  -	* Child process: eliminate spawn_child() and spawn_child_err() which
  -	are unsafe.
  -
   Documentation that needs writing:
   
       * Documentation for:
  @@ -218,8 +215,7 @@
   	really bad
   
       * chdir() for CGI scripts and mod_include #exec needs to be 
  -      re-implemented.  This requires either serializing chdir/spawn 
  -      or using a native Win32 CreateProcess(?) call.
  +      re-implemented now that CreateProcess is being used.
   
       * process/thread model
   	- need dynamic thread creation/destruction, similar to 
  @@ -247,8 +243,6 @@
       * we don't mmap on NT.  Use TransmitFile?
   
       * CGIs
  -        - hangs on multiple CGI execution?  PR#1607,1129
  -    	    Marc can't repeat...
   	- docs on how they work w/scripts
   	- use registry to find interpreter?
   	- WTF is the buffering coming from?
  @@ -369,4 +363,9 @@
           5) would be nice if the proxy used Via and Max-Forwards, even as HTTP/1.0
   
       * #ifdef __EMX__ --> #ifdef OS2.
  +
  +    * use of spawnvp in uncompress_child in mod_mime_magic - doesn't
  +      use the new child_info structure, is this still safe?  Needs to be 
  +      looked at.
  +
   
  
  
  
  1.853     +9 -2      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.852
  retrieving revision 1.853
  diff -u -r1.852 -r1.853
  --- CHANGES	1998/05/18 21:56:06	1.852
  +++ CHANGES	1998/05/19 22:48:57	1.853
  @@ -1,5 +1,12 @@
   Changes with Apache 1.3b7
   
  +  *) Mod_log_agent, mod_log_referer now use ap_open_piped_log for piped logs.
  +     [Brian Behlendorf]
  +
  +  *) Replace use of spawn_child with ap_spawn_child_err_buff, to make everything
  +     "safe" under Win32.  In: mod_include.c, mod_mime_magic.c
  +     [Brian Behlendorf]
  +
     *) Improve RFC1413 support. [Bob Beck <be...@bofh.ucs.ualberta.ca>]
   
     *) Fix support script `dbmmanage': It was unable to handle some sort
  @@ -11,8 +18,8 @@
   
     *) WIN32: CGIs could cause a hang (because of a deadlock in the standard C
        library), so CGI handling has been changed to use Win32 native handles
  -	 instead of C file descriptors.
  -	 [Ben Laurie and Bill Stoddard <wg...@us.ibm.com>] PR#1129, 1607
  +     instead of C file descriptors.
  +     [Ben Laurie and Bill Stoddard <wg...@us.ibm.com>] PR#1129, 1607
   
     *) The proxy cache would store an incorrect content-length in the cached
        file copy after a cache update. That resulted in repeated fetching
  
  
  
  1.89      +6 -13     apache-1.3/src/modules/standard/mod_include.c
  
  Index: mod_include.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_include.c,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- mod_include.c	1998/05/19 19:19:01	1.88
  +++ mod_include.c	1998/05/19 22:49:03	1.89
  @@ -786,7 +786,7 @@
   #endif
       ap_cleanup_for_exec();
       /* set shellcmd flag to pass arg to SHELL_PATH */
  -    child_pid = ap_call_exec(r, NULL, s, ap_create_environment(r->pool, env),
  +    child_pid = ap_call_exec(r, pinfo, s, ap_create_environment(r->pool, env),
   			     1);
   #ifdef WIN32
       return (child_pid);
  @@ -811,20 +811,18 @@
   static int include_cmd(char *s, request_rec *r)
   {
       include_cmd_arg arg;
  -    FILE *f;
  +    BUFF *script_in;
   
       arg.r = r;
       arg.s = s;
   
  -    if (!spawn_child(r->pool, include_cmd_child, &arg,
  -                     kill_after_timeout, NULL, &f)) {
  +    if (!ap_spawn_child_err_buff(r->pool, include_cmd_child, &arg,
  +                     kill_after_timeout, NULL, &script_in, NULL)) {
           return -1;
       }
   
  -    ap_send_fd(f, r);
  -    ap_pfclose(r->pool, f);        /* will wait for zombie when
  -                                 * r->pool is cleared
  -                                 */
  +    ap_send_fb(script_in, r);
  +    ap_bclose(script_in);
       return 0;
   }
   #endif
  @@ -841,10 +839,6 @@
               return 1;
           }
           if (!strcmp(tag, "cmd")) {
  -#ifdef WIN32
  -            ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
  -                        "cmd in SSI temporarily disabled");
  -#else
               parse_string(r, tag_val, parsed_string, sizeof(parsed_string), 1);
               if (include_cmd(parsed_string, r) == -1) {
                   ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
  @@ -856,7 +850,6 @@
               /* just in case some stooge changed directories */
   #ifndef WIN32
               ap_chdir_file(r->filename);
  -#endif
   #endif
           }
           else if (!strcmp(tag, "cgi")) {
  
  
  
  1.25      +5 -31     apache-1.3/src/modules/standard/mod_log_agent.c
  
  Index: mod_log_agent.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_log_agent.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- mod_log_agent.c	1998/05/19 19:19:02	1.24
  +++ mod_log_agent.c	1998/05/19 22:49:03	1.25
  @@ -58,6 +58,7 @@
   
   #include "httpd.h"
   #include "http_config.h"
  +#include "http_log.h"
   
   module agent_log_module;
   
  @@ -101,30 +102,6 @@
       {NULL}
   };
   
  -static int agent_log_child(void *cmd, child_info *pinfo)
  -{
  -    /* Child process code for 'AgentLog "|..."';
  -     * may want a common framework for this, since I expect it will
  -     * be common for other foo-loggers to want this sort of thing...
  -     */
  -    int child_pid = 1;
  -
  -    ap_cleanup_for_exec();
  -    signal(SIGHUP, SIG_IGN);
  -#if defined(WIN32)
  -    child_pid = spawnl(SHELL_PATH, SHELL_PATH, "/c", (char *) cmd, NULL);
  -    return (child_pid);
  -#elif defined(__EMX__)
  -    /* For OS/2 we need to use a '/' */
  -    execl(SHELL_PATH, SHELL_PATH, "/c", (char *) cmd, NULL);
  -#else
  -    execl(SHELL_PATH, SHELL_PATH, "-c", (char *) cmd, NULL);
  -#endif
  -    perror("exec");
  -    fprintf(stderr, "Exec of shell for logging failed!!!\n");
  -    return (child_pid);
  -}
  -
   static void open_agent_log(server_rec *s, pool *p)
   {
       agent_log_state *cls = ap_get_module_config(s->module_config,
  @@ -136,16 +113,13 @@
           return;                 /* virtual log shared w/main server */
   
       if (*cls->fname == '|') {
  -        FILE *dummy;
  +        piped_log *pl;
   
  -        if (!spawn_child(p, agent_log_child, (void *) (cls->fname + 1),
  -                         kill_after_timeout, &dummy, NULL)) {
  -            perror("spawn_child");
  -            fprintf(stderr, "Couldn't fork child for AgentLog process\n");
  +        pl = ap_open_piped_log(p, cls->fname + 1);
  +        if (pl == NULL) {
               exit(1);
           }
  -
  -        cls->agent_fd = fileno(dummy);
  +        cls->agent_fd = ap_piped_log_write_fd(pl);
       }
       else if (*cls->fname != '\0') {
           if ((cls->agent_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
  
  
  
  1.26      +5 -31     apache-1.3/src/modules/standard/mod_log_referer.c
  
  Index: mod_log_referer.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_log_referer.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- mod_log_referer.c	1998/05/19 19:19:02	1.25
  +++ mod_log_referer.c	1998/05/19 22:49:03	1.26
  @@ -58,6 +58,7 @@
   
   #include "httpd.h"
   #include "http_config.h"
  +#include "http_log.h"
   
   module referer_log_module;
   
  @@ -116,31 +117,6 @@
       {NULL}
   };
   
  -static int referer_log_child(void *cmd, child_info *pinfo)
  -{
  -    /* Child process code for 'RefererLog "|..."';
  -     * may want a common framework for this, since I expect it will
  -     * be common for other foo-loggers to want this sort of thing...
  -     */
  -    int child_pid = 1;
  -
  -    ap_cleanup_for_exec();
  -    signal(SIGHUP, SIG_IGN);
  -#if defined(WIN32)
  -    /* For OS/2 we need to use a '/' */
  -    child_pid = spawnl(SHELL_PATH, SHELL_PATH, "/c", (char *) cmd, NULL);
  -    return (child_pid);
  -#elif defined(__EMX__)
  -    /* For OS/2 we need to use a '/' */
  -    execl(SHELL_PATH, SHELL_PATH, "/c", (char *) cmd, NULL);
  -#else
  -    execl(SHELL_PATH, SHELL_PATH, "-c", (char *) cmd, NULL);
  -#endif
  -    perror("execl");
  -    fprintf(stderr, "Exec of shell for logging failed!!!\n");
  -    return (child_pid);
  -}
  -
   static void open_referer_log(server_rec *s, pool *p)
   {
       referer_log_state *cls = ap_get_module_config(s->module_config,
  @@ -152,16 +128,14 @@
           return;                 /* virtual log shared w/main server */
   
       if (*cls->fname == '|') {
  -        FILE *dummy;
  +        piped_log *pl;
   
  -        if (!spawn_child(p, referer_log_child, (void *) (cls->fname + 1),
  -                         kill_after_timeout, &dummy, NULL)) {
  -            perror("spawn_child");
  -            fprintf(stderr, "Couldn't fork child for RefererLog process\n");
  +	pl = ap_open_piped_log(p, cls->fname + 1);
  +	if (pl == NULL) {
               exit(1);
           }
   
  -        cls->referer_fd = fileno(dummy);
  +        cls->referer_fd = ap_piped_log_write_fd(pl);
       }
       else if (*cls->fname != '\0') {
           if ((cls->referer_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
  
  
  
  1.32      +6 -7      apache-1.3/src/modules/standard/mod_mime_magic.c
  
  Index: mod_mime_magic.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime_magic.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- mod_mime_magic.c	1998/05/19 19:19:02	1.31
  +++ mod_mime_magic.c	1998/05/19 22:49:03	1.32
  @@ -2171,8 +2171,7 @@
   		      unsigned char **newch, int n)
   {
       struct uncompress_parms parm;
  -    FILE *fin;
  -    FILE *fout;
  +    BUFF *bin, *bout;
       pool *sub_pool;
   
       parm.r = r;
  @@ -2184,22 +2183,22 @@
        */
       sub_pool = ap_make_sub_pool(r->pool);
   
  -    if (!spawn_child(sub_pool, uncompress_child, &parm, kill_always,
  -		     &fin, &fout)) {
  +    if (!ap_spawn_child_err_buff(sub_pool, uncompress_child, &parm, kill_always,
  +		     &bin, &bout, NULL)) {
   	ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
   		    MODNAME ": couldn't spawn uncompress process: %s", r->uri);
   	return -1;
       }
   
  -    if (write(fileno(fin), old, n) != n) {
  +    if (ap_bwrite(bin, old, n) != n) {
   	ap_destroy_pool(sub_pool);
   	ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
   		    MODNAME ": write failed.");
   	return -1;
       }
  -    ap_pfclose(sub_pool, fin);
  +    ap_bclose(bin);
       *newch = (unsigned char *) ap_palloc(r->pool, n);
  -    if ((n = read(fileno(fout), *newch, n)) <= 0) {
  +    if ((n = ap_bread(bout, *newch, n)) <= 0) {
   	ap_destroy_pool(sub_pool);
   	ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
   	    MODNAME ": read failed %s", r->filename);
  
  
  

Re: cvs commit: apache-1.3/src/modules/standard mod_include.c mod_log_agent.c mod_log_referer.c mod_mime_magic.c

Posted by Brian Behlendorf <br...@hyperreal.org>.
At 07:31 PM 5/20/98 +0100, you wrote:
>brian@hyperreal.org wrote:
>>   +        cls->agent_fd = ap_piped_log_write_fd(pl);
>
>Not so sure about this ... surely it can't be an fd if it works for
>Win32?

The variable names are misleading, they are really an int.  But you tell me
if this doesn't work on Win32.

Sigh.  Time to bite the win32 bullet i guess.

	Brian


--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
pure chewing satisfaction                                  brian@apache.org
                                                        brian@hyperreal.org

Re: cvs commit: apache-1.3/src/modules/standard mod_include.c mod_log_agent.c mod_log_referer.c mod_mime_magic.c

Posted by Ben Laurie <be...@algroup.co.uk>.
brian@hyperreal.org wrote:
>   +        cls->agent_fd = ap_piped_log_write_fd(pl);

Not so sure about this ... surely it can't be an fd if it works for
Win32?

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|  Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author    http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: cvs commit: apache-1.3/src/modules/standard mod_include.c mod_log_agent.c mod_log_referer.c mod_mime_magic.c

Posted by Ben Laurie <be...@algroup.co.uk>.
brian@hyperreal.org wrote:
>   +        cls->agent_fd = ap_piped_log_write_fd(pl);

Not so sure about this ... surely it can't be an fd if it works for
Win32?

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686|  Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author    http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache