From nobody Sat May 18 14:01:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1693322011; cv=none; d=zohomail.com; s=zohoarc; b=Mi2GzsYoyPxlVVXmRCjuu1etm54vfcc6zlXMF0z3byRcpos+8gUIjc2ozEikquuKlzI+X/neqvfI8N/BOlR/ILIGhl5D0NUnBy1GzN9woexJYWNtJZ/22HkpGN9y2Zq59Qh60xSzWZvQJFsfzwkmhlFUhn3YBINZkJd3CmBJzmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693322011; 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=H3tCeW1vLR2mmjY6ccE6CbQRsvBvY43E8QPsTrd5xrk=; b=lLwLlQ6xisz4MAUwdFX3EcyigC3pwRtCJtoGAcDcG4dCqU0pEltnQWq0TMocRTXze04GTDYDssDhNMlVu8wce9mEtbsMYiX7J4YDSWDsI8U3xHJwiJ38Q19mLDtS1YHTBvMx7ibosqy0jyqeF1j5AVTvsUwawqoM9ucj8bgblQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1693322011406202.7552897603756; Tue, 29 Aug 2023 08:13:31 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-60-UppzSeOEPTqelcdYVjDrBw-1; Tue, 29 Aug 2023 11:13:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2EA11C068ED; Tue, 29 Aug 2023 15:13:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CABD40C2063; Tue, 29 Aug 2023 15:13:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BAB6319451D0; Tue, 29 Aug 2023 15:13:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4015F19465B6 for ; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2181240C2070; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD44640C2063 for ; Tue, 29 Aug 2023 15:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693322010; 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=H3tCeW1vLR2mmjY6ccE6CbQRsvBvY43E8QPsTrd5xrk=; b=cCvpnhCV3WfyRb0U0jxjhxG6a8fhPqOSxsNQGoKzUGs8Y9gStHQS3mUqRj3p7vzQ09TlvH 2WowfXH7SAlGJX2sQefDHz5FRoeOtrzZITVrjy6otNBt4yJcPhzRDiIz/95xRpIMtDwcD9 VWa9l6LZc9PomlrtgBIt/lEErtBAeBs= X-MC-Unique: UppzSeOEPTqelcdYVjDrBw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] vircommand: Drop unused arguments from virCommandMassCloseGetFDs*() Date: Tue, 29 Aug 2023 17:13:06 +0200 Message-ID: <2cb0a9c461309bda546ad18bcafb888fc46c87fe.1693321948.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693322013132100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Both virCommandMassCloseGetFDsLinux() and virCommandMassCloseGetFDsGeneric() take @cmd argument only to mark it as unused. Drop it from both. Signed-off-by: Michal Privoznik --- src/util/vircommand.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 5f094c625a..60d419a695 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -485,8 +485,7 @@ virExecCommon(virCommand *cmd, gid_t *groups, int ngrou= ps) * onto child process (well, the one we will exec soon since this * is called from the child). */ static int -virCommandMassCloseGetFDsLinux(virCommand *cmd G_GNUC_UNUSED, - virBitmap *fds) +virCommandMassCloseGetFDsLinux(virBitmap *fds) { g_autoptr(DIR) dp =3D NULL; struct dirent *entry; @@ -518,8 +517,7 @@ virCommandMassCloseGetFDsLinux(virCommand *cmd G_GNUC_U= NUSED, # else /* !__linux__ */ =20 static int -virCommandMassCloseGetFDsGeneric(virCommand *cmd G_GNUC_UNUSED, - virBitmap *fds) +virCommandMassCloseGetFDsGeneric(virBitmap *fds) { virBitmapSetAll(fds); return 0; @@ -554,10 +552,10 @@ virCommandMassCloseFrom(virCommand *cmd, fds =3D virBitmapNew(openmax); =20 # ifdef __linux__ - if (virCommandMassCloseGetFDsLinux(cmd, fds) < 0) + if (virCommandMassCloseGetFDsLinux(fds) < 0) return -1; # else - if (virCommandMassCloseGetFDsGeneric(cmd, fds) < 0) + if (virCommandMassCloseGetFDsGeneric(fds) < 0) return -1; # endif =20 --=20 2.41.0 From nobody Sat May 18 14:01:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1693322016; cv=none; d=zohomail.com; s=zohoarc; b=YcQpbxHtlBIHoeXODrUZLJ6/EukAVTRupQJ/XU9iTRa1w4Yw9WbpmPHbUQTwm686lKD8IZi0eBFaBE1FQ6TF6NNo2KFqixWMXSYL3OlJzMuJcXW8f9tC7CSyBeq33vNPAnCNqdIl7tJyNRkuUVJPM01WeSdP1uzDqLI8TFTMhkc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693322016; 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=ZbzHMuFXV5bk9C7XSz9o7k7ZKPruD2bwADOSpJDEsTs=; b=SxSWGYBFgk8Z2EV/h8XQpm+0KrpUTDhBPIvO0QdVq8S++4jOEmu/ODz0OsFliUzRj6ujQmPqzvC/C/eGOVpAcfNZh+AVSKlnqaApKg6V5NkzJxB3FMIRrYDdCLym6b8AS5fAaxIdnKD70SLWB5NJTy0U/eQFkefG2w1Z5OfbBlI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1693322016615533.659472657974; Tue, 29 Aug 2023 08:13:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-bsEEQc4nMxeF7h9G0oe6ng-1; Tue, 29 Aug 2023 11:13:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5847D38149A7; Tue, 29 Aug 2023 15:13:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46D821121318; Tue, 29 Aug 2023 15:13:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D7EA419452C5; Tue, 29 Aug 2023 15:13:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CF4BE19465B6 for ; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B035540C2070; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 584D740C2063 for ; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693322015; 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=ZbzHMuFXV5bk9C7XSz9o7k7ZKPruD2bwADOSpJDEsTs=; b=TaW/5vgDKtWOefutUejBeDlR2w4nwAOc5IvbNpxPf/uPFQrU0P6tcMUYdcYo8/WLjfL2px H1UmDx0wUECZH+XCOrgooKuoS+wtRK3y+UBk0GsIQuxrHCCGQeVlgqTaW7klux0Bm0cDdW TpIfdqWdoOf/J4ghjibeTIuQ3MqBu9w= X-MC-Unique: bsEEQc4nMxeF7h9G0oe6ng-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] vircommand: Isolate FD dir parsing into a separate function Date: Tue, 29 Aug 2023 17:13:07 +0200 Message-ID: <0b96f34da10164f714a35458ea948efb1623c064.1693321948.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693322018627100001 Content-Type: text/plain; charset="utf-8"; x-default="true" So far, virCommandMassCloseGetFDsLinux() opens "/proc/self/fd", iterates over it marking opened FDs in @fds bitmap. Well, we can do the same on other systems (with altered path), like MacOS or FreeBSD. Therefore, isolate dir iteration into a separate function that accepts dir path as an argument. Unfortunately, this function might be unused on some systems (e.g. mingw), therefore mark it as such. Signed-off-by: Michal Privoznik --- src/util/vircommand.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 60d419a695..822b9487f9 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -479,17 +479,12 @@ virExecCommon(virCommand *cmd, gid_t *groups, int ngr= oups) return 0; } =20 -# ifdef __linux__ -/* On Linux, we can utilize procfs and read the table of opened - * FDs and selectively close only those FDs we don't want to pass - * onto child process (well, the one we will exec soon since this - * is called from the child). */ -static int -virCommandMassCloseGetFDsLinux(virBitmap *fds) +static int G_GNUC_UNUSED +virCommandMassCloseGetFDsDir(virBitmap *fds, + const char *dirName) { g_autoptr(DIR) dp =3D NULL; struct dirent *entry; - const char *dirName =3D "/proc/self/fd"; int rc; =20 if (virDirOpen(&dp, dirName) < 0) @@ -514,15 +509,20 @@ virCommandMassCloseGetFDsLinux(virBitmap *fds) return 0; } =20 -# else /* !__linux__ */ - static int -virCommandMassCloseGetFDsGeneric(virBitmap *fds) +virCommandMassCloseGetFDs(virBitmap *fds) { +# ifdef __linux__ + /* On Linux, we can utilize procfs and read the table of opened + * FDs and selectively close only those FDs we don't want to pass + * onto child process (well, the one we will exec soon since this + * is called from the child). */ + return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd"); +# else virBitmapSetAll(fds); return 0; +# endif } -# endif /* !__linux__ */ =20 static int virCommandMassCloseFrom(virCommand *cmd, @@ -551,13 +551,8 @@ virCommandMassCloseFrom(virCommand *cmd, =20 fds =3D virBitmapNew(openmax); =20 -# ifdef __linux__ - if (virCommandMassCloseGetFDsLinux(fds) < 0) + if (virCommandMassCloseGetFDs(fds) < 0) return -1; -# else - if (virCommandMassCloseGetFDsGeneric(fds) < 0) - return -1; -# endif =20 lastfd =3D MAX(lastfd, childin); lastfd =3D MAX(lastfd, childout); --=20 2.41.0 From nobody Sat May 18 14:01:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1693322006; cv=none; d=zohomail.com; s=zohoarc; b=alyP1cHtcauHPGMKYc0QnZtFDnQuorDsqJDWuxwWtu89yTBcGxbKKSQNJ1pKMJlNM3qSm66jBWWE+pRpaH2GnzPc/1SQJ+wWAxTJk/7Lit/nJrRjO7Pmj4YVFbdyjxX/uTY5JM+spQHsIjKEkyv+bLYsDt6v2TrOp/4yvO6JiFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693322006; 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=CeOOBTXCU6HJ4WmQKeD8LqH4RbLouqtlOC8NZcPgp/U=; b=fH3HdCwuPJbhhMEie4q+La2QUZ4yHdpODrVq312Wcw7SrjSC0fUtUYxz7wCpiK9A32PCcdv3dlzuqRSmf6vBrpATzGd1iaLJU1ANbChQxMe7f1N6Dt5Sk6AcLt5goQyIUFxFXnzgxipmm+CAb898x38yXuzGWkeeeXLJl9a1wjs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1693322006464803.2019115855717; Tue, 29 Aug 2023 08:13:26 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-70-g8NK0al-OlmogPfrN2J28A-1; Tue, 29 Aug 2023 11:13:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 374AE87D285; Tue, 29 Aug 2023 15:13:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F002166B26; Tue, 29 Aug 2023 15:13:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 62E911946A43; Tue, 29 Aug 2023 15:13:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5C27119452CB for ; Tue, 29 Aug 2023 15:13:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4BA5640C2070; Tue, 29 Aug 2023 15:13:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id E720C40C2063 for ; Tue, 29 Aug 2023 15:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693322005; 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=CeOOBTXCU6HJ4WmQKeD8LqH4RbLouqtlOC8NZcPgp/U=; b=Tzatadb6reFNoc+R17fsf4y1Io9PwuMy+HiHRrH5DnUibyzgAQNE9JgLxH+hiWQqeQQ6a/ Bu1oEaKLUYeWjDa7jldWSubFa5mKhHATZQDrwUk/AifIzRPB2bvbwjkoSeOyej2YEkDhez gFbCwGQkbMPobghRMs2FGSHrmDeaWSM= X-MC-Unique: g8NK0al-OlmogPfrN2J28A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] vircommand: Make sysconf(_SC_OPEN_MAX) failure non-fatal Date: Tue, 29 Aug 2023 17:13:08 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693322008455100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The point of calling sysconf(_SC_OPEN_MAX) is to allocate big enough bitmap so that subsequent call to virCommandMassCloseGetFDsDir() can just set the bit instead of expanding memory (this code runs in a forked off child and thus using async-signal-unsafe functions like malloc() is a bit tricky). But on some systems the limit for opened FDs is virtually non-existent (typically macOS Ventura started reporting EINVAL). But with both glibc and musl using malloc() after fork() is safe. And with sufficiently new glib too, as it's using malloc() with newer releases instead of their own allocator. Therefore, pick a sufficiently large value (glibc falls back to 256, [1], so 1024 should be good enough) to fall back to and make the error non-fatal. 1: https://sourceware.org/git/?p=3Dglibc.git;a=3Dblob;f=3Dsysdeps/unix/sysv= /linux/getdtsz.c;h=3D4c5a6208067d2f9eaaac6dba652702fb4af9b7e3;hb=3DHEAD Signed-off-by: Michal Privoznik --- src/util/vircommand.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 822b9487f9..8c06e19723 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -500,7 +500,7 @@ virCommandMassCloseGetFDsDir(virBitmap *fds, return -1; } =20 - ignore_value(virBitmapSetBit(fds, fd)); + virBitmapSetBitExpand(fds, fd); } =20 if (rc < 0) @@ -544,10 +544,8 @@ virCommandMassCloseFrom(virCommand *cmd, * Therefore we can safely allocate memory here (and transitively call * opendir/readdir) without a deadlock. */ =20 - if (openmax < 0) { - virReportSystemError(errno, "%s", _("sysconf(_SC_OPEN_MAX) failed"= )); - return -1; - } + if (openmax <=3D 0) + openmax =3D 1024; =20 fds =3D virBitmapNew(openmax); =20 --=20 2.41.0 From nobody Sat May 18 14:01:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1693322009; cv=none; d=zohomail.com; s=zohoarc; b=mOeV/B8CI8pnA6cSLkNLJjLmjT3CTRJaPrXEgSHqo85JyYFT5+bZqzRYEt3C+0SbX25IXcngelEzoWq4IGURcSzXs+VWfJ3mhEMXbT8DzzrkbqKTPUPnmqM2xl7HnZf0H1FytNxBlcBQEWqBH3+Rhvw0HvONqLNa7rJCV3a2/9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693322009; 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=e800CE9YRmY5o3EskC2n2Wb9JYDeK+jU7slDX0lEfDA=; b=oAaugJp0a0cRcu/7NAHvT1V/uhPjErplGDwf2E2TXVhnwKx1tSQPOPD8DZmKJ5jXvF2Q2cLy1v/KKxaFra9fIb15AB3HqyvYd2ShECGS7VKSAu5vbdCGKGbk2XQcmAm3kV7VECGkgW6SGzfOjpKIedzpYR7Qk9/O9dCmTtE+MsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1693322009591195.9923431588553; Tue, 29 Aug 2023 08:13:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-LvnXiU7iPx-e9XS4CCs4GQ-1; Tue, 29 Aug 2023 11:13:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFC52802C1E; Tue, 29 Aug 2023 15:13:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDEB22166B27; Tue, 29 Aug 2023 15:13:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9A3BA19451C7; Tue, 29 Aug 2023 15:13:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EF55119465B6 for ; Tue, 29 Aug 2023 15:13:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DAB1D40C2063; Tue, 29 Aug 2023 15:13:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 820CB40C2070 for ; Tue, 29 Aug 2023 15:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693322008; 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=e800CE9YRmY5o3EskC2n2Wb9JYDeK+jU7slDX0lEfDA=; b=hM/Oe9u99PVOAEqGxC/vnkgfYnhDX9egFpp5EdFQ8UAhJ3rj7/wXkjfIFC3OMEmEduTMgG ZzwihA+je3SyieuC+3Ss3XdWXmSb5v2weTUrr69MGKasVyY/OB9Iu/FDuunMl/2SV58vKj oOm6sYcGewV9M78UvwDwENTkI4LKI2g= X-MC-Unique: LvnXiU7iPx-e9XS4CCs4GQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs Date: Tue, 29 Aug 2023 17:13:09 +0200 Message-ID: <720db08aa2243b6a5012cd424130c620b4529ae3.1693321948.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693322010497100003 Content-Type: text/plain; charset="utf-8"; x-default="true" On BSD-like systems "/dev/fd" serves the same purpose as "/proc/self/fd". And since procfs is usually not mounted, on such systems we can use "/dev/fd" instead. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/518 Signed-off-by: Michal Privoznik --- src/util/vircommand.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8c06e19723..2b3b125e5f 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -518,6 +518,8 @@ virCommandMassCloseGetFDs(virBitmap *fds) * onto child process (well, the one we will exec soon since this * is called from the child). */ return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd"); +# elif defined(__APPLE__) || defined(__FreeBSD__) + return virCommandMassCloseGetFDsDir(fds, "/dev/fd"); # else virBitmapSetAll(fds); return 0; --=20 2.41.0