Add an "after fork, before exec" callback
[folly.git] / folly / Subprocess.cpp
index b517c55df33c54377ebb886b4bbd052b964ef69b..2a1c3bce686d4280615aea4f8bdefdcd7b21f62d 100644 (file)
@@ -493,6 +493,13 @@ int Subprocess::prepareChild(const Options& options,
     }
   }
 
+  // The user callback comes last, so that the child is otherwise all set up.
+  if (options.dangerousPostForkPreExecCallback_) {
+    if (int error = (*options.dangerousPostForkPreExecCallback_)()) {
+      return error;
+    }
+  }
+
   return 0;
 }