Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 92891 - apache2 init script clobbers environment
Summary: apache2 init script clobbers environment
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Other
: High normal (vote)
Assignee: Apache Team - Bugzilla Reports
URL:
Whiteboard:
Keywords: Inclusion
: 79027 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-17 04:35 UTC by Simon Detheridge
Modified: 2005-07-12 19:57 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Detheridge 2005-05-17 04:35:56 UTC
The apache2 init script clobbers the environment, running it with an empty environment except for a custom PATH variable.

This is a problem when running some third-party apache modules that require environment variables to be set. The apache foundation's own axis-c module is an example of this, as it requires AXISCPP_DEPLOY=/some/path to be set to funcion correctly.

A workaround (specific for axis-c) is to modify the apache init script so that the line:
    APACHE2="env -i PATH=${PATH} /usr/sbin/apache2${MY_MPM}"
reads:
    APACHE2="env -i PATH=${PATH} AXISCPP_DEPLOY=/some/path /usr/sbin/apache2${MY_MPM}"

This works, but is not the most graceful way of doing this. Subsequent updates to apache that change the init script could wipe out these modifications if not merged carefully.

I propose that a better way would be to add a variable APACHE2_ENV to /etc/conf.d/apache2, and modifying the line to read:
    APACHE2="env -i PATH=${PATH} ${APACHE2_ENV} /usr/sbin/apache2${MY_MPM}"

Then I could add:
APACHE2_ENV="AXISCPP_DEPLOY=/some/path" 
to /etc/conf.d/apache2 and not worry about future updates to apache wiping this out.
Comment 1 Elfyn McBratney (beu) (RETIRED) gentoo-dev 2005-05-18 02:20:42 UTC
The 'cleansing' of the environment is intentional, and there has been a few     
open bugs about this before.  I really do not want to change this, or start     
creating white lists, either ..  
     
However, I can't think think of any one way that'd suit both camps .. Does    
anyone have any adverse feelings to having a white-list variable    
in /etc/conf.d/apache2 as Simon explained ?  Would be easy to implement, as 
well (could also go in at the same time we kill the 
'graceful-restart-by-default' behaviour in the init script </muse> ..) 
Comment 2 Alexander Hoogerhuis 2005-07-04 06:08:55 UTC
Could this one help?

This lets the user decide what to keep from the env, and I have to use it on a
customer site due to PHP/Oracle and NLS conflicts.

Basically the user needs to maintain the var KEEPENV in /etc/conf.d/apache2 and
it would default to PATH only.

--- /etc/init.d/apache2 2005-07-04 15:06:05.000000000 +0200
+++ tmp/apache2 2005-07-04 15:05:33.000000000 +0200
@@ -37,6 +37,13 @@
         eerror "Did you etc-update /etc/conf.d/apache2?"
         return 1
     fi
+
+    if [ ! -z "${KEEPENV}" ]; then
+       for n in ${KEEPENV}; do
+               OLDENV="${OLDENV} ${n}=`printenv ${n}`";
+       done
+    fi
+
        /usr/sbin/apache2 -t ${APACHE2_OPTS} 1>/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
@@ -54,10 +61,13 @@

 start() {
        checkconfig || return 1
+       if [ ! -z "${OLDENV}" ]; then
+               einfo "  Keeping old env: ${KEEPENV}"
+       fi
        ebegin "Starting apache2"
        [ -f /var/log/apache2/ssl_scache ] && rm /var/log/apache2/ssl_scache
        [ -f /usr/lib/apache2/build/envvars ] && . /usr/lib/apache2/build/envvars
-       env -i PATH=$PATH /sbin/start-stop-daemon --quiet \
+       env -i $OLDENV /sbin/start-stop-daemon --quiet \
                --start --startas /usr/sbin/apache2 \
                --pidfile ${PIDFILE} -- -k start ${APACHE2_OPTS}
        eend $?
Comment 3 Michael Stewart (vericgar) (RETIRED) gentoo-dev 2005-07-11 21:04:05 UTC
*** Bug 79027 has been marked as a duplicate of this bug. ***
Comment 4 Michael Stewart (vericgar) (RETIRED) gentoo-dev 2005-07-12 18:42:57 UTC
I've added a fix for this to SVN. It will appear the next time a configuration
tarball is rolled.
Comment 5 Michael Stewart (vericgar) (RETIRED) gentoo-dev 2005-07-12 19:57:03 UTC
New tarball rolled.
Fixed in CVS.
Resolving.