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."