]> git.itanic.dy.fi Git - rrdd/commitdiff
Move all fork operations to do_fork() functino
authorTimo Kokkonen <kaapeli@ee.oulu.fi>
Sun, 6 Apr 2008 06:49:44 +0000 (09:49 +0300)
committerTimo Kokkonen <kaapeli@ee.oulu.fi>
Sun, 6 Apr 2008 06:49:44 +0000 (09:49 +0300)
process.c
process.h
scheduler.c

index b93a0f50a17c7137f653b630e71638e2de9cf1c5..0e5c1c2ce24a7c3d01604b6b3bcf2c3f601c5c63 100644 (file)
--- a/process.c
+++ b/process.c
@@ -2,7 +2,7 @@
 
 int child_count = 0;
 
-int run(const char *cmd, char *const argv[])
+int do_fork(void)
 {
        int child, error;
        child = fork();
@@ -20,6 +20,15 @@ int run(const char *cmd, char *const argv[])
 
        /* 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));
@@ -69,13 +78,7 @@ int run_piped(const char *cmd, char *const argv[], int *readfd, int *writefd)
                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]);
index a44cad0f1e77f1c0809445ab2a5d2fb8a693b5ca..143f6c430e6c65f92036490a869261c2c1238cd7 100644 (file)
--- a/process.h
+++ b/process.h
@@ -9,6 +9,7 @@
 #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);
index 9890c2777146ce9894928e3f38e6bdf1febc4307..5029fca9e281b75a2e956124f25532d309be110f 100644 (file)
@@ -16,13 +16,8 @@ int update_data(struct rrd_database *rrd)
        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:");
 
@@ -34,7 +29,7 @@ int update_data(struct rrd_database *rrd)
        if (rrd->images)
                draw_images(rrd->images);
 
-       while(harvest_zombies(0));
+       while (harvest_zombies(0));
        exit(0);
 }