You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by mx...@apache.org on 2011/01/31 23:33:46 UTC
svn commit: r1065838 - in /tcl/rivet/trunk: ./ ChangeLog TODO VERSION
configure.ac doc/xml/directives.xml src/Makefile.am
src/apache-2/mod_rivet.c src/apache-2/mod_rivet.h
Author: mxmanghi
Date: Mon Jan 31 22:33:45 2011
New Revision: 1065838
URL: http://svn.apache.org/viewvc?rev=1065838&view=rev
Log:
2011-01-31 Massimo Manghi <mx...@apache.org>
* configure.ac: default value for directive SeparateVirtualInterps changed to 'yes'.
* VERSION: version number set as 2.1.0r1 ('r' is for 'revision')
* doc/xml/directives.xml: New directive ServerInitScript is documented.
Modified:
tcl/rivet/trunk/ (props changed)
tcl/rivet/trunk/ChangeLog
tcl/rivet/trunk/TODO
tcl/rivet/trunk/VERSION
tcl/rivet/trunk/configure.ac
tcl/rivet/trunk/doc/xml/directives.xml
tcl/rivet/trunk/src/Makefile.am
tcl/rivet/trunk/src/apache-2/mod_rivet.c
tcl/rivet/trunk/src/apache-2/mod_rivet.h
Propchange: tcl/rivet/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jan 31 22:33:45 2011
@@ -1 +1,2 @@
/tcl/rivet/branches/2_0:939332-1027850
+/tcl/rivet/branches/master-interp:1062190-1065801
Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Mon Jan 31 22:33:45 2011
@@ -1,3 +1,14 @@
+2011-01-31 Massimo Manghi <mx...@apache.org>
+ * configure.ac: default value for directive SeparateVirtualInterps changed to 'yes'.
+ * VERSION: version number set as 2.1.0r1 ('r' is for 'revision')
+ * doc/xml/directives.xml: New directive ServerInitScript is documented.
+
+2011-01-23 Massimo Manghi <mx...@apache.org>
+ * src/apache-2/mod_rivet.[c|h]: Created new ServerInitScript configuration directive: it assigns
+ rivet_server_init_script with a script run in Rivet_InitHandler after configuration has been built and
+ before server children are forked. A master interpreter is created in Rivet_InitHandler. Children
+ interpreters should hopefully be pure clones of this interpreter created by 'fork'
+
2011-01-09 Massimo Manghi <mx...@apache.org>
* configure.ac: fixed AC_DEFINE_UNQUOTED macro call for definition of proprocessor symbol RIVET_MAX_POST,
an integer valued symbol which was put in quotation marks. File indentation was fixed and tabs replaced with spaces
Modified: tcl/rivet/trunk/TODO
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/TODO?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/TODO (original)
+++ tcl/rivet/trunk/TODO Mon Jan 31 22:33:45 2011
@@ -1,3 +1,4 @@
+
BUGS
====
Modified: tcl/rivet/trunk/VERSION
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/VERSION?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/VERSION (original)
+++ tcl/rivet/trunk/VERSION Mon Jan 31 22:33:45 2011
@@ -1 +1 @@
-2.0.2
+2.1.0r1
Modified: tcl/rivet/trunk/configure.ac
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/configure.ac?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/configure.ac (original)
+++ tcl/rivet/trunk/configure.ac Mon Jan 31 22:33:45 2011
@@ -22,7 +22,7 @@ dnl
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------
-AC_INIT([Rivet],[2.0.3])
+AC_INIT([Rivet],[2.1.0r1])
TEA_INIT([3.9])
AC_CONFIG_AUX_DIR(tclconfig)
@@ -513,7 +513,7 @@ AC_DEFUN([VIRTUAL_INTERPS_SEPARATION],[
virtual-interps-separation,
[ --enable-virtual-interps-separation to turn on virtual host separation],
[ separate_virtual_interps=$enable_virtual_interps_separation ],
- [ separate_virtual_interps="no"]
+ [ separate_virtual_interps="yes"]
)
AC_MSG_CHECKING(whether Rivet will crate an interpreter for each virtual host)
Modified: tcl/rivet/trunk/doc/xml/directives.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/directives.xml?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/directives.xml (original)
+++ tcl/rivet/trunk/doc/xml/directives.xml Mon Jan 31 22:33:45 2011
@@ -9,6 +9,19 @@
<command>RivetServerConf</command>, meaning that DirConf will
override UserConf, which will in turn override ServerConf.
</para>
+ <para>
+ The directive <command>ServerInitScript</command> plays a special
+ role since the script runs within the master interpreter,
+ an interpreter created before the Apache parent process spawns
+ the children that actually will serve the requests coming from
+ the network. During this
+ stage Apache is still running as a single process, so this
+ is the right place for doing initialization of anything that
+ might work as an IPC infrastructure. Moreover everything
+ created and initialized in this stage will be handed on to the
+ interpreters run by the child processes, as they are
+ created by copying the memory of the parent process.
+ </para>
<variablelist>
<varlistentry>
@@ -17,6 +30,7 @@
<command>RivetServerConf</command>
<group choice="req">
<arg>CacheSize</arg>
+ <arg>ServerInitScript</arg>
<arg>GlobalInitScript</arg>
<arg>ChildInitScript</arg>
<arg>ChildExitScript</arg>
@@ -42,122 +56,145 @@
<variablelist>
<varlistentry>
<term>
- <cmdsynopsis>
- <arg choice="plain">CacheSize</arg>
- <arg><replaceable>size</replaceable></arg>
- </cmdsynopsis>
- </term>
- <listitem>
- <para>
- Sets the size of the internal page cache, where
- <option><replaceable>size</replaceable></option> is
- the number of byte-compiled pages to be cached for
- future use. Default is
- <command>MaxRequestsPerChild</command> / 5, or 50,
- if <command>MaxRequestsPerChild</command> is 0.
- </para>
- <para>
- This option is completely global, even when using
- separate, per-virtual host interpreters.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>
- <cmdsynopsis>
- <arg choice="plain">GlobalInitScript</arg>
- <arg><replaceable>script</replaceable></arg>
- </cmdsynopsis>
- </term>
- <listitem>
- <para>
- Tcl script that is run when each interpreter is
- initialized. <replaceable><option>script</option></replaceable>
- is an actual Tcl script, so to run a file, you would
- do:
-
- <programlisting>RivetServerConf GlobalInitScript "source /var/www/foobar.tcl"</programlisting>
- </para>
- <para>
- This option is ignored in virtual hosts.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>
- <cmdsynopsis>
- <arg choice="plain">ChildInitScript</arg>
- <arg><replaceable>script</replaceable></arg>
- </cmdsynopsis>
- </term>
- <listitem>
- <para>
- Script to be evaluated when each Apache child
- process is initialized. This is the recommended
- place to load modules, create global variables, open
- connections to other facilities (such as databases)
- and so on.
- </para>
- <para>
- In virtual hosts, this script is run in addition to
- any global childinitscript.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>
- <cmdsynopsis>
- <arg choice="plain">ChildExitScript</arg>
- <arg><replaceable>script</replaceable></arg>
- </cmdsynopsis>
- </term>
- <listitem>
- <para>
- Script to be evaluated when each Apache child
- process exits. This is the logical place to clean
- up resources created in
- <option>ChildInitScript</option>, if necessary.
- </para>
- <para>
- In virtual hosts, this script is run in addition to
- any global childexitscript.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term>
- <cmdsynopsis>
- <arg choice="plain">BeforeScript</arg>
- <arg><replaceable>script</replaceable></arg>
- </cmdsynopsis>
- </term>
- <listitem>
- <para>
- Script to be evaluated before each server parsed
- (.rvt) page. This can be used to create a standard
- header, for instance. It could also be used to load
- code that you need for every page, if you don't want
- to put it in a <option>GlobalInitScript</option>
- <option>ChildInitScript</option> when you are first
- developing a web site.
- <note>
- This code is evaluated at the global level, not
- inside the request namespace where pages are
- evaluated.
- </note>
- </para>
- <para>
- In virtual hosts, this option takes precedence over
- the global setting.
- </para>
- </listitem>
- </varlistentry>
+ <cmdsynopsis>
+ <arg choice="plain">CacheSize</arg>
+ <arg><replaceable>size</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Sets the size of the internal page cache, where
+ <option><replaceable>size</replaceable></option> is
+ the number of byte-compiled pages to be cached for
+ future use. Default is
+ <command>MaxRequestsPerChild</command> / 5, or 50,
+ if <command>MaxRequestsPerChild</command> is 0.
+ </para>
+ <para>
+ This option is completely global, even when using
+ separate, per-virtual host interpreters.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ <cmdsynopsis>
+ <arg choice="plain">ServerInitScript</arg>
+ <arg><replaceable>script</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Tcl script which is to run when the master interpreter is created.
+ Namespaces, variables and packages loaded during this stage will
+ be copied later on in the startup process, when child
+ processes are created. In general any sort of I/O channel
+ that is opened during this stage must be closed before the
+ execution of the script completes.
+ </para>
+ <para>
+ This option is only available at the global level
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ <cmdsynopsis>
+ <arg choice="plain">GlobalInitScript</arg>
+ <arg><replaceable>script</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Tcl script that is run as part of a child process initialization.
+ If the option <option>SeparateVirtualInterp</option> is not used this is
+ the right place where file handles, database connections or sockets can
+ be opened.
+ The argument <replaceable><option>script</option></replaceable>
+ is an actual Tcl script, so to run a file, you would
+ do:
+
+ <programlisting>RivetServerConf GlobalInitScript "source /var/www/foobar.tcl"</programlisting>
+ </para>
+ <para>
+ This option is ignored in virtual hosts.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <cmdsynopsis>
+ <arg choice="plain">ChildInitScript</arg>
+ <arg><replaceable>script</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Script to be evaluated when each Apache child
+ process is initialized. This is the recommended
+ place to load modules, create global variables, open
+ connections to other facilities (such as databases)
+ and so on.
+ </para>
+ <para>
+ In virtual hosts, this script is run in addition to
+ any global childinitscript.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <cmdsynopsis>
+ <arg choice="plain">ChildExitScript</arg>
+ <arg><replaceable>script</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Script to be evaluated when each Apache child
+ process exits. This is the logical place to clean
+ up resources created in <option>ChildInitScript</option>,
+ if necessary.
+ </para>
+ <para>
+ In virtual hosts, this script is run in addition to
+ any global childexitscript.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <cmdsynopsis>
+ <arg choice="plain">BeforeScript</arg>
+ <arg><replaceable>script</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Script to be evaluated before each server parsed
+ (.rvt) page. This can be used to create a standard
+ header, for instance. It could also be used to load
+ code that you need for every page, if you don't want
+ to put it in a <option>GlobalInitScript</option>
+ <option>ChildInitScript</option> when you are first
+ developing a web site.
+ <note>
+ This code is evaluated at the global level, not
+ inside the request namespace where pages are
+ evaluated.
+ </note>
+ </para>
+ <para>
+ In virtual hosts, this option takes precedence over
+ the global setting.
+ </para>
+ </listitem>
+ </varlistentry>
- <varlistentry>
+ <varlistentry>
<term>
<cmdsynopsis>
<arg choice="plain">AfterScript</arg>
Modified: tcl/rivet/trunk/src/Makefile.am
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/Makefile.am?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/src/Makefile.am (original)
+++ tcl/rivet/trunk/src/Makefile.am Mon Jan 31 22:33:45 2011
@@ -16,7 +16,6 @@
# AM_CFLAGS = @TCL_INCLUDES@ @GM_CPPFLAGS@
-
# The weird and wild magic of auto* associates these two.
##apxs_libexecdir = @APXS_LIBEXECDIR@
##apxs_libexec_LTLIBRARIES = mod_rivet.la
@@ -25,6 +24,7 @@ INCLUDES = -I@apache_include@
# ... and these two. We want to put the libs in the package path,
# rather than the standard library location for the system.
+
lib_libexecdir = @RIVET_TCL_TARGET@
lib_libexec_LTLIBRARIES = librivet.la librivetparser.la
Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.c?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.c Mon Jan 31 22:33:45 2011
@@ -6,7 +6,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -59,11 +59,11 @@
/* This is used *only* in the PanicProc. Otherwise, don't touch it! */
static request_rec *rivet_panic_request_rec = NULL;
-static apr_pool_t *rivet_panic_pool = NULL;
+static apr_pool_t *rivet_panic_pool = NULL;
static server_rec *rivet_panic_server_rec = NULL;
/* Need some arbitrary non-NULL pointer which can't also be a request_rec */
-#define NESTED_INCLUDE_MAGIC (&rivet_module)
+#define NESTED_INCLUDE_MAGIC (&rivet_module)
#define DEBUG(s) fprintf(stderr, s), fflush(stderr)
/* rivet or tcl file */
@@ -77,8 +77,12 @@ static server_rec *rivet_panic_server_
TCL_DECLARE_MUTEX(sendMutex);
-#define RIVET_FILE_CTYPE "application/x-httpd-rivet"
-#define TCL_FILE_CTYPE "application/x-rivet-tcl"
+#define RIVET_FILE_CTYPE "application/x-httpd-rivet"
+#define TCL_FILE_CTYPE "application/x-rivet-tcl"
+
+static Tcl_Interp* Rivet_CreateTclInterp (server_rec* s);
+static void Rivet_CreateCache (server_rec *s, apr_pool_t *p);
+
/* This snippet of code came from the mod_ruby project, which is under a BSD license. */
@@ -122,7 +126,7 @@ Rivet_UploadHook(void *ptr, char *buf, i
static int
Rivet_CheckType (request_rec *req)
{
- int ctype = CTYPE_NOT_HANDLED;
+ int ctype = CTYPE_NOT_HANDLED;
if ( req->content_type != NULL ) {
if( STRNEQU( req->content_type, RIVET_FILE_CTYPE) ) {
@@ -158,17 +162,17 @@ Rivet_ParseFileArgString (const char *sz
* Append it to the document root, if this is not NULL.
*/
- while (*argsPtr != '?' && *argsPtr != '\0') {
- argsPtr++;
- }
- if (*argsPtr == '?')
- argslen = argsPtr-szArgs ;
- else
- argslen = 0;
- flen += strlen(szDocRoot) + argslen ;
- *file = (char*)apr_palloc(p,flen);
- strcat(*file,szDocRoot);
- strncat(*file,szArgs,argslen);
+ while (*argsPtr != '?' && *argsPtr != '\0') {
+ argsPtr++;
+ }
+ if (*argsPtr == '?')
+ argslen = argsPtr-szArgs ;
+ else
+ argslen = 0;
+ flen += strlen(szDocRoot) + argslen ;
+ *file = (char*)apr_palloc(p,flen);
+ strcat(*file,szDocRoot);
+ strncat(*file,szArgs,argslen);
if (argTbl == NULL)
return RIVET_OK;
@@ -427,7 +431,7 @@ Rivet_ParseExecFile(TclWebRequest *req,
rsc->objCacheList[ct]);
if (delEntry != NULL) {
Tcl_DecrRefCount((Tcl_Obj *)Tcl_GetHashValue(delEntry));
- }
+ }
Tcl_DeleteHashEntry(delEntry);
free(rsc->objCacheList[ct]);
@@ -607,13 +611,13 @@ Rivet_CleanupRequest( request_rec *r )
*
* Rivet_CopyConfig --
*
- * Copy the rivet_server_conf struct.
+ * Copy the rivet_server_conf struct.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * None.
+ * None.
*
*-----------------------------------------------------------------------------
*/
@@ -624,7 +628,6 @@ Rivet_CopyConfig( rivet_server_conf *old
newrsc->server_interp = oldrsc->server_interp;
newrsc->rivet_global_init_script = oldrsc->rivet_global_init_script;
-
newrsc->rivet_before_script = oldrsc->rivet_before_script;
newrsc->rivet_after_script = oldrsc->rivet_after_script;
newrsc->rivet_error_script = oldrsc->rivet_error_script;
@@ -659,7 +662,7 @@ Rivet_CopyConfig( rivet_server_conf *old
static void
Rivet_MergeDirConfigVars(apr_pool_t *p, rivet_server_conf *new,
- rivet_server_conf *base, rivet_server_conf *add )
+ rivet_server_conf *base, rivet_server_conf *add )
{
FILEDEBUGINFO;
@@ -723,16 +726,17 @@ Rivet_CreateConfig(apr_pool_t *p, server
FILEDEBUGINFO;
- rsc->server_interp = NULL;
+ rsc->server_interp = NULL;
/* scripts obj pointers *must* be initialized to NULL */
+ rsc->rivet_server_init_script = NULL;
rsc->rivet_global_init_script = NULL;
rsc->rivet_child_init_script = NULL;
rsc->rivet_child_exit_script = NULL;
- rsc->rivet_before_script = NULL;
- rsc->rivet_after_script = NULL;
- rsc->rivet_error_script = NULL;
+ rsc->rivet_before_script = NULL;
+ rsc->rivet_after_script = NULL;
+ rsc->rivet_error_script = NULL;
rsc->user_scripts_updated = 0;
@@ -742,18 +746,18 @@ Rivet_CreateConfig(apr_pool_t *p, server
/* these are pointers so that they can be passed around... */
rsc->cache_size = apr_pcalloc(p, sizeof(int));
rsc->cache_free = apr_pcalloc(p, sizeof(int));
- *(rsc->cache_size) = -1;
- *(rsc->cache_free) = 0;
- rsc->upload_max = RIVET_MAX_POST;
- rsc->upload_files_to_var = RIVET_UPLOAD_FILES_TO_VAR;
- rsc->separate_virtual_interps = RIVET_SEPARATE_VIRTUAL_INTERPS;
- rsc->honor_header_only_reqs = RIVET_HEAD_REQUESTS;
- rsc->upload_dir = RIVET_UPLOAD_DIR;
- rsc->server_name = NULL;
- rsc->objCacheList = NULL;
- rsc->objCache = NULL;
+ *(rsc->cache_size) = -1;
+ *(rsc->cache_free) = 0;
+ rsc->upload_max = RIVET_MAX_POST;
+ rsc->upload_files_to_var = RIVET_UPLOAD_FILES_TO_VAR;
+ rsc->separate_virtual_interps = RIVET_SEPARATE_VIRTUAL_INTERPS;
+ rsc->honor_header_only_reqs = RIVET_HEAD_REQUESTS;
+ rsc->upload_dir = RIVET_UPLOAD_DIR;
+ rsc->server_name = NULL;
+ rsc->objCacheList = NULL;
+ rsc->objCache = NULL;
- rsc->outchannel = NULL;
+ rsc->outchannel = NULL;
rsc->rivet_server_vars = (apr_table_t *) apr_table_make ( p, 4 );
rsc->rivet_dir_vars = (apr_table_t *) apr_table_make ( p, 4 );
@@ -825,14 +829,14 @@ Rivet_PropagatePerDirConfArrays( Tcl_Int
*
* Rivet_PerInterpInit --
*
- * Do the initialization that needs to happen for every
- * interpreter.
+ * Do the initialization that needs to happen for every
+ * interpreter.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * None.
+ * None.
*
*-----------------------------------------------------------------------------
*/
@@ -877,7 +881,7 @@ Rivet_PerInterpInit(server_rec *s, rivet
if (Tcl_ListObjReplace(interp,auto_path,0,0,1,&rivet_tcl) == TCL_ERROR)
{
ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
- "error setting auto_path: %s",Tcl_GetStringFromObj(auto_path,NULL));
+ "error setting auto_path: %s",Tcl_GetStringFromObj(auto_path,NULL));
}
Tcl_DecrRefCount(rivet_tcl);
@@ -893,7 +897,7 @@ Rivet_PerInterpInit(server_rec *s, rivet
* won't send any result packets to the browser unless the Rivet
* programmer does a "flush stdout" or the page is completed.
*/
- // Tcl_SetChannelOption(interp, *(rsc->outchannel), "-buffersize", "1000000");
+// Tcl_SetChannelOption(interp, *(rsc->outchannel), "-buffersize", "1000000");
Tcl_SetChannelBufferSize (*(rsc->outchannel), 1000000);
Tcl_RegisterChannel(interp, *(rsc->outchannel));
Tcl_Release(interp);
@@ -904,18 +908,18 @@ Rivet_PerInterpInit(server_rec *s, rivet
*
* Rivet_AssignStringtoConf --
*
- * Assign a string to a Tcl_Obj valued configuration parameter
+ * Assign a string to a Tcl_Obj valued configuration parameter
*
* Arguments:
*
- * - objPnt: Pointer to a pointer to a Tcl_Obj. If the pointer *objPnt
- * is NULL (configuration script obj pointers are initialized to NULL)
+ * - objPnt: Pointer to a pointer to a Tcl_Obj. If the pointer *objPnt
+ * is NULL (configuration script obj pointers are initialized to NULL)
* a new Tcl_Obj is created
- * - string_value: a string to be assigned to the Tcl_Obj
+ * - string_value: a string to be assigned to the Tcl_Obj
*
* Results:
- *
- * - Pointer to a Tcl_Obj containing the parameter value.
+ *
+ * - Pointer to a Tcl_Obj containing the parameter value.
*
*----------------------------------------------------------------------
*/
@@ -943,16 +947,16 @@ Rivet_AssignStringToConf (Tcl_Obj** objP
*
* Rivet_SetScript --
*
- * Add the text from an apache directive, such as UserConf, to
- * the corresponding variable in the rivet_server_conf structure.
- * In most cases, we append the new value to any previously
- * existing value, but Before, After and Error scripts override
- * the old directive completely.
+ * Add the text from an apache directive, such as UserConf, to
+ * the corresponding variable in the rivet_server_conf structure.
+ * In most cases, we append the new value to any previously
+ * existing value, but Before, After and Error scripts override
+ * the old directive completely.
*
* Results:
*
- * Returns a Tcl_Obj* pointing to the string representation of
- * the current value for the directive.
+ * Returns a Tcl_Obj* pointing to the string representation of
+ * the current value for the directive.
*
*----------------------------------------------------------------------
*/
@@ -967,15 +971,17 @@ Rivet_SetScript (apr_pool_t *pool, rivet
if( STREQU( script, "GlobalInitScript" ) ) {
objarg = Rivet_AssignStringToConf(&(rsc->rivet_global_init_script),string);
} else if( STREQU( script, "ChildInitScript" ) ) {
- objarg = Rivet_AssignStringToConf(&(rsc->rivet_child_init_script),string);
+ objarg = Rivet_AssignStringToConf(&(rsc->rivet_child_init_script),string);
} else if( STREQU( script, "ChildExitScript" ) ) {
objarg = Rivet_AssignStringToConf(&(rsc->rivet_child_exit_script),string);
} else if( STREQU( script, "BeforeScript" ) ) {
- objarg = Rivet_AssignStringToConf(&(rsc->rivet_before_script),string);
+ objarg = Rivet_AssignStringToConf(&(rsc->rivet_before_script),string);
} else if( STREQU( script, "AfterScript" ) ) {
- objarg = Rivet_AssignStringToConf(&(rsc->rivet_after_script),string);
+ objarg = Rivet_AssignStringToConf(&(rsc->rivet_after_script),string);
} else if( STREQU( script, "ErrorScript" ) ) {
- objarg = Rivet_AssignStringToConf(&(rsc->rivet_error_script),string);
+ objarg = Rivet_AssignStringToConf(&(rsc->rivet_error_script),string);
+ } else if( STREQU( script, "ServerInitScript" ) ) {
+ objarg = Rivet_AssignStringToConf(&(rsc->rivet_server_init_script),string);
}
if( !objarg ) return string;
@@ -987,18 +993,18 @@ Rivet_SetScript (apr_pool_t *pool, rivet
* Implements the RivetServerConf Apache Directive
*
* Command Arguments:
- * RivetServerConf GlobalInitScript <script>
- * RivetServerConf ChildInitScript <script>
- * RivetServerConf ChildExitScript <script>
- * RivetServerConf BeforeScript <script>
- * RivetServerConf AfterScript <script>
- * RivetServerConf ErrorScript <script>
- * RivetServerConf CacheSize <integer>
- * RivetServerConf UploadDirectory <directory>
- * RivetServerConf UploadMaxSize <integer>
- * RivetServerConf UploadFilesToVar <yes|no>
- * RivetServerConf SeparateVirtualInterps <yes|no>
- * RivetServerConf HonorHeaderOnlyRequests <yes|no> (2008-06-20: mm)
+ * RivetServerConf GlobalInitScript <script>
+ * RivetServerConf ChildInitScript <script>
+ * RivetServerConf ChildExitScript <script>
+ * RivetServerConf BeforeScript <script>
+ * RivetServerConf AfterScript <script>
+ * RivetServerConf ErrorScript <script>
+ * RivetServerConf CacheSize <integer>
+ * RivetServerConf UploadDirectory <directory>
+ * RivetServerConf UploadMaxSize <integer>
+ * RivetServerConf UploadFilesToVar <yes|no>
+ * RivetServerConf SeparateVirtualInterps <yes|no>
+ * RivetServerConf HonorHeaderOnlyRequests <yes|no> (2008-06-20: mm)
*/
static const char *
@@ -1039,10 +1045,10 @@ Rivet_ServerConf( cmd_parms *cmd, void *
* Implements the RivetDirConf Apache Directive
*
* Command Arguments:
- * RivetDirConf BeforeScript <script>
- * RivetDirConf AfterScript <script>
- * RivetDirConf ErrorScript <script>
- * RivetDirConf UploadDirectory <directory>
+ * RivetDirConf BeforeScript <script>
+ * RivetDirConf AfterScript <script>
+ * RivetDirConf ErrorScript <script>
+ * RivetDirConf UploadDirectory <directory>
*/
static const char *
@@ -1072,15 +1078,15 @@ Rivet_DirConf( cmd_parms *cmd, void *vrd
* Implements the RivetUserConf Apache Directive
*
* Command Arguments:
- * RivetUserConf BeforeScript <script>
- * RivetUserConf AfterScript <script>
- * RivetUserConf ErrorScript <script>
+ * RivetUserConf BeforeScript <script>
+ * RivetUserConf AfterScript <script>
+ * RivetUserConf ErrorScript <script>
*/
static const char *
Rivet_UserConf( cmd_parms *cmd, void *vrdc,
const char *var,
- const char *val )
+ const char *val )
{
const char *string = val;
rivet_server_conf *rdc = (rivet_server_conf *)vrdc;
@@ -1106,6 +1112,7 @@ static int
Rivet_InitHandler(apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp,
server_rec *s)
{
+ rivet_server_conf *rsc = RIVET_SERVER_CONF( s->module_config );
rivet_panic_pool = pPool;
rivet_panic_server_rec = s;
@@ -1114,6 +1121,32 @@ Rivet_InitHandler(apr_pool_t *pPool, apr
#else
ap_add_version_component(pPool, RIVET_PACKAGE_NAME);
#endif
+
+ FILEDEBUGINFO;
+
+ rsc->server_interp = Rivet_CreateTclInterp(s) ; /* root interpreter */
+
+ Rivet_PerInterpInit(s, rsc, pPool);
+ Rivet_CreateCache(s,pPool);
+
+ /* we create and initialize a master (server) interpreter
+ * Rivet_InitTclStuff(s,pPool);
+ */
+
+ if (rsc->rivet_server_init_script != NULL) {
+ Tcl_Interp* interp = rsc->server_interp;
+
+ if (Tcl_EvalObjEx(interp, rsc->rivet_server_init_script, 0) != TCL_OK)
+ {
+ ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, "%s",
+ Tcl_GetVar(interp, "errorInfo", 0));
+ } else {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_EGENERAL, s,
+ "RivetServerInit has run");
+ }
+
+ }
+
return OK;
}
@@ -1151,18 +1184,18 @@ Rivet_MergeDirConfig( apr_pool_t *p, voi
*
* Rivet_MergeConfig --
*
- * This function is called when there is a config option set both
- * at the 'global' level, and for a virtual host. It "resolves
- * the conflicts" so to speak, by creating a new configuration,
- * and this function is where we get to have our say about how to
- * go about doing that. For most of the options, we override the
- * global option with the local one.
+ * This function is called when there is a config option set both
+ * at the 'global' level, and for a virtual host. It "resolves
+ * the conflicts" so to speak, by creating a new configuration,
+ * and this function is where we get to have our say about how to
+ * go about doing that. For most of the options, we override the
+ * global option with the local one.
*
* Results:
- * Returns a new server configuration.
+ * Returns a new server configuration.
*
* Side Effects:
- * None.
+ * None.
*
*-----------------------------------------------------------------------------
*/
@@ -1234,15 +1267,15 @@ Rivet_MergeConfig(apr_pool_t *p, void *b
*
* Rivet_PanicProc --
*
- * Called when Tcl panics, usually because of memory problems.
- * We log the request, in order to be able to determine what went
- * wrong later.
+ * Called when Tcl panics, usually because of memory problems.
+ * We log the request, in order to be able to determine what went
+ * wrong later.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * Calls abort(), which does not return - the child exits.
+ * Calls abort(), which does not return - the child exits.
*
*-----------------------------------------------------------------------------
*/
@@ -1257,14 +1290,14 @@ Rivet_Panic TCL_VARARGS_DEF(CONST char *
buf = (char *) apr_pvsprintf(rivet_panic_pool, format, argList);
if (rivet_panic_request_rec != NULL) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL,
- rivet_panic_server_rec,
- "Critical error in request: %s",
- rivet_panic_request_rec->unparsed_uri);
+ ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL,
+ rivet_panic_server_rec,
+ "Critical error in request: %s",
+ rivet_panic_request_rec->unparsed_uri);
}
ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL,
- rivet_panic_server_rec, buf);
+ rivet_panic_server_rec, buf);
abort();
}
@@ -1275,14 +1308,14 @@ Rivet_Panic TCL_VARARGS_DEF(CONST char *
*
* Rivet_ChildHandlers --
*
- * Handles, depending on the situation, the scripts for the init
- * and exit handlers.
+ * Handles, depending on the situation, the scripts for the init
+ * and exit handlers.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * Runs the rivet_child_init/exit_script scripts.
+ * Runs the rivet_child_init/exit_script scripts.
*
*-----------------------------------------------------------------------------
*/
@@ -1313,9 +1346,9 @@ Rivet_ChildHandlers(server_rec *s, int i
function = init ? rsc->rivet_child_init_script :
rsc->rivet_child_exit_script;
- if (!init && sr == s) {
- Tcl_Preserve(rsc->server_interp);
- }
+ if (!init && sr == s) {
+ Tcl_Preserve(rsc->server_interp);
+ }
/* Execute it if it exists and it's the top level, separate
* virtual interps are turned on, or it's different than the
@@ -1324,35 +1357,35 @@ Rivet_ChildHandlers(server_rec *s, int i
( sr == s || rsc->separate_virtual_interps ||
function != parentfunction))
{
- Tcl_Preserve (rsc->server_interp);
+ Tcl_Preserve (rsc->server_interp);
if (Tcl_EvalObjEx(rsc->server_interp,function, 0) != TCL_OK) {
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
errmsg, Tcl_GetString(function));
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
- "errorCode: %s",
+ "errorCode: %s",
Tcl_GetVar(rsc->server_interp, "errorCode", 0));
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
- "errorInfo: %s",
+ "errorInfo: %s",
Tcl_GetVar(rsc->server_interp, "errorInfo", 0));
}
- Tcl_Release (rsc->server_interp);
+ Tcl_Release (rsc->server_interp);
}
}
if (!init) {
- /*
- * Upon child exit we delete the master interpreter before the
- * caller invokes Tcl_Finalize. Even if we're running separate
- * virtual interpreters, we don't delete the slaves
- * as deleting the master implicitly deletes its slave interpreters.
- */
-
- rsc = RIVET_SERVER_CONF(s->module_config);
- if (!Tcl_InterpDeleted (rsc->server_interp)) {
- Tcl_DeleteInterp(rsc->server_interp);
- }
- Tcl_Release (rsc->server_interp);
+ /*
+ * Upon child exit we delete the master interpreter before the
+ * caller invokes Tcl_Finalize. Even if we're running separate
+ * virtual interpreters, we don't delete the slaves
+ * as deleting the master implicitly deletes its slave interpreters.
+ */
+
+ rsc = RIVET_SERVER_CONF(s->module_config);
+ if (!Tcl_InterpDeleted (rsc->server_interp)) {
+ Tcl_DeleteInterp(rsc->server_interp);
+ }
+ Tcl_Release (rsc->server_interp);
}
}
/*
@@ -1360,13 +1393,13 @@ Rivet_ChildHandlers(server_rec *s, int i
*
* Rivet_ChildExit --
*
- * Run when each Apache child process is about to exit.
+ * Run when each Apache child process is about to exit.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * Runs Tcl_Finalize.
+ * Runs Tcl_Finalize.
*
*-----------------------------------------------------------------------------
*/
@@ -1382,30 +1415,20 @@ Rivet_ChildExit(void *data)
/*
*-----------------------------------------------------------------------------
+ * Rivet_CreateTclInterp --
*
- * Rivet_InitTclStuff --
- *
- * Initialize the Tcl system - create interpreters, load commands
- * and so forth.
- *
+ * Arguments:
+ * server_rec* s: pointer to a server_rec structure
* Results:
- * None.
- *
+ * pointer to a Tcl_Interp structure
* Side Effects:
- * None.
*
*-----------------------------------------------------------------------------
*/
-
-static void
-Rivet_InitTclStuff(server_rec *s, apr_pool_t *p)
+static Tcl_Interp*
+Rivet_CreateTclInterp (server_rec* s)
{
- Tcl_Interp *interp;
- rivet_server_conf *rsc = RIVET_SERVER_CONF( s->module_config );
- rivet_server_conf *myrsc;
- server_rec *sr;
- extern int ap_max_requests_per_child;
- int interpCount = 0;
+ Tcl_Interp* interp = Tcl_CreateInterp();
/* Initialize TCL stuff */
Tcl_FindExecutable(RIVET_NAMEOFEXECUTABLE);
@@ -1423,12 +1446,31 @@ Rivet_InitTclStuff(server_rec *s, apr_po
Tcl_GetStringResult(interp));
exit(1);
}
-
Tcl_SetPanicProc(Rivet_Panic);
- rsc->server_interp = interp; /* root interpreter */
+ return interp;
+}
- Rivet_PerInterpInit(s, rsc, p);
+/*
+ *-----------------------------------------------------------------------------
+ * Rivet_CreateCache --
+ *
+ * Arguments:
+ * rsc: pointer to a server_rec structure
+ *
+ * Results:
+ * None
+ *
+ * Side Effects:
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static void
+Rivet_CreateCache (server_rec *s, apr_pool_t *p)
+{
+ extern int ap_max_requests_per_child;
+ rivet_server_conf *rsc = RIVET_SERVER_CONF( s->module_config );
/* If the user didn't set a cache size in their configuration, we
* will assume an arbitrary size for them.
@@ -1441,7 +1483,7 @@ Rivet_InitTclStuff(server_rec *s, apr_po
if (ap_max_requests_per_child != 0) {
*(rsc->cache_size) = ap_max_requests_per_child / 5;
} else {
- *(rsc->cache_size) = 50; /* FIXME: Arbitrary number */
+ *(rsc->cache_size) = 50; // Arbitrary number
}
}
@@ -1449,19 +1491,49 @@ Rivet_InitTclStuff(server_rec *s, apr_po
*(rsc->cache_free) = *(rsc->cache_size);
}
- /* Initialize cache structures */
+ // Initialize cache structures
+
if (*(rsc->cache_size)) {
rsc->objCacheList = apr_pcalloc(
p, (signed)(*(rsc->cache_size) * sizeof(char *)));
rsc->objCache = apr_pcalloc(p, sizeof(Tcl_HashTable));
Tcl_InitHashTable(rsc->objCache, TCL_STRING_KEYS);
}
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Rivet_InitTclStuff --
+ *
+ * Initialize the Tcl system - create interpreters, load commands
+ * and so forth.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static void
+Rivet_InitTclStuff(server_rec *s, apr_pool_t *p)
+{
+ rivet_server_conf *rsc = RIVET_SERVER_CONF( s->module_config );
+ Tcl_Interp *interp = rsc->server_interp;
+ rivet_server_conf *myrsc;
+ server_rec *sr;
+ extern int ap_max_requests_per_child;
+ int interpCount = 0;
if (rsc->rivet_global_init_script != NULL) {
if (Tcl_EvalObjEx(interp, rsc->rivet_global_init_script, 0) != TCL_OK)
{
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, "%s",
- Tcl_GetVar(interp, "errorInfo", 0));
+ Tcl_GetVar(interp, "errorInfo", 0));
}
}
@@ -1484,19 +1556,19 @@ Rivet_InitTclStuff(server_rec *s, apr_po
if (sr != s) /* not the first one */
{
if (rsc->separate_virtual_interps != 0) {
- char *slavename = (char*) apr_psprintf(p, "%s_%d_%d",
+ char *slavename = (char*) apr_psprintf (p, "%s_%d_%d",
sr->server_hostname,
sr->port,
- interpCount++);
+ interpCount++);
/* Separate virtual interps. */
myrsc->server_interp = Tcl_CreateSlave(interp, slavename, 0);
- if (myrsc->server_interp == NULL) {
- ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
- "slave interp create failed: %s",
- Tcl_GetStringResult(interp) );
- exit(1);
- }
+ if (myrsc->server_interp == NULL) {
+ ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
+ "slave interp create failed: %s",
+ Tcl_GetStringResult(interp) );
+ exit(1);
+ }
Rivet_PerInterpInit(s, myrsc, p);
} else {
myrsc->server_interp = rsc->server_interp;
@@ -1518,14 +1590,14 @@ Rivet_InitTclStuff(server_rec *s, apr_po
*
* Rivet_ChildInit --
*
- * This function is run when each individual Apache child process
- * is created.
+ * This function is run when each individual Apache child process
+ * is created.
*
* Results:
- * None.
+ * None.
*
* Side Effects:
- * Calls Tcl initialization function.
+ * Calls Tcl initialization function.
*
*-----------------------------------------------------------------------------
*/
@@ -1546,19 +1618,17 @@ Rivet_ChildInit(apr_pool_t *pChild, serv
static int
Rivet_SendContent(request_rec *r)
{
-// char error[MAX_STRING_LEN];
-// char timefmt[MAX_STRING_LEN];
int errstatus;
int retval;
int ctype;
- Tcl_Interp *interp;
- static Tcl_Obj *request_init = NULL;
- static Tcl_Obj *request_cleanup = NULL;
+ Tcl_Interp *interp;
+ static Tcl_Obj *request_init = NULL;
+ static Tcl_Obj *request_cleanup = NULL;
rivet_interp_globals *globals = NULL;
- rivet_server_conf *rsc = NULL;
- rivet_server_conf *rdc;
+ rivet_server_conf *rsc = NULL;
+ rivet_server_conf *rdc;
ctype = Rivet_CheckType(r);
if (ctype == CTYPE_NOT_HANDLED) {
@@ -1705,25 +1775,25 @@ Rivet_SendContent(request_rec *r)
*/
{
- int content_type_len = strlen(r->content_type);
+ int content_type_len = strlen(r->content_type);
+
+ if (((ctype==RIVET_FILE) && (content_type_len > strlen(RIVET_FILE_CTYPE))) || \
+ ((ctype==TCL_FILE) && (content_type_len > strlen(TCL_FILE_CTYPE)))) {
+
+ char* charset;
- if (((ctype==RIVET_FILE) && (content_type_len > strlen(RIVET_FILE_CTYPE))) || \
- ((ctype==TCL_FILE) && (content_type_len > strlen(TCL_FILE_CTYPE)))) {
-
- char* charset;
-
- /* we parse the content type: we are after a 'charset' parameter definition */
-
- charset = strstr(r->content_type,"charset");
- if (charset != NULL) {
- charset = apr_pstrdup(r->pool,charset);
-
- /* ther's some freedom about spaces in the AddType lines: let's strip them off */
-
- apr_collapse_spaces(charset,charset);
- globals->req->charset = charset;
- }
- }
+ /* we parse the content type: we are after a 'charset' parameter definition */
+
+ charset = strstr(r->content_type,"charset");
+ if (charset != NULL) {
+ charset = apr_pstrdup(r->pool,charset);
+
+ /* ther's some freedom about spaces in the AddType lines: let's strip them off */
+
+ apr_collapse_spaces(charset,charset);
+ globals->req->charset = charset;
+ }
+ }
}
if (Rivet_ParseExecFile(globals->req, r->filename, 1) != TCL_OK)
Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.h?rev=1065838&r1=1065837&r2=1065838&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.h Mon Jan 31 22:33:45 2011
@@ -30,7 +30,7 @@
/* End Configuration options */
-/* For Tcl 8.3/8.4 compatibility - see http://mini.net/tcl/3669 */
+/* For Tcl 8.3/8.4 compatibility - see http://wiki.tcl.tk/3669 */
#ifndef CONST84
# define CONST84
#endif
@@ -52,6 +52,7 @@ module AP_MODULE_DECLARE_DATA rivet_modu
typedef struct _rivet_server_conf {
Tcl_Interp *server_interp; /* per server Tcl interpreter */
+ Tcl_Obj *rivet_server_init_script; /* run before children are forked */
Tcl_Obj *rivet_global_init_script; /* run once when apache is started */
Tcl_Obj *rivet_child_init_script;
Tcl_Obj *rivet_child_exit_script;
---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-cvs-help@tcl.apache.org