From 4b8940ead0321be0a82b601b59a49e9932fbbdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 7 May 2023 02:22:17 +0200 Subject: [PATCH] A wrapper for starting a process conditionally on qvm-service Add a generic wrapper that starts a given process only if specific qvm-service is enabled. This can be used in desktop files for example (in Exec= line). Note that systemd units have this functionality built in (ConditionExists=). QubesOS/qubes-issues#8161 (cherry picked from commit 5cf9c870d49f240cc3cc99d75f4262825fb24cf0) --- debian/qubes-core-agent.install | 1 + misc/Makefile | 4 ++++ misc/qvm-service-wrapper | 12 ++++++++++++ rpm_spec/core-agent.spec.in | 1 + 4 files changed, 18 insertions(+) create mode 100755 misc/qvm-service-wrapper diff --git a/debian/qubes-core-agent.install b/debian/qubes-core-agent.install index 41d97d998..fe2a6d3c4 100644 --- a/debian/qubes-core-agent.install +++ b/debian/qubes-core-agent.install @@ -146,6 +146,7 @@ usr/lib/qubes/qvm-copy-to-vm.gnome usr/lib/qubes/qvm-copy-to-vm.kde usr/lib/qubes/qvm-move-to-vm.gnome usr/lib/qubes/qvm-move-to-vm.kde +usr/lib/qubes/qvm-service-wrapper usr/lib/qubes/resize-rootfs usr/lib/qubes/tar2qfile usr/lib/qubes/update-proxy-configs diff --git a/misc/Makefile b/misc/Makefile index 6dcb47d3d..96806fe8a 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -1,6 +1,8 @@ BINDIR ?= /usr/bin DATADIR ?= /usr/share SYSLIBDIR ?= /lib +LIBDIR ?= /usr/lib +QUBESLIBDIR := $(LIBDIR)/qubes UDEVRULESDIR := $(SYSLIBDIR)/udev/rules.d QUBESDATADIR := $(DATADIR)/qubes QUBESMIMEDIR := $(QUBESDATADIR)/xdg-override @@ -39,6 +41,8 @@ install: umask 022 && cp -r applications mime '$(DESTDIR)$(QUBESMIMEDIR)' install -m 0755 -d $(DESTDIR)$(BINDIR) install -m 0755 -t $(DESTDIR)$(BINDIR) qvm-features-request + install -m 0755 -d $(DESTDIR)$(QUBESLIBDIR) + install -m 0755 -t $(DESTDIR)$(QUBESLIBDIR) qvm-service-wrapper marker-vm: marker-vm.in printf "$(VERSION)" | cut -f 1,2 -d . | cat $< - > marker-vm diff --git a/misc/qvm-service-wrapper b/misc/qvm-service-wrapper new file mode 100755 index 000000000..11a0ca4b4 --- /dev/null +++ b/misc/qvm-service-wrapper @@ -0,0 +1,12 @@ +#!/bin/sh + +# Start an application given as $2 only if qvm-service $1 is enabled + +service="$1" +shift +if ! [ -r "/run/qubes-service/$service" ]; then + echo "Not starting '$1', qvm-service '$service' is not enabled" >&2 + exit 0 +fi + +exec "$@" diff --git a/rpm_spec/core-agent.spec.in b/rpm_spec/core-agent.spec.in index 68023ccd4..3c8be08e7 100644 --- a/rpm_spec/core-agent.spec.in +++ b/rpm_spec/core-agent.spec.in @@ -733,6 +733,7 @@ rm -f %{name}-%{version} /usr/lib/qubes/qvm-copy-to-vm.kde /usr/lib/qubes/qvm-move-to-vm.gnome /usr/lib/qubes/qvm-move-to-vm.kde +/usr/lib/qubes/qvm-service-wrapper /usr/lib/qubes/tar2qfile /usr/lib/qubes/vm-file-editor /usr/lib/qubes/xdg-icon