int child_count = 0;
-int run(const char *cmd, char *const argv[])
+int do_fork(void)
{
int child, error;
child = fork();
/* reset child's child count */
child_count = 0;
+ return 0;
+}
+
+int run(const char *cmd, char *const argv[])
+{
+ int child, error;
+ if ((child = do_fork()))
+ return child;
+
execvp(cmd, argv);
error = errno;
printf("Failed to execv command %s: %s\n", cmd, strerror(error));
return -1;
}
- pid = fork();
- if (pid < 0) {
- error = errno;
- fprintf(stderr, "fork() failed: %s\n", strerror(error));
- return -1;
- }
-
+ pid = do_fork();
if (pid) {
close(rfd[1]);
close(wfd[0]);
#include <error.h>
#include <errno.h>
+int do_fork(void);
int run(const char *p, char *const argv[]);
int harvest_zombies(int pid);
int run_piped(const char *cmd, char *const argv[], int *readfd, int *writefd);
int l;
rrd->last_update = time(0);
- if (fork()) {
- child_count++;
+ if (do_fork())
return 0;
- }
-
- /* reset child's child count */
- child_count = 0;
l = sprintf(data, "N:");
if (rrd->images)
draw_images(rrd->images);
- while(harvest_zombies(0));
+ while (harvest_zombies(0));
exit(0);
}