MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / dmtcp_spawn

Function dmtcp_spawn

src/posix_spawn.cpp:38–158  ·  view source on GitHub ↗

Spawn a new process executing PATH with the attributes describes in *ATTRP. Before running the process perform the actions described in FILE-ACTIONS. */

Source from the content-addressed store, hash-verified

36/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
37 Before running the process perform the actions described in FILE-ACTIONS. */
38int
39dmtcp_spawn(pid_t *pid,
40 const char *file,
41 const posix_spawn_file_actions_t *file_actions,
42 const posix_spawnattr_t *attrp,
43 char *const argv[],
44 char *const envp[])
45{
46 /* Do this once. */
47 short int flags = attrp == NULL ? 0 : attrp->__flags;
48
49 // TODO(kapil): Add support for POSIX_SPAWN_USEVFORK.
50 pid_t new_pid = fork();
51
52 // Parent.
53 if (new_pid != 0) {
54 if (new_pid < 0) {
55 return errno;
56 }
57
58 /* The call was successful. Store the PID if necessary. */
59 if (pid != NULL) {
60 *pid = new_pid;
61 }
62
63 return 0;
64 }
65
66 /* Set signal mask. */
67 if ((flags & POSIX_SPAWN_SETSIGMASK) != 0 &&
68 sigprocmask(SIG_SETMASK, &attrp->__ss, NULL) != 0) {
69 exit(SPAWN_ERROR);
70 }
71
72 /* Set signal default action. */
73 if ((flags & POSIX_SPAWN_SETSIGDEF) != 0) {
74 struct sigaction sa = {};
75 sa.sa_handler = SIG_DFL;
76
77 int ckptSig = dmtcp_get_ckpt_signal();
78 for (int sig = 1; sig < _NSIG; ++sig) {
79 if (sig != ckptSig && sigismember(&attrp->__sd, sig) != 0 &&
80 sigaction(sig, &sa, NULL) != 0) {
81 JTRACE("sigaction failed");
82 exit(SPAWN_ERROR);
83 }
84 }
85 }
86
87 /* Set the process group ID. */
88 if ((flags & POSIX_SPAWN_SETPGROUP) != 0 && setpgid(0, attrp->__pgrp) != 0) {
89 JTRACE("setpgid failed");
90 exit(SPAWN_ERROR);
91 }
92
93 /* Set the effective user and group IDs. */
94 if ((flags & POSIX_SPAWN_RESETIDS) != 0 &&
95 (seteuid(getuid()) != 0 || setegid(getgid()) != 0)) {

Callers 2

posix_spawnFunction · 0.85
posix_spawnpFunction · 0.85

Calls 9

sigprocmaskFunction · 0.85
setpgidFunction · 0.85
execveFunction · 0.85
forkFunction · 0.70
dmtcp_get_ckpt_signalFunction · 0.70
sigactionClass · 0.70
closeFunction · 0.70
openFunction · 0.70
dup2Function · 0.70

Tested by

no test coverage detected