mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user