Robert Schulze wrote:
Hi,
I'm currently working on a module to create virtualhosts on the fly out
of a cdb-database file.
...
In one module I saw the following:
<--------------------------------------------------------------------
request_rec *top = (r->main)?r->main:r;
/* ... */
top->server->server_hostname = apr_pstrdup (top->pool, hostname);
r->parsed_uri.hostinfo = apr_pstrdup(r->pool,r->server->server_hostname);
r->parsed_uri.hostname = apr_pstrdup(r->pool,r->server->server_hostname);
<--------------------------------------------------------------------
and thats exactly where I got some problems.
I sometimes noticed, that the virtual host name in /server-status/
contained only weird characters, which I think is a result of freeing a
buffer which is currently in use.
I think the problem is the wrong pool for allocating space for the
server_hostname.
In a threaded mpm, the same r->server struct is used by multiple requests simultaneously. It isn't
safe to change anything in it on the fly.
It is usually good enough to look up a new root directory and use apr_filepath_merge() to set the
actual filename in a "translate_name" hook, without trying to update the server_rec.
r->hostname has the requested hostname for any scripts which require this info.
Take a look at mod_vhost_alias, or mod_vhost_dbd at
http://dbd-modules.googlecode.com for examples.
-tom-