diff options
author | Christian Poessinger <christian@poessinger.com> | 2022-03-25 18:54:44 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2022-03-25 19:16:02 +0100 |
commit | a053b48316b3bee09671381e01289e927ef828e7 (patch) | |
tree | 2d8287f64e70b7e5c5720b0166f019df9fe14775 | |
parent | d2ad75c59f2e2776d1ce663b64af77a22a7764fd (diff) | |
download | vyos-1x-a053b48316b3bee09671381e01289e927ef828e7.tar.gz vyos-1x-a053b48316b3bee09671381e01289e927ef828e7.zip |
vyos.util: T4319: provide generic sysctl_read() helper
(cherry picked from commit 52cb6185a4a51ffa92f10e0ded55a943bc21bc60)
-rw-r--r-- | python/vyos/util.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 76ba0fb60..5dff70b94 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -814,11 +814,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 |