Abort depgen output reading on EOF, not child exiting
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Jun 2011 07:01:14 +0000 (10:01 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Jun 2011 07:01:14 +0000 (10:01 +0300)
- There could, at least in theory, still be data to read after
  we receive SIGCHLD. Stop the loop on EOF on read instead.
  Thanks to Michael Schroeder for pointing this out.

build/rpmfc.c

index a01cba2..70eebc3 100644 (file)
@@ -320,6 +320,7 @@ static StringBuf getOutputFrom(ARGV_t argv,
        /* Read when we get data back from the child */
        if (FD_ISSET(fromProg[0], &ibits)) {
            int nbr = read(fromProg[0], buf, sizeof(buf)-1);
+           if (nbr == 0) break; /* EOF, we're done */
            if (nbr < 0 && errno == EINTR) continue;
            if (nbr < 0) {
                myerrno = errno;
@@ -329,10 +330,9 @@ static StringBuf getOutputFrom(ARGV_t argv,
            appendStringBuf(readBuff, buf);
        }
 
-       /* Child exited, we're done */
+       /* Child exited */
        if (FD_ISSET(sigpipe, &ibits)) {
            while (read(sigpipe, buf, sizeof(buf)) > 0) {};
-           break;
        }
     }