Article View: linux.gentoo.dev
Article #227[gentoo-dev] [RFC] [PATCH 1/3] pkagent-autostart.eclass: New eclass to make session-specific pkagent file
From: Andreas Sturmlechner
Date: Sun, 29 Nov 2026 19:30
Date: Sun, 29 Nov 2026 19:30
199 lines
7683 bytes
7683 bytes
--nextPartJ5apLaa0TMewsvvOTM_Tyw
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"; protected-headers="v1"
From: Andreas Sturmlechner <asturm@gentoo.org>
To: gentoo-dev@lists.gentoo.org, freedesktop-bugs@gentoo.org
Date: Sun, 29 Nov 2026 20:23:34 +0100
Message-ID: <aTsa8Q3IT4ahLmug2F5phQ@gentoo.org>
MIME-Version: 1.0
See also: https://github.com/gentoo/gentoo/pull/47042
(pre-review discussion +contains example usage by way of xfce4-polkit)
Ensures, via OnlyShowIn=<env>, that any generated autostart file is
only, but surely, going to be started in its designated environment.
This is important because we want to avoid having more than one polkit
agent autostarting, and racing, in the same environment. It is then
the desktop environments' responsibility to pull in their designated
polkit-agent which works out of the box by matching the `DesktopNames`
entry in the env session file. Which most of them already do for a
very long time, except Xfce.
Any WM without its own polkit-agent binary may set up an autostart
file this way too, provided it has XDG autostart capability.
Catch PN=polkit-gnome to keep existing filename in an attempt to
preserve existing user modifications.
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
eclass/pkagent-autostart.eclass | 132 ++++++++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
create mode 100644 eclass/pkagent-autostart.eclass
diff --git a/eclass/pkagent-autostart.eclass b/eclass/pkagent-autostart.eclass
new file mode 100644
index 000000000000..2bcacda8b2b7
--- /dev/null
+++ b/eclass/pkagent-autostart.eclass
@@ -0,0 +1,132 @@
+# Copyright 2026 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: pkagent-autostart.eclass
+# @MAINTAINER:
+# freedesktop-bugs@gentoo.org
+# @SUPPORTED_EAPIS: 8 9
+# @BLURB: Installs aptly configured autostart desktop file for the chosen
+# environment. May be used by environments that do not come with their own
+# polkit-agent, thus reuse one of the known implementations.
+
+case ${EAPI} in
+ 8|9) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_PKAGENT_AUTOSTART_ECLASS} ]]; then
+_PKAGENT_AUTOSTART_ECLASS=1
+
+# @FUNCTION: make_pkagent_autostart_entry
+# @USAGE: <env> <pkagent>
+# @DESCRIPTION:
+# Make a session specific .desktop file and install it in /etc/xdg/autostart.
+# See also:
+# - https://specifications.freedesktop.org/menu/latest/onlyshowin-registry.html
+# - https://specifications.freedesktop.org/desktop-entry/latest-single/#key-onlyshowin
+#
+# @CODE
+# env: If set, should either correspond with registered values for Desktop
+# Environments, or be made sure to match an existing session file's
+# DesktopNames entry. Value of env is passed as OnlyShowIn=<value>.
+# Non-registered environments shall be prefixed by the string "X-" to
+# pass desktop-file-utils validation, but will work either way.
+# If empty, will set Hidden=true instead of OnlyShowIn. Also affects
+# desktop filename: 'polkit-${env,,}-authentication-agent.desktop'
+# pkagent: Target (known) polkit-agent package to choose from for Exec
+# If unknown, value of pkagent is directly passed as Exec=<value>,
+# which must be either in PATH or be an absolute path to a binary.
+# @CODE
+#
+# Example usage:
+# @CODE
+# XFCE polkit-gnome
+# @CODE
+make_pkagent_autostart_entry() {
+ local execpath fname name onlyshowin
+ if [[ $# -ne 2 ]]; then
+ die "${FUNCNAME[0]} must be passed exactly two arguments"
+ fi
+
+ # Registered OnlyShowIn values
+ case ${1} in
+ COSMIC | \
+ GNOME | \
+ GNOME-Classic | \
+ GNOME-Flashback | \
+ KDE | \
+ LXDE | \
+ LXQt | \
+ MATE | \
+ Razor | \
+ ROX | \
+ TDE | \
+ Unity | \
+ XFCE | \
+ EDE | \
+ Cinnamon | \
+ Pantheon | \
+ Phosh | \
+ DDE | \
+ Endless | \
+ Old | \
+ X-*)
+ onlyshowin="OnlyShowIn=${1};"
+ name="${PN/#X-/}"
+ ;;
+ "")
+ onlyshowin="Hidden=true"
+ name="${PN/#polkit/}"
+ name="${name/--/-}"
+ ;;
+ *)
+ onlyshowin="OnlyShowIn=${1};"
+ name="${PN/#polkit/}"
+ elog "${1} is not a registered OnlyShowIn value in the Desktop Application"
+ elog "Autostart Specification. It will not do anything without a corresponding"
+ elog "DesktopNames entry from a session desktop file."
+ ;;
+ esac
+
+ # Known 'standard' polkit-agent packages
+ case ${2} in
+ lxqt-policykit)
+ execpath="/usr/bin/lxqt-policykit-agent" ;;
+ lxsession)
+ execpath="/usr/bin/lxpolkit" ;;
+ mate-polkit)
+ execpath="/usr/libexec/polkit-mate-authentication-agent-1" ;;
+ polkit-gnome)
+ execpath="/usr/libexec/polkit-gnome-authentication-agent-1" ;;
+ polkit-kde-agent)
+ execpath="/usr/libexec/polkit-kde-authentication-agent-1" ;;
+ *)
+ execpath="${2}" ;;
+ esac
+
+ # preserve existing filename for a de facto legacy standard in GTK world
+ if [[ ${PN} == polkit-gnome ]]; then
+ fname="polkit-gnome-authentication-agent-1.desktop"
+ else
+ fname="polkit-${name,,}-authentication-agent.desktop"
+ fi
+
+ cat > "${T}/${fname}" <<- _EOF_ || die
+ [Desktop Entry]
+ Name=PolicyKit Authentication Agent
+ Comment=PolicyKit Authentication Agent
+ Exec=${execpath}
+ Icon=dialog-password
+ Terminal=false
+ Type=Application
+ ${onlyshowin}
+ NoDisplay=true
+ _EOF_
+
+ (
+ insinto /etc/xdg/autostart
+ doins "${T}/${fname}"
+ )
+}
+
+fi
--
2.56.1
--nextPartJ5apLaa0TMewsvvOTM_Tyw
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit
-----BEGIN PGP SIGNATURE-----
iQIvBAABCgCZFiEE34gXUSooizdYNDu3S5FW4z0PgBkFAmsMe7cbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25z
Lm9wZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRERjg4MTc1MTJBMjg4QjM3NTgzNDNC
Qjc0QjkxNTZFMzNEMEY4MDE5AAoJEEuRVuM9D4AZ554L/jHYXSac66YHr1ZFj8gy
N2T3UqdYXapR26KDSzOGE5qGyvAu63L0DM6/kFocyuagwDiLqcgvNQ/WxeH30TP5
J+R/eFKQig30PB5zesxuBM1xk+83VT0ongYdpG2hVniUTwlVby8+8BgfqeN8ornp
YhkhxP894x+iVCGAzOHLY7zDimflAVtjZNj+fPOk7rj6khDwQFJUzw+BRqo9Vpik
ciKBCI8Lw96nEOUCbqIGnocl2KA9M41cY0EA7LdZBkmRWXMUHP5K+I59wd3Y0nCE
oBb2c4AzkbiMeI4vnLfF7i24hm0iIXzLFIIxpVvd2HcvZNGwoHucWEXw8b74V8ty
LH4XmOTOs79Y/LpygFcVd+Tjd4imnq5lf0otLuezP5TKr4jQGUXLZWTDM8cuv7i9
reWCoYnEas5++Gf6vsVRnVkshkT3GEnp0FlKQtyyXLo7l8SkhXNY4qunOD6bHFhX
fc9R/2E6ALcuroRLnpnIky3wuLUsWAr1pSAP8kKgV4m8ww==
=ougl
-----END PGP SIGNATURE-----
--nextPartJ5apLaa0TMewsvvOTM_Tyw--
Technical Details
Message-ID:
<O4SKZ-eYzN-5@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Andreas Sturmlechner <asturm@gentoo.org> Newsgroups: linux.gentoo.dev Subject: [gentoo-dev] [RFC] [PATCH 1/3] pkagent-autostart.eclass: New eclass to make session-specific pkagent file Date: Sun, 29 Nov 2026 20:30:01 +0100 Message-ID: <O4SKZ-eYzN-5@gated-at.bofh.it> List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org> Reply-To: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPartJ5apLaa0TMewsvvOTM_Tyw"; micalg="pgp-sha512"; protocol="application/pgp-signature" Approved: robomod@news.nic.it Lines: 199 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Sun, 29 Nov 2026 20:23:34 +0100 X-Original-Message-ID: <aTsa8Q3IT4ahLmug2F5phQ@gentoo.org>