proxygen
SubprocessTestParentDeathHelper.cpp File Reference
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <glog/logging.h>
#include <folly/Conv.h>
#include <folly/Subprocess.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/Unistd.h>

Go to the source code of this file.

Functions

 DEFINE_bool (child, false,"")
 
void runChild (const char *file)
 
void runParent (const char *file)
 
int main (int argc, char *argv[])
 

Function Documentation

DEFINE_bool ( child  ,
false  ,
""   
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 73 of file SubprocessTestParentDeathHelper.cpp.

References runChild(), and runParent().

73  {
74  gflags::ParseCommandLineFlags(&argc, &argv, true);
75  CHECK_EQ(argc, 2);
76  if (FLAGS_child) {
77  runChild(argv[1]);
78  } else {
79  runParent(argv[1]);
80  }
81  return 0;
82 }
void runParent(const char *file)
void runChild(const char *file)
char ** argv
void runChild ( const char *  file)

Definition at line 44 of file SubprocessTestParentDeathHelper.cpp.

References folly::sig.

Referenced by main(), and folly::Subprocess::spawnInternal().

44  {
45  // Block SIGUSR1 so it's queued
46  sigset_t sigs;
47  CHECK_ERR(sigemptyset(&sigs));
48  CHECK_ERR(sigaddset(&sigs, kSignal));
49  CHECK_ERR(sigprocmask(SIG_BLOCK, &sigs, nullptr));
50 
51  // Kill the parent, wait for our signal.
52  CHECK_ERR(kill(getppid(), SIGKILL));
53 
54  int sig = 0;
55  CHECK_ERR(sigwait(&sigs, &sig));
56  CHECK_EQ(sig, kSignal);
57 
58  // Signal completion by creating the file
59  CHECK_ERR(creat(file, 0600));
60 }
constexpr detail::Sig< Sig > const sig
Definition: Poly.h:1165
void runParent ( const char *  file)

Definition at line 62 of file SubprocessTestParentDeathHelper.cpp.

References folly::Subprocess::poll(), and folly::ProcessReturnCode::running().

Referenced by main().

62  {
63  std::vector<std::string> args{"/proc/self/exe", "--child", file};
64  Subprocess proc(args, Subprocess::Options().parentDeathSignal(kSignal));
65  CHECK(proc.poll().running());
66 
67  // The child will kill us.
68  for (;;) {
69  pause();
70  }
71 }