This is an automated email from the ASF dual-hosted git repository. mxmanghi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git
The following commit(s) were added to refs/heads/master by this push: new fcef274 Handling the server_rec pointer in the module globals for the benefit of logging into the specific virtual host log file during child init stage fcef274 is described below commit fcef27410232a604efca94e49f5421f42ce6cb74 Author: Massimo Manghi <mxman...@apache.org> AuthorDate: Thu May 18 17:12:24 2023 +0200 Handling the server_rec pointer in the module globals for the benefit of logging into the specific virtual host log file during child init stage --- ChangeLog | 12 ++++++-- src/mod_rivet_ng/mod_rivet.c | 14 +++++----- src/mod_rivet_ng/mod_rivet.h | 1 + src/mod_rivet_ng/mod_rivet_common.c | 8 +++--- src/mod_rivet_ng/rivetCore.c | 17 +++++++---- src/mod_rivet_ng/worker_prefork_common.c | 48 +++++++++++++++++--------------- 6 files changed, 60 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index c195c41..b6497c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ -2023-05-14 Massimo Manghi <mxman...@apache.org> +2023-05-18 Massimo Manghi <mxman...@apache.org> + * src/mod_rivet_ng/mod_rivet.c: + * src/mod_rivet_ng/mod_rivet.h: + * src/mod_rivet_ng/mod_rivet_common.c: + * src/mod_rivet_ng/rivetCore.c: + * src/mod_rivet_ng/worker_prefork_common.c: now storing the server record in the intepreter globals + to be used by Rivet_LogErrorCmd instead of module_globals->server when threads private data are + not available (like when ChildInitScript is executed) + +2023-05-04 Massimo Manghi <mxman...@apache.org> * tests/rivet.test: more contributions provided by Scott Pitcher <sco...@svptechnicalservices.com.au>) * tests/apachetest/apachetest.tcl: More improvements to the test script. Now handling also Apache directive IncludeOptional and enabling execution control @@ -6,7 +15,6 @@ * tests/post.rvt: * tests/post.test: add a test for ::rivet::raw_post - * 2023-04-11 Massimo Manghi <mxman...@apache.org> * src/mod_rivet_ng/TclWebapache.c: * src/mod_rivet_ng/rivetCore.c: diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c index 7b583ba..95ce2ae 100644 --- a/src/mod_rivet_ng/mod_rivet.c +++ b/src/mod_rivet_ng/mod_rivet.c @@ -238,7 +238,7 @@ static int Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s) { #ifdef WIN32 - char* parent_pid_var = NULL; + char* parent_pid_var = NULL; #endif FILEDEBUGINFO; @@ -262,8 +262,8 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser * (https://wiki.apache.org/httpd/ModuleLife) */ - #ifdef WIN32 - +#ifdef WIN32 + /* if the environment variable AP_PARENT_PID is set * we know we are in a child process of the winnt MPM */ @@ -278,8 +278,8 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser ap_log_perror(APLOG_MARK,APLOG_INFO,0,pPool, "AP_PARENT_PID undefined, we proceed with server initialization"); } - - #endif + +#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 @@ -449,9 +449,9 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server) Tcl_InitNotifier(); #endif - /* We can rely on the existence of module_globals only we are + /* We can rely on the existence of module_globals only when * running the prefork MPM, otherwise the pointer is NULL and - * the structure has to be filled with data + * the structure has to be allocated and filled with data */ if (module_globals == NULL) diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h index 68fa9f7..94d40fa 100644 --- a/src/mod_rivet_ng/mod_rivet.h +++ b/src/mod_rivet_ng/mod_rivet.h @@ -251,6 +251,7 @@ typedef struct _thread_worker_private { typedef struct _rivet_interp_globals { Tcl_Namespace* rivet_ns; /* Rivet commands namespace */ + server_rec* server; /* Virtual host server rec */ } rivet_interp_globals; rivet_server_conf *Rivet_GetConf(request_rec *r); diff --git a/src/mod_rivet_ng/mod_rivet_common.c b/src/mod_rivet_ng/mod_rivet_common.c index 56908d9..c11131b 100644 --- a/src/mod_rivet_ng/mod_rivet_common.c +++ b/src/mod_rivet_ng/mod_rivet_common.c @@ -220,7 +220,7 @@ void Rivet_ReleasePerDirScripts(rivet_thread_interp* rivet_interp) * * Rivet_PerInterpInit -- * - * Do the initialization that needs to happen to every interpreter. + * Do the interpreter environment creation and initialization. * * Results: * None. @@ -249,11 +249,11 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj, Tcl_SetAssocData (interp,"rivet",NULL,globals); /* - * the ::rivet namespace is the only information still stored - * in the interpreter global data + * we store in the globals some information relevant to + * the embedded interpreter work */ - /* Rivet commands namespace is created */ + /* the ::rivet namespace is created */ globals->rivet_ns = Tcl_CreateNamespace (interp,RIVET_NS,NULL, (Tcl_NamespaceDeleteProc *)NULL); diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c index ffa4381..b54c8c1 100644 --- a/src/mod_rivet_ng/rivetCore.c +++ b/src/mod_rivet_ng/rivetCore.c @@ -1766,7 +1766,7 @@ TCL_CMD_HEADER( Rivet_InspectCmd ) *----------------------------------------------------------------------------- */ -TCL_CMD_HEADER( Rivet_LogErrorCmd ) +TCL_CMD_HEADER(Rivet_LogErrorCmd) { char *message = NULL; @@ -1853,9 +1853,16 @@ TCL_CMD_HEADER( Rivet_LogErrorCmd ) * root server name stored in the module_globals */ - serverRec = ((private == NULL) || (private->r == NULL)) ? module_globals->server : private->r->server; - - ap_log_error (APLOG_MARK, apLogLevel, 0, serverRec, "%s", message); + if ((private == NULL) || (private->r == NULL)) + { + rivet_interp_globals* globals = Tcl_GetAssocData(interp, "rivet", NULL); + serverRec = globals->server; + } + else + { + serverRec = private->r->server; + } + ap_log_error (APLOG_MARK,apLogLevel,0,serverRec,"%s",message); return TCL_OK; } @@ -2159,7 +2166,7 @@ TCL_CMD_HEADER( Rivet_CacheContent ) DLLEXPORT int Rivet_InitCore(Tcl_Interp *interp,rivet_thread_private* private) { - rivet_server_conf* server_conf; + rivet_server_conf* server_conf; RIVET_OBJ_CMD ("makeurl",Rivet_MakeURL,private); RIVET_OBJ_CMD ("headers",Rivet_Headers,private); diff --git a/src/mod_rivet_ng/worker_prefork_common.c b/src/mod_rivet_ng/worker_prefork_common.c index a08f993..06ae464 100644 --- a/src/mod_rivet_ng/worker_prefork_common.c +++ b/src/mod_rivet_ng/worker_prefork_common.c @@ -72,7 +72,7 @@ Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj) /* -- Rivet_VirtualHostsInterps * - * The server_rec chain is walked through and server configurations is read to + * The server_rec chain is walked through and server configurations are read to * set up the thread private configuration and interpreters database * * Arguments: @@ -91,7 +91,7 @@ Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj) rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) { - server_rec* s; + server_rec* vhost_server; server_rec* root_server = module_globals->server; rivet_server_conf* root_server_conf; rivet_server_conf* myrsc; @@ -145,11 +145,11 @@ rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) parentfunction = root_server_conf->rivet_child_init_script; - for (s = root_server; s != NULL; s = s->next) + for (vhost_server = root_server; vhost_server != NULL; vhost_server = vhost_server->next) { - rivet_thread_interp* rivet_interp; + rivet_thread_interp* rivet_interp; - myrsc = RIVET_SERVER_CONF(s->module_config); + myrsc = RIVET_SERVER_CONF(vhost_server->module_config); /* by default we assign the root_interpreter as * interpreter of the virtual host. In case of separate @@ -159,7 +159,7 @@ rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) rivet_interp = root_interp; - if (s == root_server) + if (vhost_server == root_server) { Tcl_RegisterChannel(rivet_interp->interp,*rivet_interp->channel); } @@ -187,16 +187,13 @@ rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) /* interpreter base running scripts definition and initialization */ rivet_interp->scripts = Rivet_RunningScripts (private->pool,rivet_interp->scripts,myrsc); - - //private->ext->interps[myrsc->idx] = rivet_interp; - RIVET_POKE_INTERP(private,myrsc,rivet_interp); /* Basic Rivet packages and libraries are loaded here */ if ((rivet_interp->flags & RIVET_INTERP_INITIALIZED) == 0) { - Rivet_PerInterpInit(rivet_interp, private, s, private->pool); + Rivet_PerInterpInit(rivet_interp,private,vhost_server,private->pool); } /* It seems that allocating from a shared APR memory pool is not thread safe, @@ -209,21 +206,21 @@ rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) */ apr_thread_mutex_lock(module_globals->pool_mutex); - myrsc->server_name = (char*) apr_pstrdup (private->pool, s->server_hostname); + myrsc->server_name = (char*) apr_pstrdup (private->pool,vhost_server->server_hostname); apr_thread_mutex_unlock(module_globals->pool_mutex); /* when configured a child init script gets evaluated */ function = myrsc->rivet_child_init_script; if (function && - (s == root_server || module_globals->separate_virtual_interps || function != parentfunction)) + (vhost_server == root_server || module_globals->separate_virtual_interps || function != parentfunction)) { char* errmsg = MODNAME ": Error in Child init script: %s"; - Tcl_Interp* interp = rivet_interp->interp; Tcl_Obj* tcl_child_init = Tcl_NewStringObj(function,-1); + rivet_interp_globals* globals = NULL; Tcl_IncrRefCount(tcl_child_init); - Tcl_Preserve (interp); + Tcl_Preserve (rivet_interp->interp); /* There is a lot of passing pointers around among various structures. * We should understand if this is all that necessary. @@ -238,17 +235,24 @@ rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private) * prepared TODO */ + globals = Tcl_GetAssocData(rivet_interp->interp, "rivet", NULL); + + /* + * The current server record is stored to enable ::rivet::apache_log_error and + * other commands to log error messages in the virtual host's designated log file + */ + + globals->server = vhost_server; private->running_conf = myrsc; - if (Tcl_EvalObjEx(interp,tcl_child_init, 0) != TCL_OK) { - ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server, - errmsg, function); - ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server, - "errorCode: %s", Tcl_GetVar(interp, "errorCode", 0)); - ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server, - "errorInfo: %s", Tcl_GetVar(interp, "errorInfo", 0)); + if (Tcl_EvalObjEx(rivet_interp->interp,tcl_child_init, 0) != TCL_OK) { + ap_log_error(APLOG_MARK, APLOG_ERR,APR_EGENERAL,vhost_server,errmsg, function); + ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL,vhost_server, + "errorCode: %s", Tcl_GetVar(rivet_interp->interp, "errorCode", 0)); + ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL,vhost_server, + "errorInfo: %s", Tcl_GetVar(rivet_interp->interp, "errorInfo", 0)); } - Tcl_Release (interp); + Tcl_Release (rivet_interp->interp); Tcl_DecrRefCount(tcl_child_init); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@tcl.apache.org For additional commands, e-mail: commits-h...@tcl.apache.org