]> granicus.if.org Git - apache/commitdiff
Implement new ScoreBoardFile directive logic. This affects how we
authorAaron Bannert <aaron@apache.org>
Fri, 15 Feb 2002 20:48:19 +0000 (20:48 +0000)
committerAaron Bannert <aaron@apache.org>
Fri, 15 Feb 2002 20:48:19 +0000 (20:48 +0000)
create the scoreboard's shared memory segment. We now have the best of
both worlds:

if config specifies ScoreBoardFile
  create name-based shared memory, errors are fatal
else /* we get to choose */
  create anonymous shared memory
  if ENOTIMPL
    create name-based shared memory from DEFAULT_SCOREBOARD
  else
    errors are fatal

This gives us the flexibility to have anonymous shared memory (on platforms
that support it) as well as name-based shared memory when third-party
programs want access to our scoreboard.

The ap_scoreboard_fname static variable is now owned by the scoreboard.c
file, and no longer by the MPMs. The MPMs MUST NOT set ap_scoreboard_fname
to a default, since that will override the default creation logic and
only allow name-based segments.

Submitted by: Aaron Bannert
Reviewed by: Justin Erenkrantz

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

14 files changed:
include/scoreboard.h
server/mpm/beos/beos.c
server/mpm/beos/mpm_default.h
server/mpm/experimental/perchild/mpm_default.h
server/mpm/experimental/perchild/perchild.c
server/mpm/netware/mpm_default.h
server/mpm/netware/mpm_netware.c
server/mpm/perchild/mpm_default.h
server/mpm/perchild/perchild.c
server/mpm/prefork/mpm_default.h
server/mpm/prefork/prefork.c
server/mpm/worker/mpm_default.h
server/mpm/worker/worker.c
server/scoreboard.c

index a58dd72e7ad533cde0134f0ebde326a8acdd0441..6001caf078f775e8c6e256134e4732dd865ddf8b 100644 (file)
@@ -58,6 +58,7 @@
 
 #ifndef APACHE_SCOREBOARD_H
 #define APACHE_SCOREBOARD_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -75,6 +76,11 @@ extern "C" {
 #include "apr_portable.h"
 #include "apr_shm.h"
 
+/* Scoreboard file, if there is one */
+#ifndef DEFAULT_SCOREBOARD
+#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
+#endif
+
 /* Scoreboard info on a process is, for now, kept very brief --- 
  * just status value and pid (the latter so that the caretaker process
  * can properly update the scoreboard when a process dies).  We may want
index d9fc492ff538868941761bc6b54f8c24b7e3a34e..c58a5786f4c9b2b39edc4c15aff9515988685df2 100644 (file)
@@ -762,8 +762,6 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     pconf = _pconf;
     ap_server_conf = s;
 
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
-
     /* Increase the available pool of fd's.  This code from
      * Joe Kloss <joek@be.com>
      */
@@ -1032,7 +1030,6 @@ static int beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem
     ap_thread_limit = HARD_THREAD_LIMIT;
     ap_pid_fname = DEFAULT_PIDLOG;
     ap_max_requests_per_thread = DEFAULT_MAX_REQUESTS_PER_THREAD;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
 
     apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
 
index 043f77f6915da8e6e1ea19e5ab1f8dd801ca8c3b..42e7c27b4b2bb236798abbee82189d30daad97ce 100644 (file)
 #define DEFAULT_PIDLOG "logs/httpd.pid"
 #endif
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /*
  * Interval, in microseconds, between scoreboard maintenance.
  */
index 46fb0977013164a963a041450c22e92ec3746f49..065040e63d11fcb35bb2b6d790f204cc01fcefa2 100644 (file)
 #define DEFAULT_LOCKFILE "logs/accept.lock"
 #endif
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /* Where the main/parent process's pid is logged */
 #ifndef DEFAULT_PIDLOG
 #define DEFAULT_PIDLOG "logs/httpd.pid"
index 225b27332c5fc40dd5b8dc9aa4cd0d6ee1a227bb..1ea2675b4fba3ecf8e33b98e5c393ac0faaa9e75 100644 (file)
@@ -1493,7 +1493,6 @@ static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptem
     max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
     max_threads = thread_limit;
     ap_pid_fname = DEFAULT_PIDLOG;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
     ap_lock_fname = DEFAULT_LOCKFILE;
     max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
     curr_child_num = 0;
index 8be591932178a3cb2a5ab535a7164e03f7a93f6d..ebada94fd84bad2ce6e4b53702e618fd30a47053 100644 (file)
   #endif
 */
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /* Where the main/parent process's pid is logged */
 /*#ifndef DEFAULT_PIDLOG
   #define DEFAULT_PIDLOG "logs/httpd.pid"
index 7ef5f3e7b0aa22e0562a7f585bdb2826cfec08c2..31e7a5e64e9b8d9a7bae8a2b14ea35b4f7e2b23c 100644 (file)
@@ -971,7 +971,6 @@ static int netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp
     ap_threads_min_free = DEFAULT_MIN_FREE_THREADS;
     ap_threads_max_free = DEFAULT_MAX_FREE_THREADS;
     ap_threads_limit = HARD_THREAD_LIMIT;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
     ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
     ap_extended_status = 0;
 
index 46fb0977013164a963a041450c22e92ec3746f49..065040e63d11fcb35bb2b6d790f204cc01fcefa2 100644 (file)
 #define DEFAULT_LOCKFILE "logs/accept.lock"
 #endif
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /* Where the main/parent process's pid is logged */
 #ifndef DEFAULT_PIDLOG
 #define DEFAULT_PIDLOG "logs/httpd.pid"
index 225b27332c5fc40dd5b8dc9aa4cd0d6ee1a227bb..1ea2675b4fba3ecf8e33b98e5c393ac0faaa9e75 100644 (file)
@@ -1493,7 +1493,6 @@ static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptem
     max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
     max_threads = thread_limit;
     ap_pid_fname = DEFAULT_PIDLOG;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
     ap_lock_fname = DEFAULT_LOCKFILE;
     max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
     curr_child_num = 0;
index 3854a2bc239977754a40cb02f13c88d8d2be263b..2ba0867c51cd7756ccebca1e8389f032a3acaabe 100644 (file)
 #define DEFAULT_LOCKFILE "logs/accept.lock"
 #endif
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /* Where the main/parent process's pid is logged */
 #ifndef DEFAULT_PIDLOG
 #define DEFAULT_PIDLOG "logs/httpd.pid"
index f7c510d9d17564ce3b3776e5a38506082264af46..d76098c24995c2e37314a150ccb50aa4669aa7a7 100644 (file)
@@ -1254,7 +1254,6 @@ static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp
     ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
     ap_daemons_limit = server_limit;
     ap_pid_fname = DEFAULT_PIDLOG;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
     ap_lock_fname = DEFAULT_LOCKFILE;
     ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
     ap_extended_status = 0;
index 4b9ea3acb2b508b8bef8112ecc9a4b22311645f2..c3993c4607b05e6043e7baf0f855f739010f47ac 100644 (file)
 #define DEFAULT_LOCKFILE "logs/accept.lock"
 #endif
 
-/* Scoreboard file, if there is one */
-#ifndef DEFAULT_SCOREBOARD
-#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
-#endif
-
 /* Where the main/parent process's pid is logged */
 #ifndef DEFAULT_PIDLOG
 #define DEFAULT_PIDLOG "logs/httpd.pid"
index f571fb63cc6134d008538b530553c3a481fe1734..1750862df96502f85885d93fa0562399c611594a 100644 (file)
@@ -1582,7 +1582,6 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
     ap_daemons_limit = server_limit;
     ap_threads_per_child = DEFAULT_THREADS_PER_CHILD;
     ap_pid_fname = DEFAULT_PIDLOG;
-    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
     ap_lock_fname = DEFAULT_LOCKFILE;
     ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
     ap_extended_status = 0;
index 8eb8e1a24156ccd5b23250a40df7175d2d9b4d99..744fd429058fe8f9a4267b167922c7a71ea653eb 100644 (file)
@@ -161,6 +161,31 @@ void ap_init_scoreboard(void *shared_score)
     ap_assert(more_storage == (char*)shared_score + scoreboard_size);
 }
 
+/**
+ * Create a name-based scoreboard in the given pool using the
+ * given filename.
+ */
+static apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
+                                                const char *fname)
+{
+#if APR_HAS_SHARED_MEMORY
+    apr_status_t rv;
+
+    /* The shared memory file must not exist before we create the
+     * segment. */
+    apr_file_remove(fname, pool); /* ignore errors */
+
+    rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
+                     "unable to create scoreboard "
+                     "(name-based shared memory failure)");
+        return rv;
+    }
+#endif /* APR_HAS_SHARED_MEMORY */
+    return APR_SUCCESS;
+}
+
 /* ToDo: This function should be made to handle setting up 
  * a scoreboard shared between processes using any IPC technique, 
  * not just a shared memory segment
@@ -183,35 +208,32 @@ static apr_status_t open_scoreboard(apr_pool_t *pconf)
         return rv;
     }
 
-#ifndef WIN32
-    rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname,
-                        global_pool);
-    if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
-        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
-                     "Fatal error: could not create scoreboard "
-                     "(using anonymous shared memory)");
-        return rv;
+    /* The config says to create a name-based shmem */
+    if (ap_scoreboard_fname) {
+        /* make sure it's an absolute pathname */
+        fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
+
+        return create_namebased_scoreboard(global_pool, fname);
     }
-    if (rv == APR_ENOTIMPL) {
-#else
-    {
-#endif
-        if (ap_scoreboard_fname) {
-            fname = ap_server_root_relative(global_pool, ap_scoreboard_fname);
-            /* make sure the file doesn't exist before trying 
-             * to create the segment. */
-            apr_file_remove(fname, global_pool);
-        }
-        rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname,
-                            global_pool);
-        if (rv != APR_SUCCESS) {
+    else { /* config didn't specify, we get to choose shmem type */
+        rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
+                            global_pool); /* anonymous shared memory */
+        if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
-                         "Fatal error: could not open(create) scoreboard");
+                         "Unable to create scoreboard "
+                         "(anonymous shared memory failure)");
             return rv;
         }
+        /* Make up a filename and do name-based shmem */
+        else if (rv == APR_ENOTIMPL) {
+            /* Make sure it's an absolute pathname */
+            ap_scoreboard_fname = DEFAULT_SCOREBOARD;
+            fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
+
+            return create_namebased_scoreboard(global_pool, fname);
+        }
     }
-    /* everything will be cleared shortly */
-#endif
+#endif /* APR_HAS_SHARED_MEMORY */
     return APR_SUCCESS;
 }