default:
{
- int got, exitstatus = 0;
int ret;
char status;
VIR_FORCE_CLOSE(statuspipe[1]);
/* We wait to make sure the first child forked successfully */
- if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
- got != pid ||
- exitstatus != 0) {
+ if (virPidWait(pid, NULL) < 0)
return -1;
- }
/* Now block until the second child initializes successfully */
again:
#include "intprops.h"
#include "conf.h"
#include "rpc/virnettlscontext.h"
+#include "command.h"
#ifndef WITH_DRIVER_MODULES
# ifdef WITH_TEST
#if defined(POLKIT_AUTH)
static int virConnectAuthGainPolkit(const char *privilege) {
- const char *const args[] = {
- POLKIT_AUTH, "--obtain", privilege, NULL
- };
- int childpid, status, ret;
+ virCommandPtr cmd;
+ int status;
+ int ret = -1;
- /* Root has all rights */
if (getuid() == 0)
return 0;
- if ((childpid = fork()) < 0)
- return -1;
-
- if (!childpid) {
- execvp(args[0], (char **)args);
- _exit(-1);
- }
-
- while ((ret = waitpid(childpid, &status, 0) == -1) && errno == EINTR);
- if (ret == -1) {
- return -1;
- }
-
- if (!WIFEXITED(status) ||
- (WEXITSTATUS(status) != 0 && WEXITSTATUS(status) != 1)) {
- return -1;
- }
+ cmd = virCommandNewArgList(POLKIT_AUTH, "--obtain", privilege, NULL);
+ if (virCommandRun(cmd, &status) < 0 ||
+ status > 1)
+ goto cleanup;
- return 0;
+ ret = 0;
+cleanup:
+ virCommandFree(cmd);
+ return ret;
}
#endif
int cpid;
char *childStack;
char *stack;
- int childStatus;
if (features & LXC_CONTAINER_FEATURE_USER)
flags |= CLONE_NEWUSER;
VIR_DEBUG("clone call returned %s, container support is not enabled",
virStrerror(errno, ebuf, sizeof ebuf));
return -1;
- } else {
- waitpid(cpid, &childStatus, 0);
+ } else if (virPidWait(cpid, NULL) < 0) {
+ return -1;
}
VIR_DEBUG("Mounted all filesystems");
#include "virterror_internal.h"
#include "buf.h"
#include "logging.h"
+#include "command.h"
#if TEST_OOM_TRACE
# include <execinfo.h>
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;
}
} 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);