From 53118d60cb521db2c8c9a0fbc560a30079d640bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Wed, 24 Sep 2014 19:17:25 +0200 Subject: [PATCH] tuned-adm: active: detect whether tuned deamon is running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related: rhbz#1068699 Signed-off-by: Jaroslav Škarvada --- tuned/admin/admin.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tuned/admin/admin.py b/tuned/admin/admin.py index 8b5f7bd..65520b1 100644 --- a/tuned/admin/admin.py +++ b/tuned/admin/admin.py @@ -2,7 +2,9 @@ from tuned.utils.commands import commands from tuned.profiles import Locator as profiles_locator from exceptions import TunedAdminDBusException import tuned.consts as consts +import os import sys +import errno class Admin(object): def __init__(self, controller, debug = False): @@ -13,6 +15,15 @@ class Admin(object): def _error(self, message): print >>sys.stderr, message + def _tuned_is_running(self): + try: + os.kill(int(self._cmd.read_file(consts.PID_FILE)), 0) + except OSError as e: + return e.errno == errno.EPERM + except (ValueError, IOError) as e: + return False + return True + def list(self): try: profile_names = self._controller.profiles() @@ -29,9 +40,13 @@ class Admin(object): profile_name = self._controller.active_profile() except TunedAdminDBusException as e: self._error(e) - profile_name = self._cmd.read_file(consts.ACTIVE_PROFILE_FILE, None) + profile_name = str.strip(self._cmd.read_file(consts.ACTIVE_PROFILE_FILE, None)) if profile_name is not None and profile_name != "": - print "Current active profile: %s" % profile_name + if self._tuned_is_running(): + print "Current active profile: %s" % profile_name + else: + print "It seems that tuned daemon is not running, preset profile is not activated." + print "Preset profile: %s" % profile_name return True else: print "No current active profile."