waitpid: improve safety

Based on a report by Coverity.  waitpid() can leak resources if it
fails with EINTR, so it should never be used without checking return
status.  But we already have a helper function that does that, so
use it in more places.

* src/lxc/lxc_container.c (lxcContainerAvailable): Use safer
virWaitPid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput, virtTestMain):
Likewise.
* src/libvirt.c (virConnectAuthGainPolkit): Simplify with virCommand.
This commit is contained in:
Eric Blake
2011-10-21 11:09:23 -06:00
parent 2c27dfaeb1
commit 69d044c034
4 changed files with 19 additions and 34 deletions

View File

@@ -33,6 +33,7 @@
#include "virterror_internal.h"
#include "buf.h"
#include "logging.h"
#include "command.h"
#if TEST_OOM_TRACE
# include <execinfo.h>
@@ -309,7 +310,8 @@ virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen)
VIR_FORCE_CLOSE(pipefd[1]);
len = virFileReadLimFD(pipefd[0], maxlen, buf);
VIR_FORCE_CLOSE(pipefd[0]);
waitpid(pid, NULL, 0);
if (virPidWait(pid, NULL) < 0)
return -1;
return len;
}
@@ -674,8 +676,7 @@ int virtTestMain(int argc,
} else {
int i, status;
for (i = 0 ; i < mp ; i++) {
waitpid(workers[i], &status, 0);
if (WEXITSTATUS(status) != EXIT_SUCCESS)
if (virPidWait(workers[i], NULL) < 0)
ret = EXIT_FAILURE;
}
VIR_FREE(workers);