Blob Blame History Raw
From efac9c470b2a74da94c92703e87da603bf87296f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
Date: Wed, 19 Aug 2015 14:09:56 +0200
Subject: [PATCH] plugin_sysctl: unquoting sysctl values
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Unquoting first and last quotation mark in value, i.e. converting:
OPTION="VALUE" to OPTION=VALUE

Also added unquoting to profile verification, unquoting both
(current and requested) values.

Resolves: rhbz#1254538

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
---
 tuned/plugins/base.py              | 7 +++++--
 tuned/plugins/plugin_bootloader.py | 5 +----
 tuned/plugins/plugin_sysctl.py     | 2 +-
 tuned/utils/commands.py            | 3 +++
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/tuned/plugins/base.py b/tuned/plugins/base.py
index e7ff2d2..3b4652a 100644
--- a/tuned/plugins/base.py
+++ b/tuned/plugins/base.py
@@ -3,6 +3,7 @@ import tuned.consts as consts
 import tuned.profiles.variables
 import tuned.logs
 import collections
+from tuned.utils.commands import commands
 
 log = tuned.logs.get()
 
@@ -35,6 +36,8 @@ class Plugin(object):
 
 		self._options_used_by_dynamic = self._get_config_options_used_by_dynamic()
 
+		self._cmd = commands()
+
 	def cleanup(self):
 		self.destroy_instances()
 
@@ -415,10 +418,10 @@ class Plugin(object):
 				command["set"](new_value, sim = False)
 
 	def _norm_value(self, value):
-		v = str(value)
+		v = self._cmd.unquote(str(value))
 		if re.match(r'\s*(0+,)+[\da-fA-F]*\s*$', v):
 			return re.sub(r'^\s*(0+,)+', "", v)
-		return value
+		return v
 
 	def _verify_value(self, name, new_value, current_value, device = None):
 		if new_value is None:
diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py
index e0ff646..27b7132 100644
--- a/tuned/plugins/plugin_bootloader.py
+++ b/tuned/plugins/plugin_bootloader.py
@@ -105,9 +105,6 @@ class BootloaderPlugin(base.Plugin):
 		self._grub2_default_env_patch()
 		return True
 
-	def _unquote(self, v):
-		return re.sub("^\"(.*)\"$", r"\1", v)
-
 	@command_custom("grub2_cfg_file")
 	def _grub2_cfg_file(self, enabling, value, verify):
 		# nothing to verify
@@ -118,7 +115,7 @@ class BootloaderPlugin(base.Plugin):
 
 	@command_custom("cmdline", per_device = False, priority = 10)
 	def _cmdline(self, enabling, value, verify):
-		v = self._variables.expand(self._unquote(value))
+		v = self._variables.expand(self._cmd.unquote(value))
 		if verify:
 			cmdline = self._cmd.read_file("/proc/cmdline")
 			if len(cmdline) == 0:
diff --git a/tuned/plugins/plugin_sysctl.py b/tuned/plugins/plugin_sysctl.py
index 676fd52..70f27af 100644
--- a/tuned/plugins/plugin_sysctl.py
+++ b/tuned/plugins/plugin_sysctl.py
@@ -43,7 +43,7 @@ class SysctlPlugin(base.Plugin):
 			original_value = self._read_sysctl(option)
 			if original_value != None:
 				instance._sysctl_original[option] = original_value
-			self._write_sysctl(option, self._variables.expand(value))
+			self._write_sysctl(option, self._variables.expand(self._cmd.unquote(value)))
 
 		self._storage.set("options", instance._sysctl_original)
 
diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py
index 4c80783..2392a89 100644
--- a/tuned/utils/commands.py
+++ b/tuned/utils/commands.py
@@ -30,6 +30,9 @@ class commands:
 	def remove_ws(self, s):
 		return re.sub('\s+', ' ', s).strip()
 
+	def unquote(self, v):
+		return re.sub("^\"(.*)\"$", r"\1", v)
+
 	# convert dictionary 'd' to flat list and return it
 	# it uses sort on the dictionary items to return consistent results
 	# for directories with different inserte/delete history
-- 
2.4.3