as pointed out by Peter Philipp, there are some problems with
pclose() in sendbug, this code from hwdump() which I borrowed for
usbdevs()..
1 if ((ifp = popen(cmd, "r")) != NULL) {
2 while (!feof(ifp)) {
3 len = fread(buf, 1, sizeof buf, ifp);
4 if (len == 0)
5 break;
6 if (fwrite(buf, 1, len, ofp) != len)
7 break;
8 }
9 pclose(ofp);
10 }
11 pclose(ifp);
- if the popen() fails, it's still trying to pclose(ifp).
- ofp is either stdout or a file descriptor from mkstemp(),
neither of which should be pclose()'d; main() exits if it uses
stdout, or takes care of closing the fd itself.
ok?
Index: sendbug.c
===================================================================
RCS file: /cvs/src/usr.bin/sendbug/sendbug.c,v
retrieving revision 1.65
diff -u -p -u -8 -r1.65 sendbug.c
--- sendbug.c 20 Apr 2010 19:05:03 -0000 1.65
+++ sendbug.c 20 Apr 2010 20:31:08 -0000
@@ -241,19 +241,18 @@ usbdevs(FILE *ofp)
if ((ifp = popen("usbdevs -v", "r")) != NULL) {
while (!feof(ifp)) {
len = fread(buf, 1, sizeof buf, ifp);
if (len == 0)
break;
if (fwrite(buf, 1, len, ofp) != len)
break;
}
- pclose(ofp);
+ pclose(ifp);
}
- pclose(ifp);
}
/*
* Execute an editor on the specified pathname, which is interpreted
* from the shell. This means flags may be included.
*
* Returns -1 on error, or the exit value on success.
*/
@@ -616,19 +615,18 @@ hwdump(FILE *ofp)
if ((ifp = popen(cmd, "r")) != NULL) {
while (!feof(ifp)) {
len = fread(buf, 1, sizeof buf, ifp);
if (len == 0)
break;
if (fwrite(buf, 1, len, ofp) != len)
break;
}
- pclose(ofp);
+ pclose(ifp);
}
- pclose(ifp);
free(cmd);
free(acpidir);
}
void
debase(void)
{
char buf[BUFSIZ];