MCPcopy Create free account
hub / github.com/ElementsProject/lightning / pipecmdarr

Function pipecmdarr

ccan/ccan/pipecmd/pipecmd.c:47–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47pid_t pipecmdarr(int *fd_tochild, int *fd_fromchild, int *fd_errfromchild,
48 char *const *arr)
49{
50 int tochild[2], fromchild[2], errfromchild[2], execfail[2];
51 /* fds for parent to close */
52 int par_close[4], num_par_close = 0;
53 /* fds for child to close */
54 int child_close[4], num_child_close = 0;
55 pid_t childpid;
56 int err;
57
58 if (fd_tochild) {
59 if (fd_tochild == &pipecmd_preserve) {
60 tochild[0] = STDIN_FILENO;
61 } else if (pipe(tochild) == 0) {
62 par_close[num_par_close++] = tochild[0];
63 child_close[num_child_close++] = tochild[1];
64 } else
65 goto fail;
66 } else {
67 tochild[0] = open("/dev/null", O_RDONLY);
68 if (tochild[0] < 0)
69 goto fail;
70 par_close[num_par_close++] = tochild[0];
71 }
72 if (fd_fromchild) {
73 if (fd_fromchild == &pipecmd_preserve) {
74 fromchild[1] = STDOUT_FILENO;
75 } else if (pipe(fromchild) == 0) {
76 par_close[num_par_close++] = fromchild[1];
77 child_close[num_child_close++] = fromchild[0];
78 } else
79 goto fail;
80 } else {
81 fromchild[1] = open("/dev/null", O_WRONLY);
82 if (fromchild[1] < 0)
83 goto fail;
84 par_close[num_par_close++] = fromchild[1];
85 }
86 if (fd_errfromchild) {
87 if (fd_errfromchild == &pipecmd_preserve) {
88 errfromchild[1] = STDERR_FILENO;
89 } else if (fd_errfromchild == fd_fromchild) {
90 errfromchild[0] = fromchild[0];
91 errfromchild[1] = fromchild[1];
92 } else if (pipe(errfromchild) == 0) {
93 par_close[num_par_close++] = errfromchild[1];
94 child_close[num_child_close++] = errfromchild[0];
95 } else
96 goto fail;
97 } else {
98 errfromchild[1] = open("/dev/null", O_WRONLY);
99 if (errfromchild[1] < 0)
100 goto fail;
101 par_close[num_par_close++] = errfromchild[1];
102 }
103
104 if (pipe(execfail) != 0)

Callers 4

pipecmdvFunction · 0.85
plugin_send_getmanifestFunction · 0.85
next_bcliFunction · 0.85
wait_and_check_bitcoindFunction · 0.85

Calls 2

closefromFunction · 0.85
close_noerrFunction · 0.85

Tested by

no test coverage detected