From nobody Sun Feb 8 19:25:14 2026 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=1637449834; cv=none; d=zohomail.com; s=zohoarc; b=QsM40ZyNmVuT/TcuiV2Ml4qrhdyN1BNwZM4JVcF3huC2UcmDCJW/XgkVYh1bhrMIOIGQNYaUwJTP0CEunj3e4N0LNJV0AywfGg4DeVDmrovPnoZ6wSHwtoFncOJPm+zWuNWyBT7rGlfTiE0WQB8oW/sdz9olAkHFbFHmp+J/a7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637449834; 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=5d+HmZnIDt/Xboc95t1lhO1qiEHkWUiIrUnZhoszi1M=; b=E4Q01aZLfQKRy+VvUf7cdaQwnauGmpgI5V5ZSBxIESaW9wsLegLT6sjRP+EDk6LLmib46EH1r+usRrIsC26F7TJsStshBh/ajHfc8Q2uW01UqwWch2FWjj6o1HO1xnpcynD/7KporybYgWIX78Y0kZGWpUaHnA40/U4gU02sw+8= 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 1637449834614766.4764795632393; Sat, 20 Nov 2021 15:10:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-132-8-S1hfaCPJyRQ4QuAk626g-1; Sat, 20 Nov 2021 18:10:30 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F17018125C1; Sat, 20 Nov 2021 23:10:25 +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 61B2018A8F; Sat, 20 Nov 2021 23:10:25 +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 091544E590; Sat, 20 Nov 2021 23:10:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1AKNAM5U001715 for ; Sat, 20 Nov 2021 18:10:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id B6BB02166B3F; Sat, 20 Nov 2021 23:10:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0C362166B2D for ; Sat, 20 Nov 2021 23:10:19 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C540485A5A8 for ; Sat, 20 Nov 2021 23:10:19 +0000 (UTC) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205--TOuyU4QM-iIKdniP2wQnA-1; Sat, 20 Nov 2021 18:10:18 -0500 Received: by mail-ed1-f69.google.com with SMTP id w18-20020a056402071200b003e61cbafdb4so11494015edx.4 for ; Sat, 20 Nov 2021 15:10:18 -0800 (PST) Received: from carol.localdomain (k8r.cz. [95.82.177.71]) by smtp.gmail.com with ESMTPSA id e15sm1769031edq.46.2021.11.20.15.10.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Nov 2021 15:10:16 -0800 (PST) Received: from carol.redhat.com (carol.k8r.cz [IPv6:::1]) by carol.localdomain (Postfix) with ESMTP id 26B82C2004F for ; Sun, 21 Nov 2021 00:10:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637449833; 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=5d+HmZnIDt/Xboc95t1lhO1qiEHkWUiIrUnZhoszi1M=; b=JrtDs7JiOH1XUq4Zu56O4SkqTdtNy9yOC9Z2nSLvJgfOcgx+y0ICE1rQ2lJlMXYzPSoDU+ QUFVpvul791pUEgM48MMbom+4yWQuOpJFMPwuT9yrb/jRRJpH5X/V9OoiUgT3fLacl/v1w MAgWoATUepJOSYLqqa37mXbhK3RxoKA= X-MC-Unique: 8-S1hfaCPJyRQ4QuAk626g-1 X-MC-Unique: -TOuyU4QM-iIKdniP2wQnA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5d+HmZnIDt/Xboc95t1lhO1qiEHkWUiIrUnZhoszi1M=; b=4jXBDsHLj/jkRWGx7NQMnuv0LAUL1r4Q2KdRV5HNwUd7oSqfRQz8M6KW+/wJFpoRVu F1/LyWh1GVMznPn3I9adVfh+HMgwFQ0x+wbtSX1cP+7gbSL9Q0uRpy0JRFq4fZEpe6Ou CANyRolBnPuuREAi+rMLtg1Q9Zb/KADZoZyvlp89Gngr9x84V0oVZ8M+Rf3wggqCra0/ +5+rdeOy1QhsniYdjE6h5rHQ/U6cc32akI6zbmHo595TntPBW8BMnpvAlgNQ145H0Ocm 581kNLBIk8/4lG/N66L2FC9tAYPBNWA16qrwdGJBhAPa2KvqBtFc7zyB2RyzbcPxMxkI wReg== X-Gm-Message-State: AOAM531JYRkNbuNVd5fjiQYTxZ7ABYYiUg9jTTub1rtelF1Yq1T5290f M8mStmnbMkK1zQSiQz22EFFW0eTZ8ez/480xmLBHSnLOVu3pKWDMKfPDEYKBXZxAoiovas6SPKT tcXm2CkBJOrv+076WaPk6zUnWoOJd15EdHNyo+DmiMVtgFH5o+1NEBtj19xg6Bb1q2uIMcwQ= X-Received: by 2002:a17:907:2da3:: with SMTP id gt35mr23900576ejc.314.1637449817316; Sat, 20 Nov 2021 15:10:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3nozkVmw12wA/auo8rIl+CTqeZ3N5lrlTf+xmW+aGpg31dkXQspqdkvlKl8ml3l+nBHXf8w== X-Received: by 2002:a17:907:2da3:: with SMTP id gt35mr23900533ejc.314.1637449817045; Sat, 20 Nov 2021 15:10:17 -0800 (PST) From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH 3/7] util: Add virPolkitAgentAvailable Date: Sun, 21 Nov 2021 00:10:04 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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.11 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) X-ZM-MESSAGEID: 1637449836644100003 Content-Type: text/plain; charset="utf-8" With this function we can decide whether to try running the polkit text age= nt only if it is available, removing a potential needless error saying that the agent binary does not exist, which is useful especially when running the ag= ent before knowing whether it is going to be needed. Signed-off-by: Martin Kletzander --- src/libvirt_private.syms | 1 + src/util/virpolkit.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/util/virpolkit.h | 1 + 3 files changed, 46 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a7bc50a4d16d..c11be4eafa19 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3078,6 +3078,7 @@ virPidFileWritePath; =20 =20 # util/virpolkit.h +virPolkitAgentAvailable; virPolkitAgentCreate; virPolkitAgentDestroy; virPolkitCheckAuth; diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index 86255a96760f..3b333547d70b 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -20,6 +20,7 @@ */ =20 #include +#include #include =20 #include "virpolkit.h" @@ -217,6 +218,42 @@ virPolkitAgentCreate(void) } =20 =20 +/* + * virPolkitAgentAvailable + * + * This function does some preliminary checking that the pkttyagent does n= ot + * fail starting so that it can be started without waiting for first failed + * connection with VIR_ERR_AUTH_UNAVAILABLE. + */ +bool +virPolkitAgentAvailable(void) +{ + const char *termid =3D ctermid(NULL); + VIR_AUTOCLOSE fd =3D -1; + + if (!virFileExists(PKTTYAGENT)) + return false; + + if (!termid) + return false; + + /* + *The pkttyagent needs to open the controlling terminal. + * + * Just in case we are running without a ctty make sure this open() do= es not + * change that. + * + * We could check if our session has a controlling terminal available + * instead, but it would require parsing `/proc/self/stat` on Linux, w= hich + * is not portable and moreover requires way more work than just open(= ). + */ + fd =3D open(termid, O_RDWR | O_NOCTTY); + if (fd < 0) + return false; + + return true; +} + #else /* ! WITH_POLKIT */ =20 int virPolkitCheckAuth(const char *actionid G_GNUC_UNUSED, @@ -247,4 +284,11 @@ virPolkitAgentCreate(void) _("polkit text authentication agent unavailable")); return NULL; } + +bool +virPolkitAgentAvailable(void) +{ + return false; +} + #endif /* WITH_POLKIT */ diff --git a/src/util/virpolkit.h b/src/util/virpolkit.h index a577d59452ba..7bcd040e5e06 100644 --- a/src/util/virpolkit.h +++ b/src/util/virpolkit.h @@ -37,3 +37,4 @@ typedef struct _virPolkitAgent virPolkitAgent; =20 void virPolkitAgentDestroy(virPolkitAgent *cmd); virPolkitAgent *virPolkitAgentCreate(void); +bool virPolkitAgentAvailable(void); --=20 2.34.0