From nobody Sat Feb 7 08:23:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1580217273230374.1260427616206; Tue, 28 Jan 2020 05:14:33 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-317-CgJZF1FwMI-9SaSxV4txaQ-1; Tue, 28 Jan 2020 08:14:30 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2299801E7B; Tue, 28 Jan 2020 13:14:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86FF35DA7E; Tue, 28 Jan 2020 13:14:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 468BC85E45; Tue, 28 Jan 2020 13:14:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00SDEKUA019697 for ; Tue, 28 Jan 2020 08:14:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6F3CC1001DE1; Tue, 28 Jan 2020 13:14:20 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id D35951001DD8; Tue, 28 Jan 2020 13:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580217272; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tyHoiBYBcTFmDMc1D3YYGHmsh+czCVlbvb5588dAIXc=; b=UdoJoQJm5/Zr/TSgsdlKbE0ujVngrpa7+NIUXOqrPLfzfiXn1LxQAvjwZe0phc8N367eBe VU3a+5vmlMq0szabjtVDoiszKB9GnsF2nX5N5/S1PpmhGwr0/DISVgnlyqcjtNTcuEjIKG HJ8x8FaBO1UW3qiWS+ppa+b3cniPO04= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 48/56] src: convert code to use virPipe APIs Date: Tue, 28 Jan 2020 13:11:29 +0000 Message-Id: <20200128131137.1762449-49-berrange@redhat.com> In-Reply-To: <20200128131137.1762449-1-berrange@redhat.com> References: <20200128131137.1762449-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: CgJZF1FwMI-9SaSxV4txaQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This addreses portability to Windows and standardizes error reporting. This fixes a number of places which failed to set O_CLOEXEC or failed to report errors. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/libxl/libxl_migration.c | 6 ++---- src/locking/lock_daemon.c | 2 +- src/logging/log_daemon.c | 2 +- src/logging/log_handler.c | 6 ++---- src/lxc/lxc_process.c | 5 +---- src/qemu/qemu_migration.c | 25 +++++++++---------------- src/qemu/qemu_tpm.c | 5 +---- src/remote/remote_daemon.c | 2 +- src/rpc/virnetdaemon.c | 5 +---- src/rpc/virnetsocket.c | 5 +---- src/util/vircommand.c | 18 +++++------------- src/util/virfdstream.c | 5 +---- src/util/virfile.c | 5 +---- src/util/virpolkit.c | 2 +- src/util/virprocess.c | 5 +---- tests/commandtest.c | 4 ++-- tests/eventtest.c | 2 +- tests/testutils.c | 2 +- tools/virsh-domain.c | 8 ++++---- tools/vsh.c | 8 +++----- 20 files changed, 40 insertions(+), 82 deletions(-) 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 dco= nn, * 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; =20 /* Stream data will be written to pipeIn */ @@ -916,10 +916,8 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivatePtr dri= ver, =20 tc->dataFD[0] =3D -1; tc->dataFD[1] =3D -1; - if (pipe(tc->dataFD) < 0) { - virReportError(errno, "%s", _("Unable to make pipes")); + if (virPipe(tc->dataFD) < 0) goto out; - } =20 arg =3D &tc->tmThread; /* Read from pipe */ diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 65c38139c4..9c72db93fd 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; =20 pid_t pid =3D fork(); diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 488f3b459d..2ce6eb7447 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; =20 pid_t pid =3D fork(); diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 030c9d66e3..26ccfb4470 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -385,11 +385,9 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handle= r, } } =20 - if (pipe(pipefd) < 0) { - virReportSystemError(errno, "%s", - _("Cannot open fifo pipe")); + if (virPipe(pipefd) < 0) goto error; - } + if (VIR_ALLOC(file) < 0) goto error; =20 diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index af8593d6a5..32a237fadd 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1364,11 +1364,8 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; } =20 - if (pipe(handshakefds) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(handshakefds) < 0) goto cleanup; - } =20 if (!(cmd =3D virLXCProcessBuildControllerCmd(driver, vm, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 76dcd36266..2323008699 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2488,11 +2488,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, goto done; =20 if (tunnel && - (pipe(dataFD) < 0 || virSetCloseExec(dataFD[1]) < 0)) { - virReportSystemError(errno, "%s", - _("cannot create pipe for tunnelled migration= ")); + virPipe(dataFD) < 0) goto stopjob; - } =20 startFlags =3D VIR_QEMU_PROCESS_START_AUTODESTROY; =20 @@ -3245,11 +3242,8 @@ qemuMigrationSrcStartTunnel(virStreamPtr st, qemuMigrationIOThreadPtr io =3D NULL; int wakeupFD[2] =3D { -1, -1 }; =20 - if (pipe2(wakeupFD, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("Unable to make pipe")); + if (virPipe(wakeupFD) < 0) goto error; - } =20 if (VIR_ALLOC(io) < 0) goto error; @@ -3863,10 +3857,12 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driv= er, spec.dest.fd.qemu =3D -1; spec.dest.fd.local =3D -1; =20 - if (pipe2(fds, O_CLOEXEC) =3D=3D 0) { - spec.dest.fd.qemu =3D fds[1]; - spec.dest.fd.local =3D fds[0]; - } + if (virPipe(fds) < 0) + goto cleanup; + + spec.dest.fd.qemu =3D fds[1]; + spec.dest.fd.local =3D fds[0]; + if (spec.dest.fd.qemu =3D=3D -1 || qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, spec.dest.fd.qemu) < 0) { @@ -5228,11 +5224,8 @@ qemuMigrationSrcToFile(virQEMUDriverPtr driver, virD= omainObjPtr vm, return -1; } =20 - if (compressor && pipe(pipeFD) < 0) { - virReportSystemError(errno, "%s", - _("Failed to create pipe for migration")); + if (compressor && virPipe(pipeFD) < 0) return -1; - } =20 /* 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 6741373583..17b800db1c 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -374,11 +374,8 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid, &secret, &secret_len) < 0) goto error; =20 - if (pipe(pipefd) =3D=3D -1) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(pipefd) < 0) goto error; - } =20 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 524ee2cab9..f833cc1024 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; =20 pid_t pid =3D 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 !=3D -1) return 0; =20 - if (pipe2(fds, O_CLOEXEC|O_NONBLOCK) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create signal pipe")); + if (virPipeNonBlock(fds) < 0) return -1; - } =20 if ((dmn->sigwatch =3D 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; } =20 - if (pipe(errfd) < 0) { - virReportSystemError(errno, "%s", - _("unable to create socket pair")); + if (virPipe(errfd) < 0) goto error; - } =20 virCommandSetInputFD(cmd, sv[1]); virCommandSetOutputFD(cmd, &sv[1]); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 26b3488d6b..33028aa963 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -585,11 +585,8 @@ virExec(virCommandPtr cmd) =20 if (cmd->outfdptr !=3D NULL) { if (*cmd->outfdptr =3D=3D -1) { - if (pipe2(pipeout, O_CLOEXEC) < 0) { - virReportSystemError(errno, - "%s", _("cannot create pipe")); + if (virPipe(pipeout) < 0) goto cleanup; - } =20 if ((cmd->flags & VIR_EXEC_NONBLOCK) && virSetNonBlock(pipeout[0]) =3D=3D -1) { @@ -612,11 +609,8 @@ virExec(virCommandPtr cmd) if (cmd->errfdptr =3D=3D cmd->outfdptr) { childerr =3D childout; } else if (*cmd->errfdptr =3D=3D -1) { - if (pipe2(pipeerr, O_CLOEXEC) < 0) { - virReportSystemError(errno, - "%s", _("Failed to create pipe")); + if (virPipe(pipeerr) < 0) goto cleanup; - } =20 if ((cmd->flags & VIR_EXEC_NONBLOCK) && virSetNonBlock(pipeerr[0]) =3D=3D -1) { @@ -2478,9 +2472,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) * virCommandDoAsyncIO. */ if (cmd->inbuf && cmd->infd =3D=3D -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 =3D -1; return -1; } @@ -2724,11 +2716,11 @@ void virCommandRequireHandshake(virCommandPtr cmd) return; } =20 - if (pipe2(cmd->handshakeWait, O_CLOEXEC) < 0) { + if (virPipeQuiet(cmd->handshakeWait) < 0) { cmd->has_error =3D 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 =3D 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; } =20 - if (pipe(pipefds) < 0) { - virReportSystemError(errno, "%s", - _("Unable to create pipe")); + if (virPipe(pipefds) < 0) goto error; - } =20 if (VIR_ALLOC(threadData) < 0) goto error; diff --git a/src/util/virfile.c b/src/util/virfile.c index 96778c61bd..2ab4ccb1d5 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -275,11 +275,8 @@ virFileWrapperFdNew(int *fd, const char *name, unsigne= d int flags) goto error; } =20 - if (pipe2(pipefd, O_CLOEXEC) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to create pipe for %s"), name); + if (virPipe(pipefd) < 0) goto error; - } =20 if (!(iohelper_path =3D 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; =20 - if (pipe2(pipe_fd, 0) < 0) + if (virPipe(pipe_fd) < 0) goto error; =20 if (VIR_ALLOC(agent) < 0) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 60419538e2..e33f5bdc7e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1175,11 +1175,8 @@ virProcessRunInFork(virProcessForkCallback cb, pid_t parent =3D getpid(); int errfd[2] =3D { -1, -1 }; =20 - if (pipe2(errfd, O_CLOEXEC) < 0) { - virReportSystemError(errno, "%s", - _("Cannot create pipe for child")); + if (virPipe(errfd) < 0) return -1; - } =20 if ((child =3D 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 =3D virCommandNew("some/nonexistent/binary"); =20 - 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 =3D g_strdup_printf(TEST27_ERREXPECT_TEMP, buffer0, buffer1, buffer2); =20 - 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 =3D '1'; =20 for (i =3D 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[], c= har **buf, int maxlen) int pipefd[2]; int len; =20 - if (pipe(pipefd) < 0) + if (virPipeQuiet(pipefd) < 0) return -1; =20 pid_t pid =3D fork(); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 04ba44d4f2..a1e2409303 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4422,7 +4422,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose =3D true; =20 - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; =20 data.ctl =3D ctl; @@ -4731,7 +4731,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose =3D true; =20 - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; =20 data.ctl =3D ctl; @@ -5461,7 +5461,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "verbose")) verbose =3D true; =20 - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; =20 data.ctl =3D ctl; @@ -11032,7 +11032,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (pipe(p) < 0) + if (virPipeQuiet(p) < 0) goto cleanup; =20 data.ctl =3D ctl; diff --git a/tools/vsh.c b/tools/vsh.c index 9c58e40d4f..2cf3dab054 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2061,11 +2061,9 @@ vshEventStart(vshControl *ctl, int timeout_ms) =20 assert(ctl->eventPipe[0] =3D=3D -1 && ctl->eventPipe[1] =3D=3D -1 && ctl->eventTimerId >=3D 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; } =20 --=20 2.24.1