diff options
author | marcelloc <marcellocoutinho@gmail.com> | 2012-02-03 18:49:20 -0200 |
---|---|---|
committer | marcelloc <marcellocoutinho@gmail.com> | 2012-02-03 18:49:20 -0200 |
commit | 93c0a7834e47a78065623d5b5b8620b02f06828b (patch) | |
tree | 5c93756d6f1cff4633bf1dabb1a5d6bfac5ebeff /config/lcdproc-dev/lcdproc_client.php | |
parent | 3ef5df94a33fd5619126eecc81ce1afd9b8b1b95 (diff) | |
parent | 5f0b221e5ec08527319196cf1f5eac71e5a88950 (diff) | |
download | pfsense-packages-93c0a7834e47a78065623d5b5b8620b02f06828b.tar.gz pfsense-packages-93c0a7834e47a78065623d5b5b8620b02f06828b.tar.bz2 pfsense-packages-93c0a7834e47a78065623d5b5b8620b02f06828b.zip |
Merge branch 'master' of https://github.com/bsdperimeter/pfsense-packages
Diffstat (limited to 'config/lcdproc-dev/lcdproc_client.php')
-rw-r--r-- | config/lcdproc-dev/lcdproc_client.php | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/config/lcdproc-dev/lcdproc_client.php b/config/lcdproc-dev/lcdproc_client.php index d931b9d0..36bf63fe 100644 --- a/config/lcdproc-dev/lcdproc_client.php +++ b/config/lcdproc-dev/lcdproc_client.php @@ -399,6 +399,7 @@ /* Define functions */ function send_lcd_commands($lcd, $lcd_cmds) { + global $lcdproc_connect_errors; if(!is_array($lcd_cmds) || (empty($lcd_cmds))) { lcdproc_warn("Failed to interpret lcd commands"); return; @@ -407,13 +408,16 @@ $cmd_output = ""; if(! fwrite($lcd, "$lcd_cmd\n")) { lcdproc_warn("Connection to LCDd process lost $errstr ($errno)"); - die(); + $lcdproc_connect_errors++; + return; } + usleep(20); // waits 20ms $cmd_output = fgets($lcd, 256); // FIXME: add support for interpreting menu commands here. if(preg_match("/^huh?/", $cmd_output)) { lcdproc_notice("LCDd output: \"$cmd_output\". Executed \"$lcd_cmd\""); } + $lcdproc_connect_errors = 0; // Reset the error counter } } @@ -722,6 +726,7 @@ function loop_status($lcd) { global $g; global $config; + global $lcdproc_connect_errors; $lcdproc_screens_config = $config['installedpackages']['lcdprocscreens']['config'][0]; $lcdpanel_width = get_lcdpanel_width(); $lcdpanel_height = get_lcdpanel_height(); @@ -874,7 +879,12 @@ add_summary_values($lcd_cmds, $name, $lcd_summary_data, $lcdpanel_width); } } + $temp_lcdproc_connect_errors = $lcdproc_connect_errors; send_lcd_commands($lcd, $lcd_cmds); + if ($temp_lcdproc_connect_errors != $lcdproc_connect_errors) + { //an error occurred + return; + } sleep($refresh_frequency * $widget_counter); $i++; } @@ -883,14 +893,25 @@ $traffic_last_ugmt = 0; $traffic_last_ifin = 0; $traffic_last_ifout = 0; + /* Initialize the global error counter */ + $lcdproc_connect_errors = 0; + $lcdproc_max_connect_errors = 2; /* Connect to the LCDd port and interface with the LCD */ - $lcd = fsockopen(LCDPROC_HOST, LCDPROC_PORT, $errno, $errstr, 10); - if (!$lcd) { - lcdproc_warn("Failed to connect to LCDd process $errstr ($errno)"); - } else { - build_interface($lcd); - loop_status($lcd); - /* loop exited? Close fd and wait for the script to kick in again */ - fclose($lcd); + while ($lcdproc_connect_errors <= $lcdproc_max_connect_errors) + { + lcdproc_warn("Start client procedure. Error counter: ($lcdproc_connect_errors)"); + $lcd = fsockopen(LCDPROC_HOST, LCDPROC_PORT, $errno, $errstr, 10); + if (!$lcd) { + lcdproc_warn("Failed to connect to LCDd process $errstr ($errno)"); + $lcdproc_connect_errors++; + } else { + build_interface($lcd); + loop_status($lcd); + fclose($lcd); + } + } + if ($lcdproc_connect_errors >= $lcdproc_max_connect_errors) + { + lcdproc_warn("Too many errors, the client ends."); } ?>
\ No newline at end of file |