Add a generic function to get and set sysctl values. Also fix a bug in the sysctl_kernel function where it would interpret value=0 as an attempt to get a value and not an attempt to set a value to zero.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4391 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/base_utils.py b/client/bin/base_utils.py
index 7c5d26b..2de9f86 100644
--- a/client/bin/base_utils.py
+++ b/client/bin/base_utils.py
@@ -372,9 +372,23 @@
return phys_kbytes
+def sysctl(key, value=None):
+ """Generic implementation of sysctl, to read and write.
+
+ @param key: A location under /proc/sys
+ @param value: If not None, a value to write into the sysctl.
+
+ @return The single-line sysctl value as a string.
+ """
+ path = '/proc/sys/%s' % key
+ if value is not None:
+ utils.write_one_line(path, str(value))
+ return utils.read_one_line(path)
+
+
def sysctl_kernel(key, value=None):
"""(Very) partial implementation of sysctl, for kernel params"""
- if value:
+ if value is not None:
# write
utils.write_one_line('/proc/sys/kernel/%s' % key, str(value))
else: