From nobody Sat Feb 7 08:23:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 158021727722586.007401404304; Tue, 28 Jan 2020 05:14:37 -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-300-79x40JIbOj-UmhsqEKobXA-1; Tue, 28 Jan 2020 08:14:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D7F513EE; Tue, 28 Jan 2020 13:14:27 +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 E82B560BFB; Tue, 28 Jan 2020 13:14:26 +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 8B23F85E4E; Tue, 28 Jan 2020 13:14:26 +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 00SDEJiq019690 for ; Tue, 28 Jan 2020 08:14:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8CD261001DE1; Tue, 28 Jan 2020 13:14:19 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id F20321001B08; Tue, 28 Jan 2020 13:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580217276; 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=uyfYzx46L06UowoK00ixuFqBY8D4P//2xDHAuxKZDmM=; b=QdeOxsZpD34kKDL5HZP3G8zuBZ3d1GUl/9c1Qhb9+vkjjBnCtHvzycHAQPAvJxvXe+DNBX VH7Cwgohup/yG+q2oBKdAHt9J4P23WRYuYUqGVlVNtTl0FGd44VVUGbVf44yjwU+hS1lcU gcebGsbJpdHf++Pny5Q6t87L6fp+HxU= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 47/56] src: introduce a wrapper for the pipe2() system call Date: Tue, 28 Jan 2020 13:11:28 +0000 Message-Id: <20200128131137.1762449-48-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.12 X-MC-Unique: 79x40JIbOj-UmhsqEKobXA-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 hides the differences between Windows and UNIX, and adds standard error reporting. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- configure.ac | 1 + src/libvirt_private.syms | 3 ++ src/util/virutil.c | 64 ++++++++++++++++++++++++++++++++++++++++ src/util/virutil.h | 34 +++++++++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/configure.ac b/configure.ac index 0964ab8d51..005753e8a1 100644 --- a/configure.ac +++ b/configure.ac @@ -369,6 +369,7 @@ AC_CHECK_FUNCS_ONCE([\ newlocale \ posix_fallocate \ posix_memalign \ + pipe2 \ prlimit \ sched_getaffinity \ sched_setscheduler \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 674f553403..56981541c5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3394,6 +3394,9 @@ virMemoryLimitTruncate; virMemoryMaxValue; virParseOwnershipIds; virParseVersionString; +virPipe; +virPipeNonBlock; +virPipeQuiet; virScaleInteger; virSetBlocking; virSetCloseExec; diff --git a/src/util/virutil.c b/src/util/virutil.c index fa6b56fd79..d5f3e72ba9 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1769,3 +1769,67 @@ char *virGetPassword(void) return g_strdup(getpass("")); #endif /* ! WIN32 */ } + + +static int +virPipeImpl(int fds[2], bool nonblock, bool errreport) +{ +#ifdef HAVE_PIPE2 + int flags =3D O_CLOEXEC; + if (nonblock) + flags |=3D O_NONBLOCK; + int rv =3D pipe2(fds, flags); +#else /* !HAVE_PIPE2 */ +# ifdef WIN32 + int rv =3D _pipe(fds, 4096, _O_BINARY); +# else /* !WIN32 */ + int rv =3D pipe(fds); +# endif /* !WIN32 */ +#endif /* !HAVE_PIPE2 */ + + if (rv < 0) { + if (errreport) + virReportSystemError(errno, "%s", + _("Unable to create pipes")); + return rv; + } + +#ifndef HAVE_PIPE2 + if (nonblock) { + if (virSetNonBlock(fds[0]) < 0 || + virSetNonBlock(fds[1]) < 0) { + if (errreport) + virReportSystemError(errno, "%s", + _("Unable to set pipes to non-blockin= g")); + virReportSystemError(errno, "%s", + _("Unable to create pipes")); + VIR_FORCE_CLOSE(fds[0]); + VIR_FORCE_CLOSE(fds[1]); + return -1; + } + } +#endif /* !HAVE_PIPE2 */ + + return 0; +} + + +int +virPipe(int fds[2]) +{ + return virPipeImpl(fds, false, true); +} + + +int +virPipeQuiet(int fds[2]) +{ + return virPipeImpl(fds, false, false); +} + + +int +virPipeNonBlock(int fds[2]) +{ + return virPipeImpl(fds, true, true); +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 62a53f34cb..7377c8c8da 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -161,3 +161,37 @@ char *virHostGetDRMRenderNode(void) G_GNUC_NO_INLINE; (((lvalue) =3D (rvalue)) !=3D (rvalue)) =20 char *virGetPassword(void); + +/* + * virPipe: + * + * Open a pair of FDs which can be used to communicate + * with each other. The FDs will have O_CLOEXEC set. + * This will report a libvirt error on failure. + * + * Returns: -1 on error, 0 on success + */ +int virPipe(int fds[2]); + +/* + * virPipeQuiet: + * + * Open a pair of FDs which can be used to communicate + * with each other. The FDs will have O_CLOEXEC set. + * This will set errno on failure. + * + * Returns: -1 on error, 0 on success + */ +int virPipeQuiet(int fds[2]); + +/* + * virPipe: + * + * Open a pair of FDs which can be used to communicate + * with each other. The FDs will have O_CLOEXEC and + * O_NONBLOCK set. + * This will report a libvirt error on failure. + * + * Returns: -1 on error, 0 on success + */ +int virPipeNonBlock(int fds[2]); --=20 2.24.1