]> git.itanic.dy.fi Git - rrdd/commitdiff
process: Improve error handling
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Apr 2012 12:01:19 +0000 (15:01 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Apr 2012 12:01:19 +0000 (15:01 +0300)
Check the error message from select(). If error, bail out.

Also close all file descriptors in the end. If select happends to fail
and we go to waitpid() and the process is writing content, it might
eventually block because nobody is reading the file descriptor. By
closing the file we ensure the process will not hang and there will be
no deadlock.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
process.c

index 9e2814a2109deaa1831fbabfa66915a05c38a689..93785244cd0e910bd7b1a71ac2c810f3fdd23f65 100644 (file)
--- a/process.c
+++ b/process.c
@@ -244,6 +244,11 @@ int run(const char *cmd, char *const argv[])
                maxfd = max(ofd, efd);
                error = select(maxfd, &rfds, NULL, NULL, NULL);
 
+               if (error < 0) {
+                       printf("Error with select: %m\n");
+                       break;
+               }
+
                if (FD_ISSET(ofd, &rfds)) {
                        typestr = stdoutstr;
                        bytes = read(ofd, rbuf, BUF_SIZE);
@@ -291,6 +296,9 @@ print:
                }
        }
 
+       close(ofd);
+       close(efd);
+
        harvest_zombies(child); 
 
        exit(1);