]> git.itanic.dy.fi Git - rrdd/commitdiff
Fix count number of children correctly
authorTimo Kokkonen <kaapeli@kaatokone0.dy.fi>
Sun, 6 Apr 2008 09:14:38 +0000 (12:14 +0300)
committerTimo Kokkonen <kaapeli@kaatokone0.dy.fi>
Sun, 6 Apr 2008 09:14:38 +0000 (12:14 +0300)
process.c
process.h

index 950a267d0060d61fdd1d03b4ebd70d2fa2ba9177..3c0f1190c6b91e087a7b2986fd2cbc7eceece7ed 100644 (file)
--- a/process.c
+++ b/process.c
@@ -14,8 +14,8 @@ int do_fork(void)
        }
 
        if (child) {
-               pr_info("Forked child %d\n", child);
                child_count++;
+               pr_info("Fork %d, child %d\n", child_count, child);
                return child;
        }
 
@@ -44,14 +44,21 @@ int harvest_zombies(int pid)
        if (child_count == 0)
                return 0;
 
+       if (pid)
+               pr_info("Waiting on pid %d, children left: %d\n", pid, 
+                       child_count);
+
        pid = waitpid(pid, &status, 0);
        if (pid < 0) {
                error = errno;
                pr_err("Error on wait(): %s\n", strerror(error));
+               child_count--; /* Decrement child count anyway */
        }
-       else
+       else {
+               child_count--;
                pr_info("pid %d: exit code %d. Children left: %d\n", pid,
-                       status, --child_count);
+                       status, child_count);
+       }
 
        return 1;
 }
@@ -84,7 +91,6 @@ 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 143f6c430e6c65f92036490a869261c2c1238cd7..3782d84550701e9e28eb35cad183bba936f4b657 100644 (file)
--- a/process.h
+++ b/process.h
@@ -16,6 +16,4 @@ int run_piped(const char *cmd, char *const argv[], int *readfd, int *writefd);
 int run_piped_stream(const char *cmd, char *const argv[],
                     FILE **readf, FILE **writef);
 
-extern int child_count;
-
 #endif