From 5e08e2bc1d34aa0b9bea5b773e1d5ba175eb042f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
 <marmarek@invisiblethingslab.com>
Date: Thu, 12 May 2016 00:15:14 +0200
Subject: [PATCH] systemd: order units checking for qubes-service after
 qubes-sysinit

Files in /var/run/qubes-service are created by qubes-sysinit.service. So
defer that condition check after that service start.

Thanks @adrelanos for the report.

Fixes QubesOS/qubes-issues#1985
---
 vm-systemd/ModemManager.service.d/30_qubes.conf               | 1 +
 vm-systemd/NetworkManager-wait-online.service.d/30_qubes.conf | 2 +-
 vm-systemd/NetworkManager.service.d/30_qubes.conf             | 2 +-
 vm-systemd/chronyd.service.d/30_qubes.conf                    | 1 +
 vm-systemd/cron.service.d/30_qubes.conf                       | 2 +-
 vm-systemd/crond.service.d/30_qubes.conf                      | 2 +-
 vm-systemd/cups.path.d/30_qubes.conf                          | 1 +
 vm-systemd/cups.service.d/30_qubes.conf                       | 1 +
 vm-systemd/cups.socket.d/30_qubes.conf                        | 1 +
 vm-systemd/getty@tty.service.d/30_qubes.conf                  | 1 +
 vm-systemd/netfilter-persistent.service.d/30_qubes.conf       | 1 +
 vm-systemd/network-manager.service.d/30_qubes.conf            | 1 +
 vm-systemd/ntpd.service.d/30_qubes.conf                       | 1 +
 vm-systemd/org.cups.cupsd.path.d/30_qubes.conf                | 1 +
 vm-systemd/org.cups.cupsd.service.d/30_qubes.conf             | 1 +
 vm-systemd/org.cups.cupsd.socket.d/30_qubes.conf              | 1 +
 vm-systemd/tor.service.d/30_qubes.conf                        | 1 +
 17 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/vm-systemd/ModemManager.service.d/30_qubes.conf b/vm-systemd/ModemManager.service.d/30_qubes.conf
index c8f3d99..298a7e9 100644
--- a/vm-systemd/ModemManager.service.d/30_qubes.conf
+++ b/vm-systemd/ModemManager.service.d/30_qubes.conf
@@ -1,3 +1,4 @@
 [Unit]
 ConditionPathExists=|/var/run/qubes-service/network-manager
 ConditionPathExists=|/var/run/qubes-service/modem-manager
+After=qubes-sysinit.service
diff --git a/vm-systemd/NetworkManager-wait-online.service.d/30_qubes.conf b/vm-systemd/NetworkManager-wait-online.service.d/30_qubes.conf
index 30836e5..602321b 100644
--- a/vm-systemd/NetworkManager-wait-online.service.d/30_qubes.conf
+++ b/vm-systemd/NetworkManager-wait-online.service.d/30_qubes.conf
@@ -1,4 +1,4 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/network-manager
 # For /rw
-After=qubes-misc-post.service
+After=qubes-misc-post.service qubes-sysinit.service
diff --git a/vm-systemd/NetworkManager.service.d/30_qubes.conf b/vm-systemd/NetworkManager.service.d/30_qubes.conf
index 5a35315..7daec3f 100644
--- a/vm-systemd/NetworkManager.service.d/30_qubes.conf
+++ b/vm-systemd/NetworkManager.service.d/30_qubes.conf
@@ -1,7 +1,7 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/network-manager
 # For /rw
-After=qubes-misc-post.service
+After=qubes-misc-post.service qubes-sysinit.service
 
 [Service]
 ExecStartPre=/usr/lib/qubes/network-manager-prepare-conf-dir
diff --git a/vm-systemd/chronyd.service.d/30_qubes.conf b/vm-systemd/chronyd.service.d/30_qubes.conf
index 3c37ba3..5679a2f 100644
--- a/vm-systemd/chronyd.service.d/30_qubes.conf
+++ b/vm-systemd/chronyd.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/ntpd
+After=qubes-sysinit.service
diff --git a/vm-systemd/cron.service.d/30_qubes.conf b/vm-systemd/cron.service.d/30_qubes.conf
index 316131f..0e66602 100644
--- a/vm-systemd/cron.service.d/30_qubes.conf
+++ b/vm-systemd/cron.service.d/30_qubes.conf
@@ -3,7 +3,7 @@ ConditionPathExists=/var/run/qubes-service/crond
 
 [Unit]
 # For /rw
-After=qubes-misc-post.service
+After=qubes-misc-post.service qubes-sysinit.service
 
 [Service]
 ExecStartPre=/bin/mkdir --mode=0700 -p /rw/cron
diff --git a/vm-systemd/crond.service.d/30_qubes.conf b/vm-systemd/crond.service.d/30_qubes.conf
index 316131f..0e66602 100644
--- a/vm-systemd/crond.service.d/30_qubes.conf
+++ b/vm-systemd/crond.service.d/30_qubes.conf
@@ -3,7 +3,7 @@ ConditionPathExists=/var/run/qubes-service/crond
 
 [Unit]
 # For /rw
-After=qubes-misc-post.service
+After=qubes-misc-post.service qubes-sysinit.service
 
 [Service]
 ExecStartPre=/bin/mkdir --mode=0700 -p /rw/cron
diff --git a/vm-systemd/cups.path.d/30_qubes.conf b/vm-systemd/cups.path.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/cups.path.d/30_qubes.conf
+++ b/vm-systemd/cups.path.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/cups.service.d/30_qubes.conf b/vm-systemd/cups.service.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/cups.service.d/30_qubes.conf
+++ b/vm-systemd/cups.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/cups.socket.d/30_qubes.conf b/vm-systemd/cups.socket.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/cups.socket.d/30_qubes.conf
+++ b/vm-systemd/cups.socket.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/getty@tty.service.d/30_qubes.conf b/vm-systemd/getty@tty.service.d/30_qubes.conf
index 5f26fd2..67401e1 100644
--- a/vm-systemd/getty@tty.service.d/30_qubes.conf
+++ b/vm-systemd/getty@tty.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/getty@tty
+After=qubes-sysinit.service
diff --git a/vm-systemd/netfilter-persistent.service.d/30_qubes.conf b/vm-systemd/netfilter-persistent.service.d/30_qubes.conf
index f71617f..1e655da 100644
--- a/vm-systemd/netfilter-persistent.service.d/30_qubes.conf
+++ b/vm-systemd/netfilter-persistent.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/netfilter-persistent
+After=qubes-sysinit.service
diff --git a/vm-systemd/network-manager.service.d/30_qubes.conf b/vm-systemd/network-manager.service.d/30_qubes.conf
index 24d1573..64795b6 100644
--- a/vm-systemd/network-manager.service.d/30_qubes.conf
+++ b/vm-systemd/network-manager.service.d/30_qubes.conf
@@ -1,3 +1,4 @@
 # Disable sysinit version of network-manager (wheezy)
 [Unit]
 ConditionPathExists=!/var/run/qubes-service
+After=qubes-sysinit.service
diff --git a/vm-systemd/ntpd.service.d/30_qubes.conf b/vm-systemd/ntpd.service.d/30_qubes.conf
index 3c37ba3..5679a2f 100644
--- a/vm-systemd/ntpd.service.d/30_qubes.conf
+++ b/vm-systemd/ntpd.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/ntpd
+After=qubes-sysinit.service
diff --git a/vm-systemd/org.cups.cupsd.path.d/30_qubes.conf b/vm-systemd/org.cups.cupsd.path.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/org.cups.cupsd.path.d/30_qubes.conf
+++ b/vm-systemd/org.cups.cupsd.path.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/org.cups.cupsd.service.d/30_qubes.conf b/vm-systemd/org.cups.cupsd.service.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/org.cups.cupsd.service.d/30_qubes.conf
+++ b/vm-systemd/org.cups.cupsd.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/org.cups.cupsd.socket.d/30_qubes.conf b/vm-systemd/org.cups.cupsd.socket.d/30_qubes.conf
index 7762255..54104ad 100644
--- a/vm-systemd/org.cups.cupsd.socket.d/30_qubes.conf
+++ b/vm-systemd/org.cups.cupsd.socket.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=/var/run/qubes-service/cups
+After=qubes-sysinit.service
diff --git a/vm-systemd/tor.service.d/30_qubes.conf b/vm-systemd/tor.service.d/30_qubes.conf
index 5a2c9f4..2151194 100644
--- a/vm-systemd/tor.service.d/30_qubes.conf
+++ b/vm-systemd/tor.service.d/30_qubes.conf
@@ -1,2 +1,3 @@
 [Unit]
 ConditionPathExists=!/var/run/qubes/this-is-templatevm
+After=qubes-sysinit.service