aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/nut/nut.inc30
1 files changed, 19 insertions, 11 deletions
diff --git a/config/nut/nut.inc b/config/nut/nut.inc
index 6b7b02ac..28ff3999 100644
--- a/config/nut/nut.inc
+++ b/config/nut/nut.inc
@@ -94,18 +94,26 @@
function before_form_nut($pkg) {
/* return available serial ports */
- $handle = popen('dmesg | grep \'^sio[0-9]: type\'','r');
- $read = fread($handle, 2096);
- pclose($handle);
- /* explode at the newlines */
- $read = explode("\n",$read);
-
- /* parse resulting text */
- foreach($read as $line) {
- if($line!= '') {
- $names[] = 'ttyd'.$line{3}.' (COM'.($line{3}+1).')';
- $values[] = '/dev/ttyd'.$line{3};
+ $serial_types = array("sio", "cua", "tty");
+ $ignore_files = array(".lock", ".init");
+
+ foreach($serial_types as $st) {
+ $devices = glob("/dev/{$st}*");
+ foreach($devices as $line) {
+ if($line != '') {
+ $ignore = false;
+ foreach($ignore_files as $if) {
+ if(strstr($line, $if)) {
+ $ignore = true;
+ continue;
+ }
+ }
+ if($ignore == false) {
+ $names[] = str_replace("/dev/", "", $line);
+ $values[] = $line;
+ }
+ }
}
}