httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: httpd-2.0/modules/generators mod_cgid.c
Date Mon, 28 Jan 2002 18:30:07 GMT
trawick     02/01/28 10:30:07

  Modified:    .        CHANGES
               modules/generators mod_cgid.c
  Log:
  Fix some unix socket descriptor leaks in the handler side of
  mod_cgid (the part that runs in the server process).  Whack a
  silly "close(-1)" in the handler too.
  
  Revision  Changes    Path
  1.542     +4 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.541
  retrieving revision 1.542
  diff -u -r1.541 -r1.542
  --- CHANGES	28 Jan 2002 00:41:30 -0000	1.541
  +++ CHANGES	28 Jan 2002 18:30:06 -0000	1.542
  @@ -1,5 +1,9 @@
   Changes with Apache 2.0.31-dev
   
  +  *) Fix some unix socket descriptor leaks in the handler side of
  +     mod_cgid (the part that runs in the server process).  Whack a
  +     silly "close(-1)" in the handler too.  [Jeff Trawick]
  +
     *) Change the pre_mpm hook to return a value, so that scoreboard
        init errors percolate up to code that knows how to exit 
        cleanly.  This required bump to the MMN.  [Jeff Trawick]
  
  
  
  1.111     +40 -10    httpd-2.0/modules/generators/mod_cgid.c
  
  Index: mod_cgid.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/generators/mod_cgid.c,v
  retrieving revision 1.110
  retrieving revision 1.111
  diff -u -r1.110 -r1.111
  --- mod_cgid.c	8 Jan 2002 06:26:09 -0000	1.110
  +++ mod_cgid.c	28 Jan 2002 18:30:07 -0000	1.111
  @@ -843,7 +843,12 @@
       return ret; 
   } 
   
  -
  +static apr_status_t close_unix_socket(void *thefd)
  +{
  +    int fd = (int)thefd;
  +    
  +    return close(fd);
  +}
   
   /**************************************************************** 
    * 
  @@ -926,7 +931,10 @@
       if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
               return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, errno, 
                                      "unable to create socket to cgi daemon");
  -    } 
  +    }
  +    apr_pool_cleanup_register(r->pool, (void *)sd, close_unix_socket,
  +                              apr_pool_cleanup_null);
  +    
       memset(&unix_addr, 0, sizeof(unix_addr));
       unix_addr.sun_family = AF_UNIX;
       strcpy(unix_addr.sun_path, conf->sockname);
  @@ -938,8 +946,10 @@
   
       send_req(sd, r, argv0, env, CGI_REQ); 
   
  -    /* We are putting the tempsock variable into a file so that we can use
  -     * a pipe bucket to send the data to the client.
  +    /* We are putting the socket discriptor into an apr_file_t so that we can
  +     * use a pipe bucket to send the data to the client.
  +     * Note that this does not register a cleanup for the socket.  We did
  +     * that explicitly right after we created the socket.
        */
       apr_os_file_put(&tempsock, &sd, 0, r->pool);
   
  @@ -1033,7 +1043,13 @@
               return HTTP_MOVED_TEMPORARILY; 
           } 
   
  -        if (!r->header_only) { 
  +        if (!r->header_only) {
  +            /* Passing our socket down the filter chain in a pipe bucket
  +             * gives up the responsibility of closing the socket, so
  +             * get rid of the cleanup.
  +             */
  +            apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
  +
               bb = apr_brigade_create(r->pool);
               b = apr_bucket_pipe_create(tempsock);
               APR_BRIGADE_INSERT_TAIL(bb, b);
  @@ -1044,6 +1060,12 @@
       } 
   
       if (nph) {
  +        /* Passing our socket down the filter chain in a pipe bucket
  +         * gives up the responsibility of closing the socket, so
  +         * get rid of the cleanup.
  +         */
  +        apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
  +
           bb = apr_brigade_create(r->pool);
           b = apr_bucket_pipe_create(tempsock);
           APR_BRIGADE_INSERT_TAIL(bb, b);
  @@ -1052,8 +1074,6 @@
           ap_pass_brigade(r->output_filters, bb);
       } 
   
  -    apr_file_close(tempsock);
  -
       return OK; /* NOT r->status, even if it has changed. */ 
   } 
   
  @@ -1188,7 +1208,9 @@
               return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, 0, 
                                      "unable to create socket to cgi daemon");
       }
  -
  +    apr_pool_cleanup_register(r->pool, (void *)sd, close_unix_socket,
  +                              apr_pool_cleanup_null);
  +    
       memset(&unix_addr, 0, sizeof(unix_addr));
       unix_addr.sun_family = AF_UNIX;
       strcpy(unix_addr.sun_path, conf->sockname);
  @@ -1205,8 +1227,10 @@
   
       send_req(sd, r, command, env, SSI_REQ); 
   
  -    /* We are putting the tempsock variable into a file so that we can use
  -     * a pipe bucket to send the data to the client.
  +    /* We are putting the socket discriptor into an apr_file_t so that we can
  +     * use a pipe bucket to send the data to the client.
  +     * Note that this does not register a cleanup for the socket.  We did
  +     * that explicitly right after we created the socket.
        */
       apr_os_file_put(&tempsock, &sd, 0, r->pool);
   
  @@ -1246,6 +1270,12 @@
       } 
   
       if (!r->header_only) { 
  +        /* Passing our socket down the filter chain in a pipe bucket
  +         * gives up the responsibility of closing the socket, so
  +         * get rid of the cleanup.
  +         */
  +        apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
  +
           bcgi = apr_brigade_create(r->pool);
           b    = apr_bucket_pipe_create(tempsock);
           APR_BRIGADE_INSERT_TAIL(bcgi, b);
  
  
  

Mime
View raw message