]> git.itanic.dy.fi Git - rrdd/commitdiff
Add fork debug and clear any child's child_count to zero after fork
authorTimo Kokkonen <kaapeli@ee.oulu.fi>
Thu, 3 Apr 2008 19:29:15 +0000 (22:29 +0300)
committerTimo Kokkonen <kaapeli@ee.oulu.fi>
Thu, 3 Apr 2008 19:29:15 +0000 (22:29 +0300)
process.c
scheduler.c

index 30e1249c06f2bb337b0008468538d0c45b4bd23a..b93a0f50a17c7137f653b630e71638e2de9cf1c5 100644 (file)
--- a/process.c
+++ b/process.c
@@ -13,11 +13,13 @@ int run(const char *cmd, char *const argv[])
        }
 
        if (child) {
-               printf("Forked child %d\n", child);
+               printf("%d: Forked child %d\n", getpid(), child);
                child_count++;
                return child;
        }
 
+       /* reset child's child count */
+       child_count = 0;
        execvp(cmd, argv);
        error = errno;
        printf("Failed to execv command %s: %s\n", cmd, strerror(error));
@@ -27,16 +29,21 @@ int run(const char *cmd, char *const argv[])
 
 int harvest_zombies(int pid)
 {
-       int status;
+       int status, error;
 
        if (child_count == 0)
                return 0;
 
        pid = waitpid(pid, &status, 0);
-       if (status == 0)
-               printf("pid %d: terminated with exit code %d\n", pid, status);
+       if (pid < 0) {
+               error = errno;
+               fprintf(stderr, "%d: Error on wait(): %s\n", getpid(),
+                       strerror(error));
+       }
+       else
+               printf("pid %d: exit %d. %d still running\n", pid, status,
+                      child_count--);
 
-       child_count--;
        return 1;
 }
 
@@ -74,6 +81,7 @@ int run_piped(const char *cmd, char *const argv[], int *readfd, int *writefd)
                close(wfd[0]);
                *readfd = rfd[0];
                *writefd = wfd[1];
+               child_count++;
                return pid;
        }
 
index 105533e11b2890d8e9f645a106fe2fb58a1dcbb3..9890c2777146ce9894928e3f38e6bdf1febc4307 100644 (file)
@@ -21,6 +21,9 @@ int update_data(struct rrd_database *rrd)
                return 0;
        }
 
+       /* reset child's child count */
+       child_count = 0;
+
        l = sprintf(data, "N:");
 
        if (rrd->parse) {