From da8153456768f29b1be91039dbc617b347ac7684 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Thu, 6 Aug 2015 14:54:12 +0200 Subject: blinkled.inc - style fixes and code rework - Add copyright headers - Code style fixes - use is_process_running() instead of blinkled_running () - remove blinkled_stop() and blinkled_start in favour of start_service()/stop_service() in order to actually utilize the service in a meaningful way --- config/blinkled8/blinkled.inc | 81 +++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 30 deletions(-) (limited to 'config') diff --git a/config/blinkled8/blinkled.inc b/config/blinkled8/blinkled.inc index 6d0da039..0980b253 100644 --- a/config/blinkled8/blinkled.inc +++ b/config/blinkled8/blinkled.inc @@ -1,4 +1,33 @@ 0); -} function sync_package_blinkled() { global $config; + + blinkled_rcfile(); + $blinkled_config = $config['installedpackages']['blinkled']['config'][0]; - /* kill all instances of blinkled */ - if(blinkled_running()) { - blinkled_stop(); + /* If the service is not enabled, do nothing */ + if (!($blinkled_config['enable'])) { + if (is_process_running("blinkled")) { + stop_service("blinkled"); + } + return; } - /* if blinkled not running start it */ - if(!blinkled_running()) { - blinkled_start(); + /* Kill all instances of blinkled */ + if (is_process_running("blinkled")) { + stop_service("blinkled"); + } + /* If blinkled is not running, start it */ + if (!is_process_running("blinkled")) { + start_service("blinkled"); } - blinkled_rcfile(); } function blinkled_launch($int, $led, $return = false) { $cmd = "/usr/local/bin/blinkled -i " . escapeshellarg($int) . " -l " . escapeshellarg("/dev/led/led{$led}"); - if ($return) + if ($return) { return $cmd; - else + } else { mwexec($cmd); -} - -function blinkled_start() { - global $config; - $blinkled_config = $config['installedpackages']['blinkled']['config'][0]; - if (!($blinkled_config['enable'])) - return; - - if (($blinkled_config['enable_led2']) && ($blinkled_config['iface_led2'])) - blinkled_launch(convert_friendly_interface_to_real_interface_name($blinkled_config['iface_led2']), 2); - if (($blinkled_config['enable_led3']) && ($blinkled_config['iface_led3'])) - blinkled_launch(convert_friendly_interface_to_real_interface_name($blinkled_config['iface_led3']), 3); -} - -function blinkled_stop() { - mwexec("/usr/bin/killall -9 blinkled"); + } } function validate_form_blinkled($post, &$input_errors) { /* Make sure both aren't using the same interface */ - if (($post['iface_led2']) && ($post['iface_led3']) && + if (($post['iface_led2']) && ($post['iface_led3']) && (($post['enable_led2']) && ($post['enable_led3'])) && - ($post['iface_led2'] == $post['iface_led3'])) + ($post['iface_led2'] == $post['iface_led3'])) { $input_errors[] = 'You cannot set two LEDs for a single interface. Please choose seperate interfaces.'; + } } ?> -- cgit v1.2.3