]> granicus.if.org Git - apache/commitdiff
Allow modules to query the MPM about it's execution profile. This
authorRyan Bloom <rbb@apache.org>
Fri, 2 Mar 2001 22:46:33 +0000 (22:46 +0000)
committerRyan Bloom <rbb@apache.org>
Fri, 2 Mar 2001 22:46:33 +0000 (22:46 +0000)
query API can and should be extended in the future, but for now,
max_daemons, and threading or forking is a very good start.

Non-Unix MPM's do have the MPM query function, although there is no
garauntee that the information is perfect, please check.

Submitted by: Jon Travis <jtravis@covalent.net>

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88437 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
CHANGES
include/ap_mpm.h
modules/generators/mod_info.c
server/mpm/beos/beos.c
server/mpm/experimental/perchild/perchild.c
server/mpm/perchild/perchild.c
server/mpm/prefork/prefork.c
server/mpm/spmt_os2/spmt_os2.c
server/mpm/threaded/threaded.c
server/mpm/winnt/mpm_winnt.c
server/mpm_common.c
server/scoreboard.c

diff --git a/CHANGES b/CHANGES
index 9f92e20b50425f322813c73233bde41366708d19..11035efb51b4a7cfc93e51de3d712b7c742df933 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,10 @@
 Changes with Apache 2.0.14-dev
 
+  *) Allow modules to query the MPM about it's execution profile.  This
+     query API can and should be extended in the future, but for now,
+     max_daemons, and threading or forking is a very good start.
+     [Jon Travis <jtravis@covalent.net>]
+
   *) Modify mod_include to send blocks of data no larger than 9k.
      Without this, mod_include will wait until the whole file is parsed,
      or the first tag is found to send any data to the client.
index ab527ed400e04bf00b483366239ffa529fbce9da..26a4d44aa5cc92df28660b1185a1b5095580bf4d 100644 (file)
@@ -125,13 +125,6 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *serv
  */
 AP_DECLARE(int) ap_graceful_stop_signalled(void);
 
-/**
- * Get the maximum number of daemons processes for this version of Apache
- * @return The maximum number of daemon processes
- * @deffunc int ap_get_max_daemons(void)
- */
-AP_DECLARE(int) ap_get_max_daemons(void);
-
 /**
  * Spawn a process with privileges that another module has requested
  * @param r The request_rec of the current request
@@ -155,4 +148,17 @@ AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
     apr_pool_t *p);
 
 
+#define AP_MPMQ_MAX_DAEMONS 1    /* Max # of daemons     */
+#define AP_MPMQ_IS_THREADED 2    /* MPM can do threading */
+#define AP_MPMQ_IS_FORKED   3    /* MPM can do forking   */
+
+/**
+ * Query a property of the current MPM.  
+ * @param query_code One of APM_MPMQ_*
+ * @param result A location to place the result of the query
+ * @return APR_SUCCESS or APR_ENOTIMPL
+ * @deffunc int ap_mpm_query(int query_code, int *result)
+ */
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
+
 #endif
index eff8abfe93be297fd636660a87979f878daf6598..9624270c3161c3b7e0d007bc7a7555a55f6f036f 100644 (file)
@@ -97,6 +97,7 @@
 #include "apr_lib.h"
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
+#include "ap_mpm.h"
 
 typedef struct {
     const char *name;                 /* matching module name */
@@ -305,6 +306,8 @@ static int display_info(request_rec *r)
 
         }
         if (!r->args || !strcasecmp(r->args, "server")) {
+            int max_daemons, forked, threaded;
+
             ap_rprintf(r, "<a name=\"server\"><strong>Server Version:</strong> "
                         "<font size=+1><tt>%s</tt></a></font><br>\n",
                         ap_get_server_version());
@@ -321,6 +324,13 @@ static int display_info(request_rec *r)
                         "<tt>connection: %d &nbsp;&nbsp; "
                         "keep-alive: %d</tt><br>",
                         serv->timeout, serv->keep_alive_timeout);
+            ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons);
+            ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded);
+            ap_mpm_query(AP_MPMQ_IS_FORKED, &forked);
+            ap_rprintf(r, "<strong>MPM Information:</strong> "
+                      "<tt>Max Daemons: %d Threaded: %s Forked: %s</tt><br>\n",
+                       max_daemons, threaded ? "yes" : "no",
+                       forked ? "yes" : "no");
             ap_rprintf(r, "<strong>Server Root:</strong> "
                         "<tt>%s</tt><br>\n", ap_server_root);
             ap_rprintf(r, "<strong>Config File:</strong> "
index cda91239c027b6d5869703753f59b596d16e7dd1..3d3c7ac6c7c393a8dc2090e4fbd92d3b3d3fc295 100644 (file)
@@ -140,11 +140,6 @@ static int one_process = 0;
 int raise_sigstop_flags;
 #endif
 
-AP_DECLARE(int) ap_get_max_daemons(void)
-{
-    return ap_max_child_assigned;
-}
-
 /* a clean exit from a child with proper cleanup 
    static void clean_child_exit(int code) __attribute__ ((noreturn)); */
 static void clean_child_exit(int code)
@@ -633,6 +628,22 @@ static void server_main_loop(int remaining_threads_to_start)
     }
 }
 
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
+{
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
+}
+
 int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 {
     int remaining_threads_to_start, i,j;
index 7e3d6c31be441b4d13d5e3193c8de0db7cf1e8fd..05ff39a28c26f5157b4c407352be4ef14cba3e47 100644 (file)
@@ -215,9 +215,20 @@ static apr_lock_t *process_accept_mutex;
 static const char *lock_fname;
 static apr_lock_t *thread_accept_mutex;
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */
index 7e3d6c31be441b4d13d5e3193c8de0db7cf1e8fd..05ff39a28c26f5157b4c407352be4ef14cba3e47 100644 (file)
@@ -215,9 +215,20 @@ static apr_lock_t *process_accept_mutex;
 static const char *lock_fname;
 static apr_lock_t *thread_accept_mutex;
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */
index 6693f3710435b6a787f5ef9c814fc6d8e184bc4e..4e40eaa16efff59532ae714cab8fe04e8371be05 100644 (file)
@@ -302,9 +302,20 @@ static void accept_mutex_off(void)
 #define SAFE_ACCEPT(stmt) do {stmt;} while(0)
 #endif
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 0;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 #if defined(NEED_WAITPID)
index 8cb31273d034063d4dff41ec2f175db558daa2ed..ebae795d4d3fb54796dc252d5769a4b5232a24d2 100644 (file)
@@ -217,11 +217,6 @@ static void accept_mutex_off(void)
 #define SAFE_ACCEPT(stmt) do {stmt;} while(0)
 #endif
 
-AP_DECLARE(int) ap_get_max_daemons(void)
-{
-    return max_daemons_limit;
-}
-
 static int find_thread_by_tid(int tid)
 {
     int i;
@@ -883,6 +878,21 @@ static void perform_idle_server_maintenance(void)
     }
 }
 
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
+{
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 0;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
+} 
 
 /*****************************************************************
  * Executive routines.
index fe591b7707144c40afa8bdd6a80e743dd4859ddc..db5bda9e39d165ce58a2500524acaf0f32890368 100644 (file)
@@ -171,9 +171,20 @@ static const char *lock_fname;
 #define SAFE_ACCEPT(stmt) (stmt)
 #endif
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */ 
index 61797356d39f829364da4252fb0dbb599ece4a0c..704ef5663dd8f1efbb5b344fed45163517fb770c 100644 (file)
@@ -126,10 +126,6 @@ DWORD parent_pid;
  * code
  */
 ap_generation_t volatile ap_my_generation=0; /* Used by the scoreboard */
-AP_DECLARE(int) ap_get_max_daemons(void)
-{
-    return 1;
-}
 
 /* This is the helper code to resolve late bound entry points 
  * missing from one or more releases of the Win32 API...
@@ -1780,6 +1776,22 @@ apr_array_header_t *mpm_new_argv;
  * service after we preflight the config.
  */
 
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
+{
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = MAXIMUM_WAIT_OBJECTS;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 0;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
+} 
+
 static apr_status_t service_to_start_success;
 static int inst_argc;
 static const char * const *inst_argv;
index 6ac6868a9e26bffb8fec1183966a2dc56a34e8c4..cadc7f076c64470a3c3801161a1af110c70c613f 100644 (file)
@@ -94,8 +94,9 @@ void ap_reclaim_child_processes(int terminate)
     apr_status_t waitret;
     int tries;
     int not_dead_yet;
-    int max_daemons = ap_get_max_daemons();
+    int max_daemons;
 
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons);
     MPM_SYNC_CHILD_TABLE();
 
     for (tries = terminate ? 4 : 1; tries <= 9; ++tries) {
index 88ebe0fb9ed06f00e5f95f42067d0e96fc4e28a4..80277debaf81cb4189dfaea3be06e60588caaeb4 100644 (file)
@@ -253,7 +253,9 @@ AP_DECLARE(void) ap_increment_counts(int child_num, int thread_num, request_rec
 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
 {
     int i;
-    int max_daemons_limit = ap_get_max_daemons();
+    int max_daemons_limit;
+
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
 
     for (i = 0; i < max_daemons_limit; ++i)
        if (ap_scoreboard_image->parent[i].pid == pid->pid)