httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Stoddard" <b...@wstoddard.com>
Subject Re: cvs commit: httpd-2.0/server/mpm/worker worker.c
Date Mon, 04 Feb 2002 18:01:49 GMT
Actually, this patch is not the only (or even main) culprit.  The switch to use the shared
scoreboard is fatally broken. I am in the process of keeping the spirit of Ryan's patch to
only use pre_mpm in the parent and revert back to non shared scoreboard for Windows.

Bill

----- Original Message -----
From: "Bill Stoddard" <bill@wstoddard.com>
To: <dev@httpd.apache.org>
Sent: Monday, February 04, 2002 11:57 AM
Subject: Fw: cvs commit: httpd-2.0/server/mpm/worker worker.c


> This patch seems to have broken restarts and child recovery on Windows.
Investigating...
>
> Bill
>
>
> > rbb         02/01/30 14:35:57
> >
> >   Modified:    include  scoreboard.h
> >                server   scoreboard.c
> >                server/mpm/prefork prefork.c
> >                server/mpm/winnt mpm_winnt.c
> >                server/mpm/worker worker.c
> >   Log:
> >   Change the Windows MPM to only use the pre_mpm phase in the parent process.
> >   The child processes use the child_init phase to reattach to the shared
> >   memory.  This makes Windows work like Unix, which should make it easier
> >   for module authors to write portable modules.
> >
> >   Revision  Changes    Path
> >   1.39      +3 -3      httpd-2.0/include/scoreboard.h
> >
> >   Index: scoreboard.h
> >   ===================================================================
> >   RCS file: /home/cvs/httpd-2.0/include/scoreboard.h,v
> >   retrieving revision 1.38
> >   retrieving revision 1.39
> >   diff -u -r1.38 -r1.39
> >   --- scoreboard.h 28 Jan 2002 00:41:31 -0000 1.38
> >   +++ scoreboard.h 30 Jan 2002 22:35:56 -0000 1.39
> >   @@ -73,6 +73,7 @@
> >    #include "apr_hooks.h"
> >    #include "apr_thread_proc.h"
> >    #include "apr_portable.h"
> >   +#include "apr_shm.h"
> >
> >    /* Scoreboard info on a process is, for now, kept very brief ---
> >     * just status value and pid (the latter so that the caretaker process
> >   @@ -113,8 +114,7 @@
> >     */
> >    typedef enum {
> >        SB_NOT_SHARED = 1,
> >   -    SB_SHARED = 2,      /* PARENT */
> >   -    SB_SHARED_CHILD = 3
> >   +    SB_SHARED = 2
> >    } ap_scoreboard_e;
> >
> >    #define SB_WORKING  0  /* The server is busy and the child is useful. */
> >   @@ -185,7 +185,7 @@
> >    AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
> >
> >    int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
> >   -apr_status_t reopen_scoreboard(apr_pool_t *p, int detached);
> >   +apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
> >    void ap_init_scoreboard(void *shared_score);
> >    int ap_calc_scoreboard_size(void);
> >    apr_status_t ap_cleanup_scoreboard(void *d);
> >
> >
> >
> >   1.53      +9 -17     httpd-2.0/server/scoreboard.c
> >
> >   Index: scoreboard.c
> >   ===================================================================
> >   RCS file: /home/cvs/httpd-2.0/server/scoreboard.c,v
> >   retrieving revision 1.52
> >   retrieving revision 1.53
> >   diff -u -r1.52 -r1.53
> >   --- scoreboard.c 28 Jan 2002 00:41:31 -0000 1.52
> >   +++ scoreboard.c 30 Jan 2002 22:35:56 -0000 1.53
> >   @@ -143,7 +143,8 @@
> >    {
> >        char *more_storage;
> >        int i;
> >   -
> >   +
> >   + ap_calc_scoreboard_size();
> >        ap_scoreboard_image =
> >            calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
> >        more_storage = shared_score;
> >   @@ -200,7 +201,7 @@
> >    /* If detach is non-zero, this is a seperate child process,
> >     * if zero, it is a forked child.
> >     */
> >   -apr_status_t reopen_scoreboard(apr_pool_t *p, int detached)
> >   +apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
> >    {
> >    #if APR_HAS_SHARED_MEMORY
> >        if (!detached) {
> >   @@ -215,6 +216,9 @@
> >        }
> >        /* everything will be cleared shortly */
> >    #endif
> >   +    if (*shm) {
> >   +        *shm = ap_scoreboard_shm;
> >   +    }
> >        return APR_SUCCESS;
> >    }
> >
> >   @@ -260,14 +264,6 @@
> >                memset(sb_shared, 0, scoreboard_size);
> >                ap_init_scoreboard(sb_shared);
> >            }
> >   -        else if (sb_type == SB_SHARED_CHILD) {
> >   -            void *sb_shared;
> >   -            rv = reopen_scoreboard(p, 1);
> >   -            if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm)))
{
> >   -                return HTTP_INTERNAL_SERVER_ERROR;
> >   -            }
> >   -            ap_init_scoreboard(sb_shared);
> >   -        }
> >            else
> >    #endif
> >            {
> >   @@ -282,14 +278,10 @@
> >                ap_init_scoreboard(sb_mem);
> >            }
> >        }
> >   -    /* can't just memset() */
> >   -    if (sb_type != SB_SHARED_CHILD) {
> >   -        ap_scoreboard_image->global->sb_type = sb_type;
> >   -        ap_scoreboard_image->global->running_generation = running_gen;
> >   -        apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard,
> >   -                                  apr_pool_cleanup_null);
> >   -    }
> >   +    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);
> >        return OK;
> >    }
> >
> >
> >
> >
> >   1.236     +1 -1      httpd-2.0/server/mpm/prefork/prefork.c
> >
> >   Index: prefork.c
> >   ===================================================================
> >   RCS file: /home/cvs/httpd-2.0/server/mpm/prefork/prefork.c,v
> >   retrieving revision 1.235
> >   retrieving revision 1.236
> >   diff -u -r1.235 -r1.236
> >   --- prefork.c 29 Jan 2002 22:31:25 -0000 1.235
> >   +++ prefork.c 30 Jan 2002 22:35:56 -0000 1.236
> >   @@ -594,7 +594,7 @@
> >        apr_pool_tag(ptrans, "transaction");
> >
> >        /* needs to be done before we switch UIDs so we have permissions */
> >   -    reopen_scoreboard(pchild, 0);
> >   +    ap_reopen_scoreboard(pchild, NULL, 0);
> >        SAFE_ACCEPT(accept_mutex_child_init(pchild));
> >
> >        if (unixd_setup_child()) {
> >
> >
> >
> >   1.214     +29 -8     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.213
> >   retrieving revision 1.214
> >   diff -u -r1.213 -r1.214
> >   --- mpm_winnt.c 29 Jan 2002 19:02:04 -0000 1.213
> >   +++ mpm_winnt.c 30 Jan 2002 22:35:57 -0000 1.214
> >   @@ -67,6 +67,7 @@
> >    #include "apr_getopt.h"
> >    #include "apr_strings.h"
> >    #include "apr_lib.h"
> >   +#include "apr_shm.h"
> >    #include "ap_mpm.h"
> >    #include "ap_config.h"
> >    #include "ap_listen.h"
> >   @@ -281,6 +282,23 @@
> >        }
> >    }
> >
> >   +static void winnt_child_init(apr_pool_t *pchild, struct server_rec *ap_server_conf)
> >   +{
> >   +    void *sb_shared;
> >   +    int rv;
> >   +
> >   +    rv = ap_reopen_scoreboard(pchild, &ap_scoreboard_shm, 1);
> >   +    if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
> >   + ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, "Looks like we're gonna die %d
%x",
> rv, ap_scoreboard_shm);
> >   +        exit(APEXIT_INIT); /* XXX need to return an error from this function
*/
> >   +    }
> >   +    ap_init_scoreboard(sb_shared);
> >   +
> >   +    ap_scoreboard_image->parent[0].pid = parent_pid;
> >   +    ap_scoreboard_image->parent[0].quiescing = 0;
> >   +}
> >   +
> >   +
> >    /*
> >     * The Win32 call WaitForMultipleObjects will only allow you to wait for
> >     * a maximum of MAXIMUM_WAIT_OBJECTS (current 64).  Since the threading
> >   @@ -994,7 +1012,14 @@
> >            exit_event = OpenEvent(EVENT_ALL_ACCESS, FALSE, exit_event_name);
> >            ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
> >                         "Child %d: exit_event_name = %s", my_pid, exit_event_name);
> >   +        /* Set up the scoreboard. */
> >   +        ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
> >   +    ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
> >   +                     "getting listeners child_main", my_pid);
> >   +        get_listeners_from_parent(ap_server_conf);
> >        }
> >   +    ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
> >   +                     "in child_main", my_pid);
> >
> >        /* Initialize the child_events */
> >        max_requests_per_child_event = CreateEvent(NULL, TRUE, FALSE, NULL);
> >   @@ -2117,7 +2142,6 @@
> >                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)
> >   @@ -2135,18 +2159,14 @@
> >                    exit(1);
> >                }
> >
> >   -            if (ap_run_pre_mpm(pconf, SB_SHARED_CHILD) != OK) {
> >   -                exit(1);
> >   -            }
> >   +
> >                ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
> >   -            get_listeners_from_parent(ap_server_conf);
> >            }
> >   -        ap_scoreboard_image->parent[0].pid = parent_pid;
> >   -        ap_scoreboard_image->parent[0].quiescing = 0;
> >   -
> >   +
> >            if (!set_listeners_noninheritable(pconf)) {
> >                return 1;
> >            }
> >   +
> >            child_main();
> >
> >            ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
> >   @@ -2195,6 +2215,7 @@
> >    {
> >        ap_hook_pre_config(winnt_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
> >        ap_hook_post_config(winnt_post_config, NULL, NULL, 0);
> >   +    ap_hook_child_init(winnt_child_init, NULL, NULL, APR_HOOK_MIDDLE);
> >    }
> >
> >    /*
> >
> >
> >
> >   1.69      +1 -1      httpd-2.0/server/mpm/worker/worker.c
> >
> >   Index: worker.c
> >   ===================================================================
> >   RCS file: /home/cvs/httpd-2.0/server/mpm/worker/worker.c,v
> >   retrieving revision 1.68
> >   retrieving revision 1.69
> >   diff -u -r1.68 -r1.69
> >   --- worker.c 30 Jan 2002 11:56:26 -0000 1.68
> >   +++ worker.c 30 Jan 2002 22:35:57 -0000 1.69
> >   @@ -874,7 +874,7 @@
> >        apr_pool_create(&pchild, pconf);
> >
> >        /*stuff to do before we switch id's, so we have permissions.*/
> >   -    reopen_scoreboard(pchild, 0);
> >   +    ap_reopen_scoreboard(pchild, NULL, 0);
> >
> >        rv = SAFE_ACCEPT(apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname,
> >                                                   pchild));
> >
> >
> >
> >
>


Mime
View raw message