>> wow, I didn't expect to see this followed up upon.  thanks.
> 
> 
> maybe httpd developers should be stranded in airports more often... 
> also, several weeks ago somebody was complaining to me about various
> things they didn't like about Apache 2... one of the ones I took note of
> was having httpd -V display the name of the MPM...  so when I saw your
> old post I could visualize that to-do getting marked DONE with little
> effort on my part :)

:)


> 
>>>> Server version: Apache/2.1.0-dev
>>>> Server built:   Aug 12 2003 02:25:22
>>>> Server's Module Magic Number: 20030213:1
>>>> Architecture:   32-bit
>>>> Server MPM:     Prefork
>>>
>>>
>>>
>>>
>>> too bad ap_show_mpm doesn't list this like other modules :(
>>> ("prefork.c" or "worker.c")... the major source file name is what you
>>> need in <IfModule FOO>
>>
>>
>>
>> hmm... odd.  I guess I'll take your word for it that doesn't work now 

oh, I see what you mean now - <IfModule prefork.c> works but httpd -V
doesn't show prefork.c.

> 
> 
> very minor issue... forget about it :)

k :)

> 
>> but if it doesn't I'd be happy to try and make it work if there is a
>> consensus that it would be a good thing.  the only issue I can see is
>> something mentioned in the original thread on test-dev@ - that
>> attributes like being threaded (or not) are generally more useful than
>> the more simplistic approach of looking for worker.c.
>>
>> http://marc.theaimsgroup.com/?l=apache-test-dev&m=105795076610731&w=2
> 
> 
> do whatever Stas said w.r.t. that :)

well, I wasn't taling about the Apache-Test stuff, per se, but rather what
Bill had to say about querying for specific mpm's versus threads in general,
which I think is a very good point - I actually care very little in my code
whether apache is using worker or leader, it's threads or not that's
important (to me anyway :)  thus the below...

> 
>> nevertheless, I'd be happy to do the scut work here and code both up
>> (httpd -V and IfDefine/IfModule stuff) if some agreement can be
>> reached on exactly what it all ought to look like.
> 
> 
> scratch the Ifdefine issue for now...  I don't think it is so
> important...  at worst, we just have to change the definition of the
> MPM_NAME symbol in each MPM's header file

contrary to your advice, I took the initiative and coded <IfThreaded>
against 2.1.  basically, this would allow you to group threaded directives
together.  so, instead of this

<IfModule worker.c>
    ThreadsPerChild      5
</IfModule>


<IfModule perchild.c>
    MaxThreadsPerChild   5
</IfModule>

<IfModule prefork.c>
    MaxClients           5
</IfModule>

and so on for every threaded mpm, we could have

<IfThreaded>
    MaxThreadsPerChild   5
</IfThreaded>

<IfModule prefork.c>
    MaxClients           5
</IfModule>

I toyed with the idea of adding <IfNotThreaded> to parallel the concept, but
I wasn't sure about it - I figured I'd see how the initial idea went over
first :)

so, patch attached and feedback welcome.  I'll work on the real httpd -V
stuff later this afternoon.

--Geoff
Index: server/core.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
retrieving revision 1.252
diff -u -r1.252 core.c
--- server/core.c       21 Nov 2003 15:02:04 -0000      1.252
+++ server/core.c       2 Dec 2003 16:54:26 -0000
@@ -90,6 +90,7 @@
 #include "mod_core.h"
 #include "mod_proxy.h"
 #include "ap_listen.h"
+#include "ap_mpm.h"
 
 /* LimitXMLRequestBody handling */
 #define AP_LIMIT_UNSET                  ((long) -1)
@@ -1928,6 +1929,45 @@
     }
 }
 
+static const char *start_ifthreaded(cmd_parms *cmd, void *mconfig, const char *arg)
+{
+    const char *endp = ap_strrchr_c(arg, '>');
+    int mpm_query_info;
+    apr_status_t retval;
+
+    if (endp == NULL) {
+        return unclosed_directive(cmd);
+    }
+
+    arg = apr_pstrndup(cmd->pool, arg, endp - arg);
+
+    if (arg[0]) {
+        return "<IfThreaded> takes no arguments";
+    }
+
+    retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
+
+    if (retval != APR_SUCCESS) {
+        return apr_pstrcat(cmd->pool, "<IfThreaded> could not query ",
+                           ap_show_mpm(), " MPM for threads", NULL);
+    }
+
+    if (mpm_query_info) {
+        ap_directive_t *parent = NULL;
+        ap_directive_t *current = NULL;
+        const char *retval;
+
+        retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd,
+                                      &current, &parent, "<IfThreaded");
+        *(ap_directive_t **)mconfig = current;
+        return retval;
+    }
+    else {
+        *(ap_directive_t **)mconfig = NULL;
+        return ap_soak_end_container(cmd, "<IfThreaded");
+    }
+}
+
 /* httpd.conf commands... beginning with the <VirtualHost> business */
 
 static const char *virtualhost_section(cmd_parms *cmd, void *dummy,
@@ -3073,6 +3113,8 @@
   "Container for directives based on existance of specified modules"),
 AP_INIT_TAKE1("<IfDefine", start_ifdefine, NULL, EXEC_ON_READ | OR_ALL,
   "Container for directives based on existance of command line defines"),
+AP_INIT_RAW_ARGS("<IfThreaded", start_ifthreaded, NULL, EXEC_ON_READ | OR_ALL,
+  "Container for directives based on existance of a threaded MPM"),
 AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF,
   "Container for directives affecting resources located in the "
   "specified directories"),

Reply via email to