ソースを参照

Implement dropins for /etc/xdg/autostart (#1151)

Usage of _static_ files (dropins) to override some of autostart entries
(enable/disable them in appropriate VM types) is much simpler and less
error prone than automatic generators.

Handling code is implemented in qubes-session-autostart, which is called
from qubes-session.

qubesos/qubes-issues#1151
Marek Marczykowski-Górecki 8 年 前
コミット
3d06ce1ee9

+ 2 - 0
Makefile

@@ -121,6 +121,7 @@ install-rh: install-systemd install-systemd-dropins install-sysvinit
 	install -m 0400 -D network/ip6tables $(DESTDIR)/usr/lib/qubes/init/ip6tables
 
 install-common:
+	$(MAKE) -C autostart-dropins install
 	install -m 0644 -D misc/fstab $(DESTDIR)/etc/fstab
 
 	install -D -m 0440 misc/qubes.sudoers $(DESTDIR)/etc/sudoers.d/qubes
@@ -171,6 +172,7 @@ install-common:
 	install network/qubes-netwatcher $(DESTDIR)/$(SBINDIR)/
 
 	install -d $(DESTDIR)/usr/bin
+	install -m 0755 misc/qubes-session-autostart $(DESTDIR)/usr/bin/qubes-session-autostart
 	install -m 0755 misc/qubes-desktop-file-install $(DESTDIR)/usr/bin/qubes-desktop-file-install
 	install -m 0755 misc/qubes-trigger-desktop-file-install $(DESTDIR)$(LIBDIR)/qubes/qubes-trigger-desktop-file-install
 

+ 6 - 0
autostart-dropins/Makefile

@@ -0,0 +1,6 @@
+
+DROPINS_DIR = /etc/qubes/autostart
+
+install:
+	for f in *.desktop; do install -m 0644 -D $$f $(DESTDIR)$(DROPINS_DIR)/$$f.d/30_qubes.conf; done
+	install -m 0644 README.txt $(DESTDIR)$(DROPINS_DIR)/

+ 20 - 0
autostart-dropins/README.txt

@@ -0,0 +1,20 @@
+This directory (/etc/qubes/autostart) is used to override parts of files in
+/etc/xdg/autostart. For each desktop file there, you can create directory named
+after the file plus ".d", then place files there. All such files will be read
+(in lexicographical order) and lines specified there will override respective
+entries in the original file. This can be used for example to enable or disable
+specific application in particular VM type.
+
+For example, you can extend `/etc/xdg/autostart/gnome-keyring-ssh.desktop` by
+creating `/etc/qubes/autostart/gnome-keyring-ssh.desktop.d/50_user.conf` with:
+```
+[Desktop Entry]
+OnlyShowIn=X-AppVM;
+```
+
+This would mean that `OnlyShowIn` key would be read as `X-AppVM;`, regardless
+of original entry in `/etc/xdg/autostart/gnome-keyring-ssh.desktop`.
+
+This mechanism overrides only content of /etc/xdg/autostart, files placed in
+~/.config/autostart are unaffected, so can be used to override settings per-VM
+basis.

+ 2 - 0
autostart-dropins/deja-dup-monitor.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/gcm-apply.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-DisposableVM;

+ 2 - 0
autostart-dropins/gnome-keyring-gpg.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/gnome-keyring-pkcs11.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/gnome-keyring-secrets.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/gnome-keyring-ssh.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/gnome-power-manager.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/gnome-screensaver.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/gnome-settings-daemon.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/gnome-sound-applet.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/gpk-update-icon.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-UpdateableVM;

+ 2 - 0
autostart-dropins/gsettings-data-convert.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 2 - 0
autostart-dropins/imsettings-start.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/krb5-auth-dialog.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/nm-applet.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-QUBES

+ 2 - 0
autostart-dropins/notify-osd.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/orca-autostart.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/pulseaudio.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/restorecond.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/sealertauto.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+NotShowIn=X-QUBES;

+ 2 - 0
autostart-dropins/user-dirs-update-gtk.desktop

@@ -0,0 +1,2 @@
+[Desktop Entry]
+OnlyShowIn=GNOME;X-AppVM;

+ 84 - 0
misc/qubes-session-autostart

@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# The Qubes OS Project, http://www.qubes-os.org
+#
+# Copyright (C) 2015  Marek Marczykowski-Górecki
+#                                        <marmarek@invisiblethingslab.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+#
+import subprocess
+import sys
+
+from xdg.DesktopEntry import DesktopEntry
+from qubes.xdg import launch
+import xdg.BaseDirectory
+import os
+
+QUBES_XDG_CONFIG_DROPINS = '/etc/qubes/autostart'
+
+def open_desktop_entry_and_dropins(filename):
+    desktop_entry = DesktopEntry(filename)
+    dropins_dir = os.path.join(QUBES_XDG_CONFIG_DROPINS,
+                               os.path.basename(filename) + '.d')
+    if os.path.isdir(dropins_dir):
+        for dropin in sorted(os.listdir(dropins_dir)):
+            dropin_content = DesktopEntry(os.path.join(dropins_dir, dropin))
+            desktop_entry.content.update(dropin_content.content)
+
+    return desktop_entry
+
+
+def entry_should_be_started(entry, environments):
+    """
+
+    :type entry: DesktopEntry
+    """
+    if entry.getHidden():
+        return False
+    if entry.getOnlyShowIn():
+        return bool(set(entry.getOnlyShowIn()).intersection(environments))
+    if entry.getNotShowIn():
+        return not bool(set(entry.getNotShowIn()).intersection(environments))
+    return True
+
+
+def process_autostart(environments):
+    # handle only "most important" entry
+    processed_entries = {}
+    for path in xdg.BaseDirectory.load_config_paths('autostart'):
+        for entry_name in os.listdir(path):
+            if entry_name in processed_entries:
+                continue
+
+            # make the entry as processed, even if not actually started
+            processed_entries[entry_name] = True
+
+            entry_path = os.path.join(path, entry_name)
+            # files in $HOME have higher priority than dropins
+            if not path.startswith(xdg.BaseDirectory.xdg_config_home):
+                entry = open_desktop_entry_and_dropins(entry_path)
+            else:
+                entry = DesktopEntry(entry_path)
+            if entry_should_be_started(entry, environments):
+                launch(entry_path)
+
+def main():
+    process_autostart(sys.argv[1:])
+
+if __name__ == '__main__':
+    main()

+ 4 - 0
rpm_spec/core-vm.spec

@@ -356,6 +356,9 @@ rm -f %{name}-%{version}
 %config(noreplace) /etc/qubes-rpc/qubes.SelectDirectory
 %config(noreplace) /etc/qubes-rpc/qubes.GetImageRGBA
 %config(noreplace) /etc/qubes-rpc/qubes.SetDateTime
+%dir /etc/qubes/autostart
+/etc/qubes/autostart/README.txt
+%config /etc/qubes/autostart/*.desktop.d/30_qubes.conf
 %config(noreplace) /etc/sudoers.d/qubes
 %config(noreplace) /etc/sysconfig/iptables.qubes
 %config(noreplace) /etc/sysconfig/ip6tables.qubes
@@ -384,6 +387,7 @@ rm -f %{name}-%{version}
 /usr/bin/qubes-desktop-run
 /usr/bin/qrexec-fork-server
 /usr/bin/qrexec-client-vm
+/usr/bin/qubes-session-autostart
 /usr/bin/qubes-desktop-file-install
 %dir /usr/lib/qubes
 /usr/lib/qubes/vusb-ctl.py*