diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 404c437a22..873b2b3e01 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -584,7 +584,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn, * The data flow of tunnel3 migration in the dest side: * stream -> pipe -> recvfd of libxlDomainStartRestore */ - if (pipe(dataFD) < 0) + if (virPipe(dataFD) < 0) goto endjob; /* Stream data will be written to pipeIn */ @@ -916,10 +916,8 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivatePtr driver, tc->dataFD[0] = -1; tc->dataFD[1] = -1; - if (pipe(tc->dataFD) < 0) { - virReportError(errno, "%s", _("Unable to make pipes")); + if (virPipe(tc->dataFD) < 0) goto out; - } arg = &tc->tmThread; /* Read from pipe */ diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index fd376fef2a..5e5a0c1089 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -356,7 +356,7 @@ static int virLockDaemonForkIntoBackground(const char *argv0) { int statuspipe[2]; - if (pipe(statuspipe) < 0) + if (virPipeQuiet(statuspipe) < 0) return -1; pid_t pid = fork(); diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 97be2be0a1..772bbb805b 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -298,7 +298,7 @@ static int virLogDaemonForkIntoBackground(const char *argv0) { int statuspipe[2]; - if (pipe(statuspipe) < 0) + if (virPipeQuiet(statuspipe) < 0) return -1; pid_t pid = fork(); diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 973c52c7cd..f21cac68ac 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -385,11 +385,9 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, } } - if (pipe(pipefd) < 0) { - virReportSystemError(errno, "%s", - _("Cannot open fifo pipe")); + if (virPipe(pipefd) < 0) goto error; - } + if (VIR_ALLOC(file) < 0) goto error; diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index da2541e684..da6df86834 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1363,11 +1363,8 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; } - if (pipe(handshakefds) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(handshakefds) < 0) goto cleanup; - } if (!(cmd = virLXCProcessBuildControllerCmd(driver, vm, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9320985648..ceac81c960 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2533,11 +2533,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, goto done; if (tunnel && - (pipe(dataFD) < 0 || virSetCloseExec(dataFD[1]) < 0)) { - virReportSystemError(errno, "%s", - _("cannot create pipe for tunnelled migration")); + virPipe(dataFD) < 0) goto stopjob; - } startFlags = VIR_QEMU_PROCESS_START_AUTODESTROY; @@ -3290,11 +3287,8 @@ qemuMigrationSrcStartTunnel(virStreamPtr st, qemuMigrationIOThreadPtr io = NULL; int wakeupFD[2] = { -1, -1 }; - if (pipe2(wakeupFD, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("Unable to make pipe")); + if (virPipe(wakeupFD) < 0) goto error; - } if (VIR_ALLOC(io) < 0) goto error; @@ -3908,10 +3902,12 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driver, spec.dest.fd.qemu = -1; spec.dest.fd.local = -1; - if (pipe2(fds, O_CLOEXEC) == 0) { - spec.dest.fd.qemu = fds[1]; - spec.dest.fd.local = fds[0]; - } + if (virPipe(fds) < 0) + goto cleanup; + + spec.dest.fd.qemu = fds[1]; + spec.dest.fd.local = fds[0]; + if (spec.dest.fd.qemu == -1 || qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, spec.dest.fd.qemu) < 0) { @@ -5273,11 +5269,8 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virDomainObjPtr vm, return -1; } - if (compressor && pipe(pipeFD) < 0) { - virReportSystemError(errno, "%s", - _("Failed to create pipe for migration")); + if (compressor && virPipe(pipeFD) < 0) return -1; - } /* All right! We can use fd migration, which means that qemu * doesn't have to open() the file, so while we still have to diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index f3562d7dfe..58dfdf689a 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -366,11 +366,8 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid, &secret, &secret_len) < 0) goto error; - if (pipe(pipefd) == -1) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(pipefd) < 0) goto error; - } if (virCommandSetSendBuffer(cmd, pipefd[1], secret, secret_len) < 0) goto error; diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index e0cd303582..7082460bae 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -113,7 +113,7 @@ VIR_ENUM_IMPL(virDaemonErr, static int daemonForkIntoBackground(const char *argv0) { int statuspipe[2]; - if (pipe(statuspipe) < 0) + if (virPipeQuiet(statuspipe) < 0) return -1; pid_t pid = fork(); diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index aa77e984ab..7f2226b086 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -671,11 +671,8 @@ virNetDaemonSignalSetup(virNetDaemonPtr dmn) if (dmn->sigwrite != -1) return 0; - if (pipe2(fds, O_CLOEXEC|O_NONBLOCK) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create signal pipe")); + if (virPipeNonBlock(fds) < 0) return -1; - } if ((dmn->sigwatch = virEventAddHandle(fds[0], VIR_EVENT_HANDLE_READABLE, diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 07733cee48..494b548948 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -794,11 +794,8 @@ int virNetSocketNewConnectCommand(virCommandPtr cmd, goto error; } - if (pipe(errfd) < 0) { - virReportSystemError(errno, "%s", - _("unable to create socket pair")); + if (virPipe(errfd) < 0) goto error; - } virCommandSetInputFD(cmd, sv[1]); virCommandSetOutputFD(cmd, &sv[1]); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 0dc0796b40..904a3023c5 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -585,11 +585,8 @@ virExec(virCommandPtr cmd) if (cmd->outfdptr != NULL) { if (*cmd->outfdptr == -1) { - if (pipe2(pipeout, O_CLOEXEC) < 0) { - virReportSystemError(errno, - "%s", _("cannot create pipe")); + if (virPipe(pipeout) < 0) goto cleanup; - } if ((cmd->flags & VIR_EXEC_NONBLOCK) && virSetNonBlock(pipeout[0]) == -1) { @@ -612,11 +609,8 @@ virExec(virCommandPtr cmd) if (cmd->errfdptr == cmd->outfdptr) { childerr = childout; } else if (*cmd->errfdptr == -1) { - if (pipe2(pipeerr, O_CLOEXEC) < 0) { - virReportSystemError(errno, - "%s", _("Failed to create pipe")); + if (virPipe(pipeerr) < 0) goto cleanup; - } if ((cmd->flags & VIR_EXEC_NONBLOCK) && virSetNonBlock(pipeerr[0]) == -1) { @@ -2478,9 +2472,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) * virCommandDoAsyncIO. */ if (cmd->inbuf && cmd->infd == -1 && (synchronous || cmd->flags & VIR_EXEC_ASYNC_IO)) { - if (pipe2(infd, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("unable to open pipe")); + if (virPipe(infd) < 0) { cmd->has_error = -1; return -1; } @@ -2724,11 +2716,11 @@ void virCommandRequireHandshake(virCommandPtr cmd) return; } - if (pipe2(cmd->handshakeWait, O_CLOEXEC) < 0) { + if (virPipeQuiet(cmd->handshakeWait) < 0) { cmd->has_error = errno; return; } - if (pipe2(cmd->handshakeNotify, O_CLOEXEC) < 0) { + if (virPipeQuiet(cmd->handshakeNotify) < 0) { VIR_FORCE_CLOSE(cmd->handshakeWait[0]); VIR_FORCE_CLOSE(cmd->handshakeWait[1]); cmd->has_error = errno; diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 1354d2ee52..3337fc2060 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -1274,11 +1274,8 @@ virFDStreamOpenFileInternal(virStreamPtr st, goto error; } - if (pipe(pipefds) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(pipefds) < 0) goto error; - } if (VIR_ALLOC(threadData) < 0) goto error; diff --git a/src/util/virfile.c b/src/util/virfile.c index a757dfcbdd..1da4d17b2d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -275,11 +275,8 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags) goto error; } - if (pipe2(pipefd, O_CLOEXEC) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to create pipe for %s"), name); + if (virPipe(pipefd) < 0) goto error; - } if (!(iohelper_path = virFileFindResource("libvirt_iohelper", abs_top_builddir "/src", diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index 0db7bf0747..5c2d0d4bd4 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -171,7 +171,7 @@ virPolkitAgentCreate(void) if (!isatty(STDIN_FILENO)) goto error; - if (pipe2(pipe_fd, 0) < 0) + if (virPipe(pipe_fd) < 0) goto error; if (VIR_ALLOC(agent) < 0) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 23e149def4..436172590e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1174,11 +1174,8 @@ virProcessRunInFork(virProcessForkCallback cb, pid_t parent = getpid(); int errfd[2] = { -1, -1 }; - if (pipe2(errfd, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("Cannot create pipe for child")); + if (virPipe(errfd) < 0) return -1; - } if ((child = virFork()) < 0) goto cleanup; diff --git a/tests/commandtest.c b/tests/commandtest.c index 7df3ae0171..ae2598d5fd 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1019,7 +1019,7 @@ static int test25(const void *unused G_GNUC_UNUSED) int ngroups; virCommandPtr cmd = virCommandNew("some/nonexistent/binary"); - if (pipe(pipeFD) < 0) { + if (virPipeQuiet(pipeFD) < 0) { fprintf(stderr, "Unable to create pipe\n"); goto cleanup; } @@ -1187,7 +1187,7 @@ static int test27(const void *unused G_GNUC_UNUSED) errexpect = g_strdup_printf(TEST27_ERREXPECT_TEMP, buffer0, buffer1, buffer2); - if (pipe(pipe1) < 0 || pipe(pipe2) < 0) { + if (virPipeQuiet(pipe1) < 0 || virPipeQuiet(pipe2) < 0) { printf("Could not create pipe: %s\n", g_strerror(errno)); goto cleanup; } diff --git a/tests/eventtest.c b/tests/eventtest.c index 1bda5efe6d..9855b578fb 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -321,7 +321,7 @@ mymain(void) char one = '1'; for (i = 0; i < NUM_FDS; i++) { - if (pipe(handles[i].pipeFD) < 0) { + if (virPipeQuiet(handles[i].pipeFD) < 0) { fprintf(stderr, "Cannot create pipe: %d", errno); return EXIT_FAILURE; } diff --git a/tests/testutils.c b/tests/testutils.c index 579b6fce1a..7b9a5ea05b 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -377,7 +377,7 @@ virTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen) int pipefd[2]; int len; - if (pipe(pipefd) < 0) + if (virPipeQuiet(pipefd) < 0) return -1; pid_t pid = fork(); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 32b2792694..781463f0e2 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4423,7 +4423,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose = true; - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; data.ctl = ctl; @@ -4732,7 +4732,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose = true; - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; data.ctl = ctl; @@ -5462,7 +5462,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose = true; - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; data.ctl = ctl; @@ -11033,7 +11033,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; data.ctl = ctl; diff --git a/tools/vsh.c b/tools/vsh.c index 02a6b6c955..ef4cf5c6bd 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2061,11 +2061,9 @@ vshEventStart(vshControl *ctl, int timeout_ms) assert(ctl->eventPipe[0] == -1 && ctl->eventPipe[1] == -1 && ctl->eventTimerId >= 0); - if (pipe2(ctl->eventPipe, O_CLOEXEC) < 0) { - char ebuf[1024]; - - vshError(ctl, _("failed to create pipe: %s"), - virStrerror(errno, ebuf, sizeof(ebuf))); + if (virPipe(ctl->eventPipe) < 0) { + vshSaveLibvirtError(); + vshReportError(ctl); return -1; }