From nobody Mon Feb 9 16:51:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612178947; cv=none; d=zohomail.com; s=zohoarc; b=eHLDsdS2tqdHD7RwOr00Hi5Y/3T2KynC64/lBm3t/VTvsOLBnCrvRtKW1XFJk7NuN1+vYl2GjWGz0ukMVtVuZWt94nXJaOikoGBwvJDu/rkUO4+FHcTvyAS26YUJ325ABMpSZX1oGvGu6sqLxRr1w+CN3Pk/b+PZbZ+K2p/2uuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178947; h=Content-Type:Content-Transfer-Encoding:Cc: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=Bcj6X3hYSuL5gF3VbULXOrEp3y4PVEqRLn+ewSrQW1o=; b=Joi+Yig1G68meSyF48v6xSPhWu3tVGzFAEfY+A1aM7L1yCB+Y9NPx0yrghgK4W4yVxaCK88KV6umchU0zm+LJfTe8bqULpPvg6YKLG6QZCeKMsf6OaN7ZNGqPNdiY2uDLYppXKVCD9gsN2VZcAAIH0M+DqVyJbMg0ubWJz3rOtY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612178947449653.4988089966357; Mon, 1 Feb 2021 03:29:07 -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-269-SYJpuuLAP-yt1NHu_wuoxQ-1; Mon, 01 Feb 2021 06:28:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E55238049C4; Mon, 1 Feb 2021 11:28:51 +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 C27D15F707; Mon, 1 Feb 2021 11:28:51 +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 8A0851809CB5; Mon, 1 Feb 2021 11:28:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSUmX003362 for ; Mon, 1 Feb 2021 06:28:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1342269324; Mon, 1 Feb 2021 11:28:30 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C9506A90C; Mon, 1 Feb 2021 11:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178946; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Bcj6X3hYSuL5gF3VbULXOrEp3y4PVEqRLn+ewSrQW1o=; b=iLGx6VZTnBwNlzPBNXneZ1m+IMFXLAcYlgqDELNhawR9KYlFk7DaJgrgZEK5Jm7/0yGexp wb9hjGT5XoKZGYVPJlkjuL8DTQvUSL92fa4FJd9/D0JsFEo6VXbHwdRCjrFwHqfU+XJ71M Fnh1BU223MGallgiEc5X01fdb+49fZc= X-MC-Unique: SYJpuuLAP-yt1NHu_wuoxQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/20] commandhelper: Factor out printFds Date: Mon, 1 Feb 2021 12:27:54 +0100 Message-Id: <20210201112804.144366-11-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , Tim Wiederhake 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.16 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 842cc72942..fd45c4fdf7 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -140,10 +140,32 @@ static int printEnvironment(FILE *log) return ret; } =20 +static int printFds(FILE *log) +{ + long int open_max =3D sysconf(_SC_OPEN_MAX); + size_t i; + + if (open_max < 0) + return -1; + + for (i =3D 0; i < open_max; i++) { + int ignore; + + if (i =3D=3D fileno(log)) + continue; + + if (fcntl(i, F_GETFD, &ignore) =3D=3D -1 && errno =3D=3D EBADF) + continue; + + fprintf(log, "FD:%zu\n", i); + } + + return 0; +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); size_t i; - int open_max; char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; @@ -162,19 +184,8 @@ int main(int argc, char **argv) { if (printEnvironment(log) !=3D 0) goto cleanup; =20 - open_max =3D sysconf(_SC_OPEN_MAX); - if (open_max < 0) + if (printFds(log) !=3D 0) goto cleanup; - for (i =3D 0; i < open_max; i++) { - int f; - int closed; - if (i =3D=3D fileno(log)) - continue; - closed =3D fcntl(i, F_GETFD, &f) =3D=3D -1 && - errno =3D=3D EBADF; - if (!closed) - fprintf(log, "FD:%zu\n", i); - } =20 while (true) { bool daemonized =3D getpgrp() !=3D getppid(); --=20 2.26.2