diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index f72d6588c..c10a04faa 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -53,6 +53,7 @@ sub system_background($) { } # Returns the output of a shell command +# if you change this also check speed.cgi that include a local copy for systemload reasons sub system_output($) { my @command = @_; my $pid; @@ -1227,6 +1228,7 @@ sub firewall_reload() { } # Function which will return the used interface for the red network zone (red0, ppp0, etc). +# if you change this also check speed.cgi that include a local copy for systemload reasons sub get_red_interface() { open(IFACE, "${General::swroot}/red/iface") or die "Could not open /var/ipfire/red/iface"; diff --git a/html/cgi-bin/speed.cgi b/html/cgi-bin/speed.cgi index b550fda52..651c3c0b3 100644 --- a/html/cgi-bin/speed.cgi +++ b/html/cgi-bin/speed.cgi @@ -19,7 +19,47 @@ # # ############################################################################### -require '/var/ipfire/general-functions.pl'; +############################################################################### +# functions copied from general-functions.pl for speed improvement because # +# loading and initializing the whole general-functions.pl every second create # +# high system load # +###########################################OA################################## +# +# Returns the output of a shell command +sub General__system_output($) { + my @command = @_; + my $pid; + my @output = (); + + unless ($pid = open(OUTPUT, "-|")) { + open(STDERR, ">&STDOUT"); + exec { ${command[0]} } @command; + die "Could not execute @command: $!"; + } + + waitpid($pid, 0); + + while () { + push(@output, $_); + } + + close(OUTPUT); + return @output; +} +# +# Function which will return the used interface for the red network zone (red0, ppp0, etc). +sub General__get_red_interface() { + + open(IFACE, "/var/ipfire/red/iface") or die "Could not open /var/ipfire/red/iface"; + + my $interface = ; + close(IFACE); + chomp $interface; + + return $interface; +} +# +############################################################################### my $data_last = $ENV{'QUERY_STRING'}; my $rxb_last = 0; @@ -38,8 +78,8 @@ foreach $field (@fields) { } } -my $interface = &General::get_red_interface(); -my @data_now = &General::system_output("ip", "-s", "link", "show", "$interface"); +my $interface = &General__get_red_interface(); +my @data_now = &General__system_output("ip", "-s", "link", "show", "$interface"); my $lastline; my $rxb_now = 0;