summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErik Fonnesbeck <efonnes@gmail.com>2010-08-04 19:22:03 -0600
committerErik Fonnesbeck <efonnes@gmail.com>2010-08-04 19:22:03 -0600
commitaa4f498dda86d1808e652cd56d14d08dbc766760 (patch)
treec029d10bc4e1d66de1d1ee9efc52962208b22dd0 /etc
parentde9b760fe106ed02ef692c62834b7f656b58d174 (diff)
downloadpfsense-aa4f498dda86d1808e652cd56d14d08dbc766760.zip
pfsense-aa4f498dda86d1808e652cd56d14d08dbc766760.tar.gz
Add sysctl functions that support getting/setting multiple values in a single call.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/util.inc61
1 files changed, 61 insertions, 0 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index ced2be0..922eb5e 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -1074,6 +1074,67 @@ function make_dirs($path, $mode = 0755) {
}
/*
+ * get_sysctl($names)
+ * Get values of sysctl OID's listed in $names (accepts an array or a single
+ * name) and return an array of key/value pairs set for those that exist
+ */
+function get_sysctl($names) {
+ if (empty($names))
+ return array();
+
+ if (is_array($names)) {
+ $name_list = array();
+ foreach ($names as $name) {
+ $name_list[] = escapeshellarg($name);
+ }
+ } else
+ $name_list = array(escapeshellarg($names));
+
+ exec("/sbin/sysctl -i " . implode(" ", $name_list), $output);
+ $values = array();
+ foreach ($output as $line) {
+ $line = explode(": ", $line, 2);
+ if (count($line) == 2)
+ $values[$line[0]] = $line[1];
+ }
+
+ return $values;
+}
+
+/*
+ * set_sysctl($value_list)
+ * Set sysctl OID's listed as key/value pairs and return
+ * an array with keys set for those that succeeded
+ */
+function set_sysctl($values) {
+ if (empty($values))
+ return array();
+
+ $value_list = array();
+ foreach ($values as $key => $value) {
+ $value_list[] = escapeshellarg($key) . "=" . escapeshellarg($value);
+ }
+
+ exec("/sbin/sysctl -i " . implode(" ", $value_list), $output, $success);
+
+ /* Retry individually if failed (one or more read-only) */
+ if ($success <> 0 && count($value_list) > 1) {
+ foreach ($value_list as $value) {
+ exec("/sbin/sysctl -i " . $value, $output);
+ }
+ }
+
+ $ret = array();
+ foreach ($output as $line) {
+ $line = explode(": ", $line, 2);
+ if (count($line) == 2)
+ $ret[$line[0]] = true;
+ }
+
+ return $ret;
+}
+
+/*
* get_memory()
* returns an array listing the amount of
* memory installed in the hardware
OpenPOWER on IntegriCloud