12 pr_err("fork() failed: %s\n", strerror(error));
18 pr_info("Fork %d, child %d\n", child_count, child);
22 /* reset child's child count */
27 int run(const char *cmd, char *const argv[])
30 if ((child = do_fork()))
35 pr_err("Failed to execv command %s: %s\n", cmd, strerror(error));
40 int harvest_zombies(int pid)
48 pr_info("Waiting on pid %d, children left: %d\n", pid,
51 pid = waitpid(pid, &status, 0);
54 pr_err("Error on wait(): %s\n", strerror(error));
55 child_count--; /* Decrement child count anyway */
59 pr_info("pid %d: exit code %d. Children left: %d\n", pid,
67 * Runs a command cmd with params argv, connects stdin and stdout to
70 * Returns the pid of the executed process
72 int run_piped(const char *cmd, char *const argv[], int *readfd, int *writefd)
74 int rfd[2], wfd[2], error, pid;
78 pr_err("pipe() failed: %s\n", strerror(error));
84 pr_err("pipe() failed: %s\n", strerror(error));
99 dup2(wfd[0], STDIN_FILENO);
100 dup2(rfd[1], STDOUT_FILENO);
102 /* Now we have redirected both stdin and stdout to parent process */
105 pr_err("Failed to execv command %s: %s\n", cmd, strerror(error));
111 * Runs a command cmd with params argv, connects stdin and stdout to
114 * Returns the pid of the executed process
116 int run_piped_stream(const char *cmd, char *const argv[],
117 FILE **readf, FILE **writef)
119 int rfd, wfd, pid, error;
121 pid = run_piped(cmd, argv, &rfd, &wfd);
124 *readf = fdopen(rfd, "r");
125 if (*readf == NULL) {
127 pr_err("Error opening file stream for fd %d: %s\n",
128 rfd, strerror(error));
134 *writef = fdopen(wfd, "w");
135 if (*writef == NULL) {
137 pr_err("Error opening file stream for fd %d: %s\n",
138 wfd, strerror(error));