From 173ebb3fe6d38ac123b13afa29b61a01409707f0 Mon Sep 17 00:00:00 2001 From: jbj Date: Thu, 10 Sep 1998 15:09:21 +0000 Subject: [PATCH] eliminate redundant close in provide/require processing. CVS patchset: 2286 CVS date: 1998/09/10 15:09:21 --- CHANGES | 1 + build/files.c | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 3ff3b2079..bafba90a7 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ - create /usr/lib/rpm directory and move rpmrc et al there 2.5.3 -> 2.5.4: + - eliminate redundant close in provide/require processing. - solaris portability patch resurrection (Steve Sanberg). - add %license/%readme virtual file attributes - align "Build Host:" with other fields diff --git a/build/files.c b/build/files.c index 39bec0420..131ee842a 100644 --- a/build/files.c +++ b/build/files.c @@ -1431,7 +1431,6 @@ static StringBuf getOutputFrom(char *dir, char *argv[], int failNonZero) { int progPID; - int progDead; int toProg[2]; int fromProg[2]; int status; @@ -1478,12 +1477,7 @@ static StringBuf getOutputFrom(char *dir, char *argv[], readBuff = newStringBuf(); - progDead = 0; do { - if (waitpid(progPID, &status, WNOHANG)) { - progDead = 1; - } - /* Write some stuff to the process if possible */ if (writeBytesLeft) { if ((bytesWritten = @@ -1497,22 +1491,22 @@ static StringBuf getOutputFrom(char *dir, char *argv[], } writeBytesLeft -= bytesWritten; writePtr += bytesWritten; - } else { + } else if (toProg[1] >= 0) { close(toProg[1]); + toProg[1] = -1; } /* Read any data from prog */ - bytes = read(fromProg[0], buf, sizeof(buf)-1); - while (bytes > 0) { + while ((bytes = read(fromProg[0], buf, sizeof(buf)-1)) > 0) { buf[bytes] = '\0'; appendStringBuf(readBuff, buf); - bytes = read(fromProg[0], buf, sizeof(buf)-1); } /* terminate when prog dies */ - } while (!progDead); + } while (!waitpid(progPID, &status, WNOHANG)); - close(toProg[1]); + if (toProg[1] >= 0) + close(toProg[1]); close(fromProg[0]); signal(SIGPIPE, oldhandler);