From nobody Mon Nov 25 10:56:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606226655; cv=none; d=zohomail.com; s=zohoarc; b=Wu9u7+MrKqcThMX8Ngeh9MMDmltbzvusDEdlIV6vegbdx6i4Eq+WU7lXYPEiiq1KopAG7e/llil5e5mUoJQn5zWuRv9cdWisgTCn+iOQ/NGqTuFyrWU5z+ncIwKkbO5zVrrnzoA/UyTIpiBmurtU+l7AHIfXMSxUxT0wu8UwZ7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606226655; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v1BbZjRwG4Tay7Z/QAhFTrpNmDmsHoDfZjfIG+QDA88=; b=Ywt1QijPfr75oQAWdk6R5xjTOjt4eRuaieel7I3cnAzPIk0oytRq0AvMrqT1I/1vncfqfcbUivmJwhR5L2RYIJw7eWS35pKNaL7nqXUJ7aaxoYf6poPQZa/gVh6hoNOgzBj04w/JeUUzAItBrzX+Fl6tcud6o9XJtLsLoHhI7Sg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606226655492427.14748517489363; Tue, 24 Nov 2020 06:04:15 -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-208-R6-6uOgDPSCd5bGezyIC1w-1; Tue, 24 Nov 2020 09:02:45 -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 EDC6CAFA88; Tue, 24 Nov 2020 14:02:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C872160C66; Tue, 24 Nov 2020 14:02:39 +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 89FFA1809CA3; Tue, 24 Nov 2020 14:02:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AOE2Z2Z023720 for ; Tue, 24 Nov 2020 09:02:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 95FCA5D9E3; Tue, 24 Nov 2020 14:02:35 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DC385D9CC for ; Tue, 24 Nov 2020 14:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606226652; 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=v1BbZjRwG4Tay7Z/QAhFTrpNmDmsHoDfZjfIG+QDA88=; b=YAxfqOBzQEqH30JoDbHBXnfXEztH9WApGseDTfGNTDWOCUZrMs6BmcKGjlhqLILqZw26TO IeTBTAl7cbVB7HTGkhcQA9RNLc1JugZqhvxlm0HSMh4cv8AoUVQCL+apa/a9fdZyGhA0JK 7e4BEbux3zajYlt88K063hmDJJJpm4Y= X-MC-Unique: R6-6uOgDPSCd5bGezyIC1w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] util: introduce virCommandPassFDIndex Date: Tue, 24 Nov 2020 15:02:25 +0100 Message-Id: <0db55f37a89ef9769de9010c721d91a58257a9e3.1606226180.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Just like virCommandPassFD, but it also returns an index of the passed FD in the FD set. Signed-off-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/vircommand.c | 28 ++++++++++++++++++++++++++-- src/util/vircommand.h | 5 +++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 79a23f34cb..08f16eedb4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1883,6 +1883,7 @@ virCommandNewVAList; virCommandNonblockingFDs; virCommandPassFD; virCommandPassFDGetFDIndex; +virCommandPassFDIndex; virCommandRawStatus; virCommandRequireHandshake; virCommandRun; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 9a4f3d7f32..2b9f28a918 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -999,10 +999,11 @@ virCommandNewVAList(const char *binary, va_list list) VIR_FORCE_CLOSE(fd) =20 /** - * virCommandPassFD: + * virCommandPassFDIndex: * @cmd: the command to modify * @fd: fd to reassign to the child * @flags: extra flags; binary-OR of virCommandPassFDFlags + * @idx: pointer to fill with the index of the FD in the transfer set * * Transfer the specified file descriptor to the child, instead * of closing it on exec. @fd must not be one of the three @@ -1013,7 +1014,7 @@ virCommandNewVAList(const char *binary, va_list list) * should cease using the @fd when this call completes */ void -virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags) +virCommandPassFDIndex(virCommandPtr cmd, int fd, unsigned int flags, size_= t *idx) { int ret =3D 0; =20 @@ -1037,6 +1038,29 @@ virCommandPassFD(virCommandPtr cmd, int fd, unsigned= int flags) VIR_COMMAND_MAYBE_CLOSE_FD(fd, flags); return; } + + if (idx) + *idx =3D cmd->npassfd - 1; +} + +/** + * virCommandPassFD: + * @cmd: the command to modify + * @fd: fd to reassign to the child + * @flags: extra flags; binary-OR of virCommandPassFDFlags + * + * Transfer the specified file descriptor to the child, instead + * of closing it on exec. @fd must not be one of the three + * standard streams. + * + * If the flag VIR_COMMAND_PASS_FD_CLOSE_PARENT is set then fd will + * be closed in the parent no later than Run/RunAsync/Free. The parent + * should cease using the @fd when this call completes + */ +void +virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags) +{ + virCommandPassFDIndex(cmd, fd, flags, NULL); } =20 /* diff --git a/src/util/vircommand.h b/src/util/vircommand.h index e12c88bcc3..0ea6c8229f 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -57,6 +57,11 @@ void virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags) G_GNUC_NO_INLINE; =20 +void virCommandPassFDIndex(virCommandPtr cmd, + int fd, + unsigned int flags, + size_t *idx) G_GNUC_NO_INLINE; + int virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd); =20 --=20 2.26.2