]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
global/global_init: fix stdout/stderr/stdin closing for daemonization 22954/head
authorSage Weil <sage@redhat.com>
Mon, 9 Jul 2018 18:26:39 +0000 (13:26 -0500)
committerSage Weil <sage@redhat.com>
Mon, 9 Jul 2018 18:26:39 +0000 (13:26 -0500)
commit3c2d91ed11c19ee8769acef8268938d2cab59152
tree84321f9ad928a4137d390bf75b002895a3ce55b3
parent975528f632f73fbffa3f1fee304e3bbe3296cffc
global/global_init: fix stdout/stderr/stdin closing for daemonization

The global_init_postfork/prefork helpers close stdout/stdin/stderr on
fork and reopen /dev/null in their place.  This ensures that if later
code writes to those descriptors (e.g., a stray cout or cerr usage) the
output/input will go nowhere instead of interfering with some other open
fd.

However, with the use of preforker, there are other threads running when
these helpers are run, which means we can race with, say, filestore
opening an object file and end up sending log output there.

Fix by atomically replacing the fds with the dup2(2) syscall, which
will implicitly close and reopen the target fd in an atomic fashion.  This
behavior is present on both Linux and FreeBSD.

Fixes: http://tracker.ceph.com/issues/23492
Signed-off-by: Sage Weil <sage@redhat.com>
src/global/global_init.cc