httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: httpd-2.0/server scoreboard.c
Date Fri, 25 Jan 2002 07:21:40 GMT
wrowe       02/01/24 23:21:40

  Modified:    .        CHANGES
               server/mpm/winnt mpm_winnt.c
               server   scoreboard.c
  Log:
    No.  I don't like this patch.  I like what it does [shared scoreboard
    for Windows, finally] but not how it's implemented.
  
    However it works, and is equally crufty to what already exists for
    win32 listeners and other exposed data within scoreboard.c.
  
    To do this right, we need to drop all the external references to data
    within the scoreboard, and add an accessor for remaining bits (such as
    Win32's need for direct access to the apr_shm_t.)  And within Win32,
    we need to stack all this _within_ the pre-mpm hook.  But those are
    missions in and of themselves.
  
  Revision  Changes    Path
  1.535     +2 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.534
  retrieving revision 1.535
  diff -u -r1.534 -r1.535
  --- CHANGES	25 Jan 2002 01:21:10 -0000	1.534
  +++ CHANGES	25 Jan 2002 07:21:39 -0000	1.535
  @@ -1,5 +1,7 @@
   Changes with Apache 2.0.31-dev
   
  +  *) The Win32 mpm_winnt now has a shared scoreboard.  [William Rowe]
  +
     *) Change ap_get_brigade prototype to use apr_off_t instead of apr_off_t*.
        [Justin Erenkrantz]
   
  
  
  
  1.209     +47 -2     httpd-2.0/server/mpm/winnt/mpm_winnt.c
  
  Index: mpm_winnt.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v
  retrieving revision 1.208
  retrieving revision 1.209
  diff -u -r1.208 -r1.209
  --- mpm_winnt.c	24 Jan 2002 06:14:35 -0000	1.208
  +++ mpm_winnt.c	25 Jan 2002 07:21:39 -0000	1.209
  @@ -99,6 +99,7 @@
    */
   #define HARD_SERVER_LIMIT 1
   
  +extern apr_shm_t *ap_scoreboard_shm;
   server_rec *ap_server_conf;
   typedef HANDLE thread;
   
  @@ -469,6 +470,7 @@
        * data. The sockets have been set to listening in the parent process.
        */
       pipe = GetStdHandle(STD_INPUT_HANDLE);
  +
       for (lr = ap_listeners; lr; lr = lr->next) {
           if (!ReadFile(pipe, &WSAProtocolInfo, sizeof(WSAPROTOCOL_INFO), 
                         &BytesRead, (LPOVERLAPPED) NULL)) {
  @@ -1224,6 +1226,8 @@
       HANDLE hShareError;
       HANDLE hShareErrorDup;
       HANDLE hCurrentProcess = GetCurrentProcess();
  +    HANDLE sb_os_shm;
  +    HANDLE dup_os_shm;
       SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
   
       LPWSAPROTOCOL_INFO  lpWSAProtocolInfo;
  @@ -1399,6 +1403,25 @@
        */
       Sleep(1000);
   
  +    if ((rv = apr_os_shm_get(&sb_os_shm, ap_scoreboard_shm)) != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf,
  +                     "Parent: Unable to retrieve the scoreboard handle");
  +        return -1;
  +    }
  +    if (!DuplicateHandle(hCurrentProcess, sb_os_shm, pi.hProcess, &dup_os_shm,
  +                         0, FALSE, DUPLICATE_SAME_ACCESS)) {
  +        ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,
  +                     "Parent: Unable to duplicate the scoreboard handle to the child");
  +        return -1;
  +    }
  +    if (!WriteFile(hPipeWrite, &dup_os_shm, sizeof(dup_os_shm),
  +                   &BytesWritten, (LPOVERLAPPED) NULL)
  +        || (BytesWritten != sizeof(dup_os_shm))) {
  +        ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,
  +                     "Parent: Unable to send the scoreboard handle to the child");
  +        return -1;
  +    }
  +
       /* Run the chain of open sockets. For each socket, duplicate it 
        * for the target process then send the WSAPROTOCOL_INFO 
        * (returned by dup socket) to the child.
  @@ -2078,13 +2101,35 @@
   
           if (one_process) {
               /* Set up the scoreboard. */
  -            ap_run_pre_mpm(pconf, SB_NOT_SHARED);
  +            ap_run_pre_mpm(pconf, SB_SHARED);
               if (ap_setup_listeners(ap_server_conf) < 1) {
                   return 1;
               }
           }
           else {
               /* Set up the scoreboard. */
  +            HANDLE pipe;
  +            HANDLE sb_os_shm;
  +            DWORD BytesRead;
  +            apr_status_t rv;
  +
  +            pipe = GetStdHandle(STD_INPUT_HANDLE);
  +            if (!ReadFile(pipe, &sb_os_shm, sizeof(sb_os_shm),
  +                          &BytesRead, (LPOVERLAPPED) NULL)
  +                || (BytesRead != sizeof(sb_os_shm))) {
  +                ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,
  +                             "child: Unable to access scoreboard handle from parent");
  +                ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
  +                exit(1);
  +            }
  +            if ((rv = apr_os_shm_put(&ap_scoreboard_shm, &sb_os_shm, s->process->pool))

  +                    != APR_SUCCESS) {
  +                ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf,
  +                             "child: Unable to access scoreboard handle from parent");
  +                ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
  +                exit(1);
  +            }
  +
               ap_run_pre_mpm(pconf, SB_SHARED_CHILD);
               ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
               get_listeners_from_parent(ap_server_conf);
  @@ -2101,7 +2146,7 @@
                        "Child %d: Child process is exiting", my_pid);        
           return 1;
       }
  -    else { 
  +    else /* Child */ { 
           /* Set up the scoreboard. */
           ap_run_pre_mpm(pconf, SB_SHARED);
   
  
  
  
  1.50      +17 -19    httpd-2.0/server/scoreboard.c
  
  Index: scoreboard.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/scoreboard.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- scoreboard.c	24 Jan 2002 07:47:10 -0000	1.49
  +++ scoreboard.c	25 Jan 2002 07:21:40 -0000	1.50
  @@ -85,8 +85,14 @@
   AP_DECLARE_DATA apr_time_t ap_restart_time = 0;
   
   #if APR_HAS_SHARED_MEMORY
  +
   #include "apr_shm.h"
  -static apr_shm_t *scoreboard_shm = NULL;
  +
  +#ifndef WIN32
  +static /* but must be exported to mpm_winnt */
  +#endif
  +        apr_shm_t *ap_scoreboard_shm = NULL;
  +
   #endif
   
   APR_HOOK_STRUCT(
  @@ -118,7 +124,7 @@
   #if APR_HAS_SHARED_MEMORY
       free(ap_scoreboard_image);
       ap_scoreboard_image = NULL;
  -    apr_shm_destroy(scoreboard_shm);
  +    apr_shm_destroy(ap_scoreboard_shm);
   #endif
       return APR_SUCCESS;
   }
  @@ -165,7 +171,7 @@
       char *fname = NULL;
   
   #ifndef WIN32
  -    rv = apr_shm_create(&scoreboard_shm, scoreboard_size, fname, p);
  +    rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, p);
       if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
                        "Fatal error: could not create scoreboard "
  @@ -179,7 +185,7 @@
           if (ap_scoreboard_fname) {
               fname = ap_server_root_relative(p, ap_scoreboard_fname);
           }
  -        rv = apr_shm_create(&scoreboard_shm, scoreboard_size, fname, p);
  +        rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, p);
           if (rv != APR_SUCCESS) {
               ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
                            "Fatal error: could not open(create) scoreboard");
  @@ -203,20 +209,12 @@
       if (!detached) {
           return APR_SUCCESS;
       }
  -    if (ap_scoreboard_fname) {
  -        fname = ap_server_root_relative(p, ap_scoreboard_fname);
  -    }
  -    rv = apr_shm_attach(&scoreboard_shm, fname, p);
  -    if (rv != APR_SUCCESS) {
  -        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
  -                     "Fatal error: could not open(create) scoreboard");
  -        return rv;
  -    }
  -    if (apr_shm_size_get(scoreboard_shm) < scoreboard_size) {
  +    if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
           ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
                        "Fatal error: shared scoreboard too small for child!");
  -        apr_shm_detach(scoreboard_shm);
  -        scoreboard_shm = NULL;
  +        apr_shm_detach(ap_scoreboard_shm);
  +        ap_scoreboard_shm = NULL;
  +        return APR_EINVAL;
       }
       /* everything will be cleared shortly */
   #endif
  @@ -259,7 +257,7 @@
           if (sb_type == SB_SHARED) {
               void *sb_shared;
               rv = open_scoreboard(p);
  -            if (rv || !(sb_shared = apr_shm_baseaddr_get(scoreboard_shm))) {
  +            if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
                   exit(APEXIT_INIT); /* XXX need to return an error from this function */
               }
               memset(sb_shared, 0, scoreboard_size);
  @@ -268,7 +266,7 @@
           else if (sb_type == SB_SHARED_CHILD) {
               void *sb_shared;
               rv = reopen_scoreboard(p, 1);
  -            if (rv || !(sb_shared = apr_shm_baseaddr_get(scoreboard_shm))) {
  +            if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
                   exit(APEXIT_INIT); /* XXX need to return an error from this function */
               }
               ap_init_scoreboard(sb_shared);
  @@ -291,10 +289,10 @@
       if (sb_type != SB_SHARED_CHILD) {
           ap_scoreboard_image->global->sb_type = sb_type;
           ap_scoreboard_image->global->running_generation = running_gen;
  -        ap_restart_time = apr_time_now();
           apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard,
                                     apr_pool_cleanup_null);
       }
  +    ap_restart_time = apr_time_now();
   }
   
   /* Routines called to deal with the scoreboard image
  
  
  

Mime
View raw message