You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2019/01/21 10:14:04 UTC

[tcl-rivet] branch newserverinit created (now 4213d7e)

This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a change to branch newserverinit
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git.


      at 4213d7e  cosmetic changes to improve readability

This branch includes the following new commits:

     new f07fc9a  creating a branch from stashed work on new server init mechanics
     new 1f3b273  Merge branch 'master' into newserverinit
     new 0f61ef8  Merge branch 'master' into newserverinit
     new 4213d7e  cosmetic changes to improve readability

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


[tcl-rivet] 02/04: Merge branch 'master' into newserverinit

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch newserverinit
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 1f3b273176c1a901f0aec50b06c37c386e097b61
Merge: f07fc9a 4cb80bc
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Thu Nov 8 19:36:57 2018 +0100

    Merge branch 'master' into newserverinit

 ChangeLog                    | 4 ++++
 src/mod_rivet_ng/mod_rivet.c | 2 +-
 src/mod_rivet_ng/mod_rivet.h | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


[tcl-rivet] 04/04: cosmetic changes to improve readability

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch newserverinit
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 4213d7e357a98e9944cde0bd259bcd99c39c2b99
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Tue Nov 20 15:17:17 2018 +0100

    cosmetic changes to improve readability
---
 doc/rivet.xml | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/doc/rivet.xml b/doc/rivet.xml
index d4543c7..7324d0a 100644
--- a/doc/rivet.xml
+++ b/doc/rivet.xml
@@ -35,22 +35,22 @@
     <!ENTITY asciiglyphs.xml       SYSTEM "xml/asciiglyphs.xml" >
     <!ENTITY lazybridge.xml        SYSTEM "xml/lazybridge.xml" >
     <!ENTITY formbroker.xml        SYSTEM "xml/formbroker.xml" >
-    <!ENTITY version	              "3.1" >
+    <!ENTITY version	           "3.1" >
     <!ENTITY fullversion           "3.1.0" >
-    <!ENTITY version2-series	     "2.0,2.1,2.2,2.3" >
-    <!ENTITY version2-generic	     "2.x" >
-    <!ENTITY version30		        "3.0" >
-    <!ENTITY version31		        "3.1" >
+    <!ENTITY version2-series	   "2.0,2.1,2.2,2.3" >
+    <!ENTITY version2-generic	   "2.x" >
+    <!ENTITY version30		       "3.0" >
+    <!ENTITY version31		       "3.1" >
     <!ENTITY tcltk-url             "http://www.tcl.tk/" >
     <!ENTITY apache-url            "http://httpd.apache.org" >
     <!ENTITY apachedoc-vhost       "https://httpd.apache.org/docs/2.4/vhosts" >
-    <!ENTITY apachedoc-mpm	        "https://httpd.apache.org/docs/2.4/mpm.html" >
-    <!ENTITY apachedoc-prefork	  "https://httpd.apache.org/docs/2.4/mod/prefork.html" >
-    <!ENTITY apachedoc-worker	     "https://httpd.apache.org/docs/2.4/mod/worker.html" >
-    <!ENTITY apachedoc-event	     "https://httpd.apache.org/docs/2.4/mod/event.html" >
-    <!ENTITY apachedoc-winnt		  "https://httpd.apache.org/docs/2.4/mod/mpm_winnt.html" >
+    <!ENTITY apachedoc-mpm	       "https://httpd.apache.org/docs/2.4/mpm.html" >
+    <!ENTITY apachedoc-prefork	   "https://httpd.apache.org/docs/2.4/mod/prefork.html" >
+    <!ENTITY apachedoc-worker	   "https://httpd.apache.org/docs/2.4/mod/worker.html" >
+    <!ENTITY apachedoc-event	   "https://httpd.apache.org/docs/2.4/mod/event.html" >
+    <!ENTITY apachedoc-winnt	   "https://httpd.apache.org/docs/2.4/mod/mpm_winnt.html" >
     <!ENTITY apachedoc-docroot     "https://httpd.apache.org/docs/2.4/mod/core.html#documentroot" >
-    <!ENTITY apachedoc-alias		  "https://httpd.apache.org/docs/2.4/mod/mod_alias.html" >
+    <!ENTITY apachedoc-alias	   "https://httpd.apache.org/docs/2.4/mod/mod_alias.html" >
     <!ENTITY apachedoc-rewrite     "https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html" >
     <!ENTITY apachedoc-perftuning  "https://httpd.apache.org/docs/2.4/misc/perf-tuning.html" >
 ]>
@@ -90,7 +90,7 @@
   	</articleinfo>
 
   	<para>
-    	This manual was generated on <?dbtimestamp format="A Y-m-d X" ?>
+    	This manual is released as part of Apache/Rivet &fullversion; (<?dbtimestamp format="A Y-m-d X" ?>).
   	</para>
 
 	<!-- Introduction -->


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


[tcl-rivet] 01/04: creating a branch from stashed work on new server init mechanics

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch newserverinit
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit f07fc9ade0afce8a8b39dd27ba68f61cb3aad628
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Wed Nov 7 10:06:12 2018 +0100

    creating a branch from stashed work on new server init mechanics
---
 ChangeLog                                |   7 +-
 doc/xml/commands.xml                     |   2 +-
 src/mod_rivet_ng/mod_rivet.c             | 188 +++++++++++++++++++------------
 src/mod_rivet_ng/mod_rivet.h             |   6 +-
 src/mod_rivet_ng/mod_rivet_common.c      |  41 +++++--
 src/mod_rivet_ng/mod_rivet_common.h      |   1 +
 src/mod_rivet_ng/rivet_lazy_mpm.c        |   5 +
 src/mod_rivet_ng/rivet_prefork_mpm.c     | 102 +++++++++++++----
 src/mod_rivet_ng/rivet_worker_mpm.c      |  17 ++-
 src/mod_rivet_ng/worker_prefork_common.c |  29 -----
 10 files changed, 255 insertions(+), 143 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 301bf41..3dab9f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,11 +33,14 @@
     case of handling an error that occurs in the default error script may
     need the introduction of a new test
 
+2018-04-27 Massimo Manghi <mx...@apache.org>
+    * doc/xml/command.xml: small correction in ::rivet::exit section 
+
 2018-04-09 Massimo Manghi <mx...@apache.org>
     * src/mod_rivet_ng/mod_rivet.h: changing argument list of function
     *mpm_thread_interp in the bridge interface. It must work
-    as an accessor to the interpreter database when both getting
-    and storing an interpreter pointer
+    as an accessor to the interpreter database either getting
+    or storing an interpreter pointer
 
 2018-02-28 Massimo Manghi <mx...@apache.org>
     * Makefile.am: default_request_handler.tcl and init.tcl can be
diff --git a/doc/xml/commands.xml b/doc/xml/commands.xml
index 4971cbf..be99749 100644
--- a/doc/xml/commands.xml
+++ b/doc/xml/commands.xml
@@ -647,7 +647,7 @@
 				could be the only way to exit a process and force the Apache HTTP web server to start
 				a fresh one. Moreover the core <command>exit</command> could be called from third parties
 				software and you may not be aware of it. We thus decided to trap this command and give it 
-				the most gentle behavior still preserving the its basic purpose.
+				the most gentle behavior still preserving its basic purpose.
 			</para>
 			<note>
 				Nonetheless we discourage the programmer to use such command, and suggest to focus on proper
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index 1c24e67..48e08d3 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -66,10 +66,10 @@
 #include "mod_rivet_common.h"
 #include "mod_rivet_generator.h"
 
-module AP_MODULE_DECLARE_DATA rivet_module;
-extern Tcl_ChannelType   RivetChan;
-DLLEXPORT apr_threadkey_t*         rivet_thread_key    = NULL;
-DLLEXPORT mod_rivet_globals*       module_globals      = NULL;
+module AP_MODULE_DECLARE_DATA       rivet_module;
+extern Tcl_ChannelType              RivetChan;
+DLLEXPORT apr_threadkey_t*          rivet_thread_key    = NULL;
+DLLEXPORT mod_rivet_globals*        module_globals      = NULL;
 
 #define ERRORBUF_SZ         256
 #define TCL_HANDLER_FILE    RIVET_DIR"/default_request_handler.tcl"
@@ -77,7 +77,19 @@ DLLEXPORT mod_rivet_globals*       module_globals      = NULL;
 /*
  * -- Rivet_SeekMPMBridge 
  *
+ *  Determing the bridge name to be loaded. The configuration
+ *  is checked to see if an MpmBridge line existed (resulting
+ *  in setting the configuration mpm_bridge field) and if
+ *  defined 
+ *  
+ *   - interpolated into rivet_<bridge-name>_mpm.so 
+ *   - or interpreted as a full path to a bridge
  *
+ *  if not defined we adopt an heuristic method based
+ *  on the response from the call to ap_mpm_query. If
+ *  the MPM is not threaded we load the prefork bridge
+ *  
+ *  As a fallback we load the worker bridge
  */
 
 static char*
@@ -173,6 +185,12 @@ Rivet_CreateModuleGlobals (apr_pool_t* pool, server_rec* server)
         exit(1);
     }
 
+    /* This mutex should protect the process wide pool */
+
+    apr_thread_mutex_create(&mod_rivet_g->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pool);
+
+    /* establishing the name of the bridge to be loaded */
+
     mod_rivet_g->rivet_mpm_bridge = Rivet_SeekMPMBridge(pool,server);
 
     /* read the default request handler code */
@@ -213,28 +231,19 @@ int Rivet_Exit_Handler(int code)
 /* 
  * -- Rivet_RunServerInit
  *
+ *  Server initialization
  * 
  */
 
 static int
-Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s)
+Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *server)
 {
-#ifdef WIN32
-	char*			   parent_pid_var = NULL;
-#endif
-    rivet_server_conf* rsc = RIVET_SERVER_CONF( s->module_config );
+    rivet_server_conf* rsc;
+    server_rec*        s;
 
     FILEDEBUGINFO;
 
-    /* we create and initialize a master (server) interpreter */
-
-    module_globals->server_interp = Rivet_NewVHostInterp(pPool,s); /* root interpreter */
-
-    /* We initialize the interpreter and we won't register a channel with it because
-     * we couldn't send data to the stdout anyway 
-	 */
-
-    Rivet_PerInterpInit(module_globals->server_interp,NULL,s,pPool);
+#ifdef WIN32
 
 	/* This code conditionally compiled when we are building for the
 	 * Windows family of OS. The winnt MPM runs the post_config 
@@ -245,59 +254,100 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser
 	 * (https://wiki.apache.org/httpd/ModuleLife)
 	 */
 	
-	#ifdef WIN32
-	
 	/* if the environment variable AP_PARENT_PID is set 
      * we know we are in a child process of the winnt MPM
      */
-	
-	apr_env_get(&parent_pid_var,"AP_PARENT_PID",pTemp);
-	if (parent_pid_var != NULL)
 	{
-		ap_log_error(APLOG_MARK,APLOG_INFO,0,s,
-					"AP_PARENT_PID found: not running the Tcl server script in winnt MPM child process");
-		return OK;
-	} else {
-		ap_log_error(APLOG_MARK,APLOG_INFO,0,s,
-				 "AP_PARENT_PID undefined, we proceed with server initialization");
+	    char* parent_pid_var = NULL;
+
+        apr_env_get(&parent_pid_var,"AP_PARENT_PID",pTemp);
+        if (parent_pid_var != NULL)
+        {
+            ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
+                        "AP_PARENT_PID found: not running the Tcl server script in winnt MPM child process");
+            return OK;
+        } else {
+            ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
+                     "AP_PARENT_PID undefined, we proceed with server initialization");
+        }
 	}
-	
-	#endif
-	
-    /* We don't create the cache here: it would make sense for prefork MPM
-     * but threaded MPM bridges have their pool of threads. Each of them
-     * will by now have their own cache
-     */
 
-    if (rsc->rivet_server_init_script != NULL) {
-        Tcl_Interp* interp = module_globals->server_interp->interp;
-        Tcl_Obj*    server_init = Tcl_NewStringObj(rsc->rivet_server_init_script,-1);
+#endif
 
-        Tcl_IncrRefCount(server_init);
+    module_globals->server_interps = 
+        apr_pcalloc(pPool,module_globals->vhosts_count*sizeof(rivet_thread_interp));
 
-        if (Tcl_EvalObjEx(interp, server_init, 0) != TCL_OK)
+    for (s = server; s != NULL; s = s->next)
+    {
+        rivet_server_conf*      vhost_rsc;
+        rivet_thread_interp*    interp_obj = NULL;
+
+        vhost_rsc = RIVET_SERVER_CONF(s->module_config);
+
+        if (vhost_rsc->rivet_server_init_script != NULL) 
         {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
-                         MODNAME ": Error running ServerInitScript '%s': %s",
-                         rsc->rivet_server_init_script,
-                         Tcl_GetVar(interp, "errorInfo", 0));
-        } else {
-            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, 
-                         MODNAME ": ServerInitScript '%s' successful", 
-                         rsc->rivet_server_init_script);
-        }
+            Tcl_Interp* interp;
+            Tcl_Obj*    server_init;
+ 
+            /* either we want separate virtual interps or we haven't 
+             * created an interpreter so far we create one
+             */
+
+            if ((interp_obj == NULL) || vhost_rsc->separate_virtual_interps) 
+            {
+                interp_obj = Rivet_NewVHostInterp(pPool,s);
+
+                /* We initialize the interpreter and we won't 
+                 * register a channel with it because
+                 * we couldn't send data to the stdout anyway 
+                 */
+
+                Rivet_PerInterpInit(interp_obj,NULL,s,pPool);
+            }
+
+            /* This is stored basically to enable the prefork bridge to pick
+             * the pointer to these interpreters from the globals
+             */
+
+            module_globals->server_interps[vhost_rsc->idx] = interp_obj;
+            
+            /* We don't create the cache here: it would make sense for prefork MPM
+             * but threaded MPM bridges have their pool of threads. Each of them
+             * will by now have their own cache
+             */
+
+            interp = interp_obj->interp;
+            server_init = Tcl_NewStringObj(vhost_rsc->rivet_server_init_script,-1);
+
+            Tcl_IncrRefCount(server_init);
+
+            if (Tcl_EvalObjEx(interp, server_init, 0) != TCL_OK)
+            {
+                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
+                             MODNAME ": Error running ServerInitScript '%s': %s",
+                             rsc->rivet_server_init_script,
+                             Tcl_GetVar(interp, "errorInfo", 0));
+            } else {
+                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, 
+                             MODNAME ": ServerInitScript '%s' successful", 
+                             rsc->rivet_server_init_script);
+            }
 
-        Tcl_DecrRefCount(server_init);
+            Tcl_DecrRefCount(server_init);
+
+        }
+        
     }
 
 	/* bridge specific server init script */
 	
-	RIVET_MPM_BRIDGE_CALL(mpm_server_init,pPool,pLog,pTemp,s);
+	RIVET_MPM_BRIDGE_CALL(mpm_server_init,pPool,pLog,pTemp,server);
 
     return OK;
 }
 
-/* -- Rivet_ServerInit
+/* 
+ * -- Rivet_ServerInit
  *
  * Post config hook. The server initialization loads the MPM bridge
  * and runs the Tcl server initialization script
@@ -317,9 +367,8 @@ Rivet_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server
     ap_add_version_component(pPool,RIVET_PACKAGE_NAME);
 #endif
 
-	/* This function runs as post_config_hook
-	 * and as such it's run twice by design. 
-	 * This is the recommended way to avoid a double load of
+	/* This function runs as post_config_hook and as such it's run twice 
+     * by design. This is the recommended way to avoid a double load of
 	 * external modules.
 	 */
 
@@ -335,9 +384,8 @@ Rivet_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server
         return OK; /* This would be the first time through */
 	}	
 	
-    /* Everything revolves around this structure: module_globals */
-
-    /* the module global structure is allocated and the MPM bridge name established */
+    /* Everything revolves around this structure: module_globals. The structure 
+     * is allocated and the MPM bridge name is established */
 
     module_globals = Rivet_CreateModuleGlobals (pPool,server);
 
@@ -400,7 +448,6 @@ apr_status_t Rivet_Finalize(void* data)
 {
 
     RIVET_MPM_BRIDGE_CALL(mpm_finalize,data);
-    apr_threadkey_private_delete (rivet_thread_key);
 
     return OK;
 }
@@ -411,10 +458,6 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
     rivet_server_conf*  root_server_conf;
     server_rec*         s;
 
-    /* the thread key used to access to Tcl threads private data */
-
-    ap_assert (apr_threadkey_private_create (&rivet_thread_key, NULL, pChild) == APR_SUCCESS);
-
     /* This code is run once per child process. In a threaded Tcl builds the forking 
      * of a child process most likely has not preserved the thread where the Tcl 
      * notifier runs. The Notifier should have been restarted by one the 
@@ -427,23 +470,19 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
     Tcl_InitNotifier();
 #endif
 
+    /* for any non-prefork bridge the module globals are to be created here */
+
     if (module_globals == NULL)
     {
-        module_globals = Rivet_CreateModuleGlobals (pChild,server);
+        module_globals = Rivet_CreateModuleGlobals(pChild,server);
     }
 
-    /* This mutex should protect the process wide pool from concurrent access by 
-     * different threads
-     */
-
-    apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pChild);
-
     /* Once we have established a pool with the same lifetime of the child process we
      * process all the configured server records assigning an integer as unique key 
      * to each of them 
      */
 
-    root_server_conf = RIVET_SERVER_CONF( server->module_config );
+    root_server_conf = RIVET_SERVER_CONF(server->module_config);
     idx = 0;
     for (s = server; s != NULL; s = s->next)
     {
@@ -455,10 +494,11 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
          * was called. We really need a separate one for each server,
          * so we go ahead and create one here, if necessary. */
 
-        if (s != server && myrsc == root_server_conf) {
+        if (s != server && myrsc == root_server_conf) 
+        {
             myrsc = RIVET_NEW_CONF(pChild);
             ap_set_module_config(s->module_config, &rivet_module, myrsc);
-            Rivet_CopyConfig( root_server_conf, myrsc );
+            Rivet_CopyConfig(root_server_conf,myrsc);
         }
 
         myrsc->idx = idx++;
diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h
index 65225a0..e9ef620 100644
--- a/src/mod_rivet_ng/mod_rivet.h
+++ b/src/mod_rivet_ng/mod_rivet.h
@@ -19,8 +19,6 @@
     under the License.
 */
 
-/* $Id$ */
-
 #ifndef __mod_rivet_h__
 #define __mod_rivet_h__
 
@@ -198,8 +196,8 @@ typedef struct _mod_rivet_globals {
                                                  * the root server thus it's supposed to be >= 1 */
 	char*				default_handler;		/* Default request handler code             */
 	int					default_handler_size;	/* Size of the default_handler buffer       */
-    rivet_thread_interp* 
-                        server_interp;          /* server and prefork MPM interpreter       */
+    rivet_thread_interp** 
+                        server_interps;          /* server and prefork MPM interpreter       */
     apr_thread_mutex_t* pool_mutex;             /* threads commmon pool mutex               */
     rivet_bridge_table* bridge_jump_table;      /* Jump table to bridge specific procedures */
     mpm_bridge_status*  mpm;                    /* bridge private control structure         */
diff --git a/src/mod_rivet_ng/mod_rivet_common.c b/src/mod_rivet_ng/mod_rivet_common.c
index d40864d..6ccf7da 100644
--- a/src/mod_rivet_ng/mod_rivet_common.c
+++ b/src/mod_rivet_ng/mod_rivet_common.c
@@ -61,13 +61,41 @@ extern mod_rivet_globals* module_globals;
 extern module rivet_module;
 
 /*
+ * Rivet_DuplicateVhostInterp
+ *
+ *
+ */
+
+rivet_thread_interp* 
+Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj)
+{
+    rivet_thread_interp* interp_obj = apr_pcalloc(pool,sizeof(rivet_thread_interp));
+
+    interp_obj->interp      = source_obj->interp;
+    interp_obj->channel     = source_obj->channel;
+    interp_obj->cache_free  = source_obj->cache_free;
+    interp_obj->cache_size  = source_obj->cache_size;
+
+    /* An intepreter must have its own cache */
+
+    if (interp_obj->cache_size) {
+        RivetCache_Create(pool,interp_obj); 
+    }
+
+    interp_obj->pool            = source_obj->pool;
+    interp_obj->scripts         = (running_scripts *) apr_pcalloc(pool,sizeof(running_scripts));
+    interp_obj->per_dir_scripts = apr_hash_make(pool); 
+    interp_obj->flags           = source_obj->flags;
+    return interp_obj;
+}
+
+/*
  * -- Rivet_ReadFile
  * 
  */
 
 int
-Rivet_ReadFile (apr_pool_t* pool,char* filename,
-                char** buffer,int* nbytes)
+Rivet_ReadFile (apr_pool_t* pool,char* filename,char** buffer,int* nbytes)
 {
     apr_finfo_t*        file_info;
     apr_file_t*         apr_fp;
@@ -275,11 +303,11 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
      * across patchlevel releases
      */
 
-    if (Tcl_PkgRequire(interp, "Rivet", RIVET_INIT_VERSION, 1) == NULL)
+    if (Tcl_PkgRequire(interp,"Rivet",RIVET_INIT_VERSION,1) == NULL)
     {
-        ap_log_error (APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
+        ap_log_error (APLOG_MARK,APLOG_ERR,APR_EGENERAL,s,
                       MODNAME ": init.tcl must be installed correctly for Apache Rivet to function: %s (%s)",
-                      Tcl_GetStringResult(interp), RIVET_DIR );
+                      Tcl_GetStringResult(interp),RIVET_DIR);
         exit(1);
     }
 
@@ -361,7 +389,7 @@ rivet_thread_interp* Rivet_NewVHostInterp(apr_pool_t *pool,server_rec* server)
  *
  * -- Rivet_CreateRivetChannel
  *
- * Creates a channel and registers with to the interpreter
+ * Creates a channel 
  *
  *  Arguments:
  *
@@ -780,4 +808,3 @@ int Rivet_chdir_file (const char *file)
         
     return chdir_retval;
 }
-
diff --git a/src/mod_rivet_ng/mod_rivet_common.h b/src/mod_rivet_ng/mod_rivet_common.h
index e074ff6..de08275 100644
--- a/src/mod_rivet_ng/mod_rivet_common.h
+++ b/src/mod_rivet_ng/mod_rivet_common.h
@@ -22,6 +22,7 @@
 #ifndef _MOD_RIVET_COMMON_
 #define _MOD_RIVET_COMMON_
 
+EXTERN rivet_thread_interp* Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj);
 EXTERN running_scripts* Rivet_RunningScripts (apr_pool_t* pool,running_scripts* scripts,rivet_server_conf* rivet_conf);
 EXTERN void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,rivet_thread_private* private, server_rec *s, apr_pool_t *p);
 EXTERN void Rivet_CreateCache (apr_pool_t *p, rivet_thread_interp* interp_obj);
diff --git a/src/mod_rivet_ng/rivet_lazy_mpm.c b/src/mod_rivet_ng/rivet_lazy_mpm.c
index d406f55..f69545d 100644
--- a/src/mod_rivet_ng/rivet_lazy_mpm.c
+++ b/src/mod_rivet_ng/rivet_lazy_mpm.c
@@ -290,6 +290,10 @@ void Lazy_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
     server_rec*     s;
     server_rec*     root_server = module_globals->server;
 
+    /* the thread key used to access to Tcl threads private data */
+
+    ap_assert (apr_threadkey_private_create (&rivet_thread_key, NULL, pool) == APR_SUCCESS);
+
     module_globals->mpm = apr_pcalloc(pool,sizeof(mpm_bridge_status));
 
     /* This mutex is only used to consistently carry out these 
@@ -463,6 +467,7 @@ apr_status_t Lazy_MPM_Finalize (void* data)
         apr_thread_mutex_unlock(mutex);
     }
 
+    apr_threadkey_private_delete (rivet_thread_key);
     return APR_SUCCESS;
 }
 
diff --git a/src/mod_rivet_ng/rivet_prefork_mpm.c b/src/mod_rivet_ng/rivet_prefork_mpm.c
index d14ec04..a04ce6c 100644
--- a/src/mod_rivet_ng/rivet_prefork_mpm.c
+++ b/src/mod_rivet_ng/rivet_prefork_mpm.c
@@ -36,17 +36,81 @@
 extern DLLIMPORT mod_rivet_globals* module_globals;
 extern DLLIMPORT apr_threadkey_t*   rivet_thread_key;
 
-rivet_thread_private*   Rivet_VirtualHostsInterps (rivet_thread_private* private);
+rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private);
 
-/* -- Prefork_MPM_Finalize */
+int Prefork_Bridge_ServerInit (apr_pool_t *pPool, 
+                               apr_pool_t *pLog,
+                               apr_pool_t *pTemp, server_rec *server)
+{
+    rivet_server_conf*      rsc;
+    server_rec*             s;
+    rivet_thread_interp*    interp_obj = NULL; 
+
+    /* the thread key used to access to Tcl threads private data */
+
+    ap_assert (apr_threadkey_private_create (&rivet_thread_key, NULL, pPool) == APR_SUCCESS);
+
+    rsc = RIVET_SERVER_CONF(server->module_config);
+    if (!rsc->separate_virtual_interps)
+    {
+        int idx;
+
+        for (idx = 0;idx < module_globals->vhosts_count;idx++)
+        {
+            if (module_globals->server_interps[idx] != NULL)
+            {
+                interp_obj = module_globals->server_interps[idx];
+                break;
+            }
+        }
+
+        /* if no interpreter objects were created we proceed creating one */
+
+        if (interp_obj == NULL)
+        {
+            interp_obj = Rivet_NewVHostInterp(pPool,server);
+        }
+    }
+
+   /*
+    * 
+    */
+
+    for (s = server; s != NULL; s = s->next)
+    {
+        idx = s->idx;
+        if (module_globals->server_interps[idx] == NULL)
+        {
+            if (rsc->separate_virtual_interps)
+            {
+                module_globals->server_interps[idx] = Rivet_NewVHostInterp(pPool,s);
+
+                /* We initialize the interpreter */
+                
+                Rivet_PerInterpInit(interp_obj,NULL,s,pPool);
+
+            }
+            else
+            {
+                module_globals->server_interps[idx] = interp_obj;
+            }
+        }
 
-apr_status_t Prefork_MPM_Finalize (void* data)
+
+    }
+    return OK;
+}
+
+
+/* -- Prefork_Bridge_Finalize */
+
+apr_status_t Prefork_Bridge_Finalize (void* data)
 {
     rivet_thread_private*   private;
     server_rec* s = (server_rec*) data;
 
     RIVET_PRIVATE_DATA_NOT_NULL(rivet_thread_key,private)
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, s, "Running prefork bridge finalize method");
+    ap_log_error(APLOG_MARK,APLOG_DEBUG,APR_SUCCESS,s,"Running prefork bridge finalize method");
 
     // No, we don't do any clean up anymore as we are just shutting this process down
     // Rivet_ProcessorCleanup(private);
@@ -54,13 +118,9 @@ apr_status_t Prefork_MPM_Finalize (void* data)
     return OK;
 }
 
+/* -- Prefork_Bridge_ChildInit: bridge child process initialization  */
 
-/* -- Prefork_MPM_ChildInit: bridge child process initialization
- *
- */
-
-
-void Prefork_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
+void Prefork_Bridge_ChildInit (apr_pool_t* pool, server_rec* server)
 {
     rivet_thread_private*   private;
 
@@ -103,7 +163,7 @@ void Prefork_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
 }
 
 /*
- * -- Prefork_MPM_Request
+ * -- Prefork_Bridge_Request
  *
  *  The prefork implementation of this function is basically a wrapper of
  *  Rivet_SendContent. The real job is fetching the thread private data
@@ -117,7 +177,7 @@ void Prefork_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
  *   HTTP status code (see the Apache HTTP web server documentation)
  */
 
-int Prefork_MPM_Request (request_rec* r,rivet_req_ctype ctype)
+int Prefork_Bridge_Request (request_rec* r,rivet_req_ctype ctype)
 {
     rivet_thread_private*   private;
 
@@ -161,7 +221,7 @@ rivet_thread_interp* MPM_MasterInterp(server_rec* server)
 }
 
 /*
- * -- Prefork_MPM_ExitHandler
+ * -- Prefork_Bridge_ExitHandler
  *
  *  Just calling Tcl_Exit  
  *
@@ -173,7 +233,7 @@ rivet_thread_interp* MPM_MasterInterp(server_rec* server)
  *  the thread running the Tcl script will exit 
  */
 
-int Prefork_MPM_ExitHandler(int code)
+int Prefork_Bridge_ExitHandler(int code)
 {
     Tcl_Exit(code);
 
@@ -181,7 +241,7 @@ int Prefork_MPM_ExitHandler(int code)
     return TCL_OK;
 }
 
-rivet_thread_interp* Prefork_MPM_Interp (rivet_thread_private* private,
+rivet_thread_interp* Prefork_Bridge_Interp (rivet_thread_private* private,
                                          rivet_server_conf*    conf,
                                          rivet_thread_interp*  interp)
 {
@@ -192,11 +252,11 @@ rivet_thread_interp* Prefork_MPM_Interp (rivet_thread_private* private,
 
 DLLEXPORT
 RIVET_MPM_BRIDGE {
-    NULL,
-    Prefork_MPM_ChildInit,
-    Prefork_MPM_Request,
-    Prefork_MPM_Finalize,
-    Prefork_MPM_ExitHandler,
-    Prefork_MPM_Interp
+    Prefork_Bridge_ServerInit,
+    Prefork_Bridge_ChildInit,
+    Prefork_Bridge_Request,
+    Prefork_Bridge_Finalize,
+    Prefork_Bridge_ExitHandler,
+    Prefork_Bridge_Interp
 };
 
diff --git a/src/mod_rivet_ng/rivet_worker_mpm.c b/src/mod_rivet_ng/rivet_worker_mpm.c
index 7c36afe..b1fcf71 100644
--- a/src/mod_rivet_ng/rivet_worker_mpm.c
+++ b/src/mod_rivet_ng/rivet_worker_mpm.c
@@ -444,8 +444,6 @@ static void* APR_THREAD_FUNC threaded_bridge_supervisor (apr_thread_t *thd, void
     return NULL;
 }
 
-// int Worker_MPM_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s) { return OK; }
-
 /*
  * -- Worker_MPM_ChildInit
  *
@@ -461,7 +459,15 @@ static void* APR_THREAD_FUNC threaded_bridge_supervisor (apr_thread_t *thd, void
 void Worker_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
 {
     apr_status_t        rv;
-    
+
+    /* the thread key used to access to Tcl threads private data */
+
+    ap_assert (apr_threadkey_private_create (&rivet_thread_key, NULL, pool) == APR_SUCCESS);
+
+    /* On some platform this is required in order to initialize the
+     * 
+     */
+ 
     apr_atomic_init(pool);
 
 #ifdef RIVET_SERIALIZE_HTTP_REQUESTS
@@ -691,7 +697,7 @@ apr_status_t Worker_MPM_Finalize (void* data)
         }
     }
 
-    // apr_threadkey_private_delete (handler_thread_key);
+    apr_threadkey_private_delete (rivet_thread_key);
     return OK;
 }
 
@@ -722,10 +728,11 @@ rivet_thread_interp* MPM_MasterInterp(server_rec* s)
 /*
  * -- Worker_MPM_ExitHandler
  *  
- *  Signals a thread to exit by setting the loop control flag to 0
+ * Signals a thread to exit by setting the loop control flag to 0
  * and by returning a Tcl error with error code THREAD_EXIT_CODE
  *
  *  Arguments:
+ *
  *      int code
  *
  * Side Effects:
diff --git a/src/mod_rivet_ng/worker_prefork_common.c b/src/mod_rivet_ng/worker_prefork_common.c
index a3f170c..54f6f05 100644
--- a/src/mod_rivet_ng/worker_prefork_common.c
+++ b/src/mod_rivet_ng/worker_prefork_common.c
@@ -40,35 +40,6 @@ extern DLLIMPORT module rivet_module;
 
 extern rivet_thread_interp* MPM_MasterInterp(server_rec* s);
 
-/*
- * Rivet_DuplicateVhostInterp
- *
- *
- */
-
-static rivet_thread_interp* 
-Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj)
-{
-    rivet_thread_interp* interp_obj = apr_pcalloc(pool,sizeof(rivet_thread_interp));
-
-    interp_obj->interp      = source_obj->interp;
-    interp_obj->channel     = source_obj->channel;
-    interp_obj->cache_free  = source_obj->cache_free;
-    interp_obj->cache_size  = source_obj->cache_size;
-
-    /* An intepreter must have its own cache */
-
-    if (interp_obj->cache_size) {
-        RivetCache_Create(pool,interp_obj); 
-    }
-
-    interp_obj->pool            = source_obj->pool;
-    interp_obj->scripts         = (running_scripts *) apr_pcalloc(pool,sizeof(running_scripts));
-    interp_obj->per_dir_scripts = apr_hash_make(pool); 
-    interp_obj->flags           = source_obj->flags;
-    return interp_obj;
-}
-
 /* -- Rivet_VirtualHostsInterps 
  *
  * The server_rec chain is walked through and server configurations is read to


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


[tcl-rivet] 03/04: Merge branch 'master' into newserverinit

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch newserverinit
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 0f61ef8aa70b6aec3baf543c29bb1d4c14252129
Merge: 1f3b273 a3d08c0
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Tue Nov 20 10:34:48 2018 +0100

    Merge branch 'master' into newserverinit

 ChangeLog                    |  6 ++++++
 doc/rivet.xml.in             | 24 ++++++++++++------------
 src/mod_rivet_ng/rivetCore.c | 23 ++++++++++++++++++++++-
 tests/fqrivet_var.tcl        | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/post.test              | 23 +++++++++++++++++++++++
 5 files changed, 103 insertions(+), 13 deletions(-)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org