TritonDataCenter / pkgsrc-joyent

Various pkgsrc packages used by Joyent, not committed upstream yet
30 stars 31 forks source link

Postfix export_environment bug #11

Open njones11 opened 10 years ago

njones11 commented 10 years ago

Postfix provides the 'export_environment' option to define which environment variables should be passed to processes it calls.

See here: http://www.postfix.org/postconf.5.html#export_environment

In our case, we're using Postfix to deliver mail to a local system account. Inside the system account's .forward file, we have something like this:

|/home/mlm/test.py

Basically, postfix pipes all the mail to this script which does further processing. Inside /opt/local/etc/postfix/main.cf, we have several environment variables defined that our script needs to see.

export_environment = PATH=/home/mlm/virtualenv/bin PYTHONPATH=/home/mlm/virtualenv/lib/python2.7/site-packages/

We know that PYTHONPATH is being set correctly. However, for some reason, PATH is not getting correctly passed to the script. As far as I can tell, this looks like a packaging bug.

Inside test.py, we added this for debugging:

    for key in os.environ:
        logging.info("%s: %s" % (key, os.environ[key]))

And then this is what we saw in the log:

2014-07-21 11:02:48,112 - root - INFO - PATH: /usr/bin:/usr/ucb
2014-07-21 11:02:48,113 - root - INFO - PYTHONPATH: /home/mlm/virtualenv/lib/python2.7/site-packages/

As far as I can tell, this path is getting hard-coded somewhere in the packaging process:

# for i in `ls /opt/local/libexec/postfix/`;do echo $i: `strings /opt/local/libexec/postfix/$i | grep ucb` ;done
anvil:
bounce:
cleanup: /usr/bin:/usr/ucb
discard:
dnsblog:
error:
flush:
lmtp:
local: /usr/bin:/usr/ucb
main.cf:
master:
master.cf:
nqmgr:
oqmgr:
pickup:
pipe: /usr/bin:/usr/ucb
post-install: PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
postfix-files:
postfix-script:
postfix-wrapper:
postmulti-script:
postscreen:
proxymap:
qmgr:
qmqpd: /usr/bin:/usr/ucb
scache:
showq:
smtp:
smtpd: /usr/bin:/usr/ucb
spawn: /usr/bin:/usr/ucb
tlsmgr:
tlsproxy:
trivial-rewrite:
verify:
virtual:

Any suggestions?

cc: @nshalman