From 52cb6185a4a51ffa92f10e0ded55a943bc21bc60 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 25 Mar 2022 18:54:44 +0100 Subject: vyos.util: T4319: provide generic sysctl_read() helper --- python/vyos/util.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'python/vyos/util.py') diff --git a/python/vyos/util.py b/python/vyos/util.py index 4526375df..da39ee8d1 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -1006,11 +1006,16 @@ def boot_configuration_complete() -> bool: return True return False +def sysctl_read(name): + """ Read and return current value of sysctl() option """ + tmp = cmd(f'sysctl {name}') + return tmp.split()[-1] + def sysctl(name, value): """ Change value via sysctl() - return True if changed, False otherwise """ tmp = cmd(f'sysctl {name}') # last list index contains the actual value - only write if value differs - if tmp.split()[-1] != str(value): + if sysctl_read(name) != str(value): call(f'sysctl -wq {name}={value}') return True return False -- cgit v1.2.3