From d87fcac96b45958bd777c7ac38cc0665dbde6062 Mon Sep 17 00:00:00 2001 From: Ermal Date: Mon, 10 Nov 2014 21:47:14 +0100 Subject: Do not require the default sysctl items to be set on the config.xml but rather extract the definitions from the sysctl tree. Also to reduce config.xml size --- etc/inc/system.inc | 39 ++++++++++++++++++++++++++++++++++++++- etc/inc/unbound.inc | 18 ++++++++++-------- 2 files changed, 48 insertions(+), 9 deletions(-) (limited to 'etc') diff --git a/etc/inc/system.inc b/etc/inc/system.inc index 273b5a2..87bbdb2 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -72,13 +72,50 @@ function get_default_sysctl_value($id) { return $sysctls[$id]; } +function get_sysctl_descr($sysctl) { + unset($output); + $_gb = exec("/sbin/sysctl -nd {$sysctl}", $output); + + return $output[0]; +} + +function system_get_sysctls() { + global $config, $sysctls; + + $disp_sysctl = array(); + $disp_cache = array(); + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { + foreach($config['sysctl']['item'] as $id => $tunable) { + if ($tunable['value'] == "default") + $value = get_default_sysctl_value($tunable['tunable']); + else + $value = $tunable['value']; + + $disp_sysctl[$id] = $tunable; + $disp_sysctl[$id]['modified'] = true; + $disp_cache[$tunable['tunable']] = 'set'; + } + } + + foreach ($sysctls as $sysctl => $value) { + if (isset($disp_cache[$sysctl])) + continue; + + $disp_sysctl[$sysctl] = array('tunable' => $sysctl, 'value' => $value, 'descr' => get_sysctl_descr($sysctl)); + + + } + unset($disp_cache); + return $disp_sysctl; +} + function activate_sysctls() { global $config, $g, $sysctls; if ($g['platform'] == 'jail') return; - if (is_array($config['sysctl'])) { + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { foreach($config['sysctl']['item'] as $tunable) { if($tunable['value'] == "default") $value = get_default_sysctl_value($tunable['tunable']); diff --git a/etc/inc/unbound.inc b/etc/inc/unbound.inc index 4088035..b047346 100644 --- a/etc/inc/unbound.inc +++ b/etc/inc/unbound.inc @@ -79,14 +79,16 @@ function unbound_optimization() { * Larger socket buffer for busy servers * Check that it is set to 4MB (by default the OS has it configured to 4MB) */ - foreach ($config['sysctl']['item'] as $tunable) { - if ($tunable['tunable'] == 'kern.ipc.maxsockbuf') { - $so = floor(($tunable['value']/1024/1024)-1); - // Check to ensure that the number is not a negative - if ($so > 0) - $optimization['so_rcvbuf'] = "so-rcvbuf: {$so}m"; - else - unset($optimization['so_rcvbuf']); + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { + foreach ($config['sysctl']['item'] as $tunable) { + if ($tunable['tunable'] == 'kern.ipc.maxsockbuf') { + $so = floor(($tunable['value']/1024/1024)-1); + // Check to ensure that the number is not a negative + if ($so > 0) + $optimization['so_rcvbuf'] = "so-rcvbuf: {$so}m"; + else + unset($optimization['so_rcvbuf']); + } } } // Safety check in case kern.ipc.maxsockbuf is not available. -- cgit v1.1