httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton" <graham.dumple...@gmail.com>
Subject Re: need some help with module that does not work on linux
Date Mon, 28 Apr 2008 20:57:25 GMT
2008/4/29 Chris Kukuchka <chrisk@sequoiagroup.com>:
> Aivars Šterns wrote:
>
> > Yes, but this is not how apache could handle this, we need argv[], but
> there
> > is no way to get this from apache right?
> >
> >
>
>  In server/main.c, argv gets linked to the process_rec structure during the
> process startup.  Further, according to include/httpd.h, the process_rec
> structure can be reached through the request_rec structure
> (r->connection->server->process).  As such, argv[] should be available for
> reading most anywhere in Apache.
>
>  As far as the safety of making changes to those values is concerned, I have
> no advise beyond, "proceed with caution."  Especially if you intend on
> placing raw request data there.

Although you can get access to argv[], you can only change the value
of argv[0], at least for the purposes of effecting the output from
'ps'. This is because that argv[] is not the original argv[] and thus
modules could have substituted the program arguments, ie., argv[1] and
beyond. This means that any value you substitute must fit into the
original length of argv[0] and cannot flow over into the additional
arguments.

Some code form mod_wsgi:

static void wsgi_setup_daemon_name(WSGIDaemonProcess *daemon, apr_pool_t *p)
{
    const char *display_name = NULL;

    int slen = 0;
    int dlen = 0;

    char *argv0 = NULL;

    display_name = daemon->group->display_name;

    if (!display_name)
        return;

    if (!strcmp(display_name, "%{GROUP}")) {
        display_name = apr_pstrcat(p, "(wsgi:", daemon->group->name,
                                   ")", NULL);
    }

    /*
     * Only argv[0] is guaranteed to be the real things as MPM
     * modules may make modifications to subsequent arguments.
     * Thus can only replace the argv[0] value. Because length
     * is restricted, need to truncate display name if too long.
     */

    argv0 = (char*)wsgi_server->process->argv[0];

    dlen = strlen(argv0);
    slen = strlen(display_name);

    memset(argv0, ' ', dlen);

    if (slen < dlen)
        memcpy(argv0, display_name, slen);
    else
        memcpy(argv0, display_name, dlen);
}

The wsgi_server variable is a cached reference to server_rec structure.

Graham

Mime
View raw message