Blame SOURCES/tuned-2.8.0-improve-reboot-check.patch

990480
diff --git a/tuned.service b/tuned.service
990480
index fcb3fa0..c59e3a9 100644
990480
--- a/tuned.service
990480
+++ b/tuned.service
990480
@@ -1,6 +1,6 @@
990480
 [Unit]
990480
 Description=Dynamic System Tuning Daemon
990480
-After=syslog.target systemd-sysctl.service network.target
990480
+After=syslog.target systemd-sysctl.service network.target dbus.service
990480
 Requires=dbus.service polkit.service
990480
 Conflicts=cpupower.service
990480
 
990480
diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py
990480
index b7db721..f78ec5a 100644
990480
--- a/tuned/daemon/daemon.py
990480
+++ b/tuned/daemon/daemon.py
990480
@@ -6,6 +6,7 @@ from tuned.exceptions import TunedException
990480
 from tuned.profiles.exceptions import InvalidProfileException
990480
 import tuned.consts as consts
990480
 from tuned.utils.commands import commands
990480
+import re
990480
 
990480
 log = tuned.logs.get()
990480
 
990480
@@ -98,6 +99,13 @@ class Daemon(object):
990480
 			self._application._dbus_exporter.send_signal(consts.DBUS_SIGNAL_PROFILE_CHANGED, profile_name, result, errstr)
990480
 		return errstr
990480
 
990480
+	def _system_shutting_down(self):
990480
+		retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
990480
+		if out[:8] == "stopping":
990480
+			return True
990480
+		retcode, out = self._cmd.execute(["systemctl", "list-jobs"], no_errors = [0])
990480
+		return re.search(r"\b(shutdown|reboot|halt|poweroff)\.target.*start", out) is not None
990480
+
990480
 	def _thread_code(self):
990480
 		if self._profile is None:
990480
 			raise TunedException("Cannot start the daemon without setting a profile.")
990480
@@ -143,13 +151,11 @@ class Daemon(object):
990480
 			# stopped by user and in such case do full cleanup, without systemd never
990480
 			# do full cleanup
990480
 			full_rollback = False
990480
-			retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
990480
-			if retcode >= 0:
990480
-				if out[:8] == "stopping":
990480
-					log.info("terminating Tuned due to system shutdown / reboot")
990480
-				else:
990480
-					log.info("terminating Tuned, rolling back all changes")
990480
-					full_rollback = True
990480
+			if self._system_shutting_down():
990480
+				log.info("terminating Tuned due to system shutdown / reboot")
990480
+			else:
990480
+				log.info("terminating Tuned, rolling back all changes")
990480
+				full_rollback = True
990480
 		if self._daemon:
990480
 			self._unit_manager.stop_tuning(full_rollback)
990480
 		self._unit_manager.destroy_all()