slapgrid: Fix promise logging with instance python
In runpromise.py stderr outputs are redirected on stdout to reserve stderr for propagating error messages back to the parent process. However it turns out preexec_fn can log on stderr before this redirection is set up.
This can cause either unexpected warnings to appear in the logs (when the promises all succeed) or pollute the error message when a promise fails.
An example of such a warning:
[2022-03-29 16:52:42,933] INFO Checking slappartXX promises...
[2022-03-29 16:52:42,934] INFO Switching to slappartXX's python at /YYYY/python2.7/bin/python2.7
[2022-03-29 16:52:42,941] DEBUG Succesfully dropped privileges to uid=965 gid=1038
...
[2022-03-29 16:52:47,620] WARNING Promise runner unexpected output:
2022-03-29 16:52:42 slapos[15963] DEBUG Succesfully dropped privileges to uid=965 gid=1038
In this case this is caused by dropPrivileges issuing a logger.debug() call, and since dropPrivileges is executed as inside the child process with preexec_fn, the logger ends up writing to the child process's stderr before it is redirected to stdout.
To fix this issue, preexec_fn is modified to do the same redirection and then revert it. Reverting it avoids the need to communicate the new file descriptor for the original stderr stream to runpromise.py, which seems very hard do to from inside preexec_fn.