Commit 7959b9a5 authored by Xavier Thompson's avatar Xavier Thompson

slapgrid: Fix promise logging with instance python

The promise runner launched in a subprocess with the instance's python
redirects stderr to stdout in order to reserve stderr for propagating
error messages.

However `preexec_fn` is used to run `dropPrivileges` inside the child
process, so when `dropPrivileges` calls `logger.debug`, the logger
writes to stderr before the redirection is set up.

To fix this, the `preexec_fn` function is modified to apply the same
redirection first and revert it at the end. Reverting it avoids the
need to communicate the new file descriptor for the original stderr
stream to runpromise.py.
parent dc8272b5
......@@ -732,10 +732,15 @@ stderr_logfile_backups=1
# The runpromise script uses stderr exclusively to propagate exception
# messages. It otherwise redirects stderr to stdout so that all outputs
# from the promises go to stdout.
def preexec_fn():
err = os.dup(2)
os.dup2(1, 2)
dropPrivileges(uid, gid, logger=self.logger)
os.dup2(err, 2)
try:
process = SlapPopen(
command,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
preexec_fn=preexec_fn,
cwd=instance_path,
universal_newlines=True,
stdout=subprocess.PIPE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment