Add an "after fork, before exec" callback
authorAlexey Spiridonov <lesha@fb.com>
Fri, 4 Dec 2015 09:35:41 +0000 (01:35 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Sun, 6 Dec 2015 03:20:23 +0000 (19:20 -0800)
commit59030f07f4ff117ddd881d746b3631e434ca2ac2
tree820ffd8448433177d0440e4ab53342bb29a76e1c
parentf94bbfebcbd7802d81102c084784115b70930e8e
Add an "after fork, before exec" callback

Summary:
In rare cases, it is required to run code **in the child process**, before it calls `exec()` because you need to change the state of the process **before** the child binary gets to run. This diff adds a callback to permit this. The callback is deliberately harder to use than an `std::function`, because you **REALLY HAVE TO KNOW WHAT YOU ARE DOING** to use this. And you have to check your work three times. Even glog `LOG()` must not be called from inside this callback. Your random library of choice is also probably unsafe.

This diff is primarily applicable to job managers and shells. For example, these tasks benefit from this callback: adding a child to a Linux `cgroup`, twiddling its various POSIX process attributes.

Implementing a correct callback for the post-vfork environment is fraught with peril. Read http://ewontfix.com/7/, and the docstrings in this diff.

Reviewed By: yfeldblum

Differential Revision: D2688323

fb-gh-sync-id: aae49e2b3957ca845895acca26e9cb44df1afc07
folly/Subprocess.cpp
folly/Subprocess.h
folly/test/SubprocessTest.cpp