+
+ $Lang::tr{'services'} |
+ $Lang::tr{'status'} |
+ PID |
+ $Lang::tr{'memory'} |
+
END
;
my $key = '';
+ my $col="";
foreach $key (sort keys %servicenames){
$lines++;
if ($lines % 2){
- print "\n";
- print %link->{$key};
- print " | \n";
+ $col="bgcolor='$color{'color22'}'";
+ print "
";
+ print $link{$key};
+ print " | ";
}else{
- print "
\n";
- print %link->{$key};
- print " | \n";
+ $col="bgcolor='$color{'color20'}'";
+ print "
";
+ print $link{$key};
+ print " | ";
}
my $shortname = $servicenames{$key};
- my $status = &isrunning($shortname);
+ my $status = &isrunning($shortname,$col);
print "$status\n";
print "
\n";
@@ -147,19 +141,19 @@ END
my $paramstr=$ENV{QUERY_STRING};
my @param=split(/!/, $paramstr);
if ($param[1] ne ''){
- system("/usr/local/bin/addonctrl @param[0] @param[1] > /dev/null 2>&1");
+ &General::system("/usr/local/bin/addonctrl", "$param[0]", "$param[1]");
}
print <
-
-
-Addon |
-Boot |
-$Lang::tr{'action'} |
-$Lang::tr{'status'} |
-PID |
-$Lang::tr{'memory'} |
+
+
+ Addon |
+ Boot |
+ $Lang::tr{'action'} |
+ $Lang::tr{'status'} |
+ PID |
+ $Lang::tr{'memory'} |
END
;
@@ -167,32 +161,41 @@ END
my $lines=0; # Used to count the outputlines to make different bgcolor
# Generate list of installed addon pak's
- my @pak = `find /opt/pakfire/db/installed/meta-* 2>/dev/null | cut -d"-" -f2`;
+ opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!";
+ my @pak = sort readdir DIR;
+ closedir(DIR);
+
foreach (@pak){
chomp($_);
+ next unless (m/^meta-/);
+ s/^meta-//;
# Check which of the paks are services
- my @svc = `find /etc/init.d/$_ 2>/dev/null | cut -d"/" -f4`;
- foreach (@svc){
+ if (-e "/etc/init.d/$_") {
# blacklist some packages
#
# alsa has trouble with the volume saving and was not really stopped
# mdadm should not stopped with webif because this could crash the system
#
- chomp($_);
+ if ( $_ eq 'squid' ) {
+ next;
+ }
if ( ($_ ne "alsa") && ($_ ne "mdadm") ) {
$lines++;
if ($lines % 2){
- print "";
+ print "
";
+ $col="bgcolor='$color{'color22'}'";
}else{
- print "
";
+ print "
";
+ $col="bgcolor='$color{'color20'}'";
}
- print "$_ | ";
- my $status = isautorun($_);
+
+ print "$_ | ";
+ my $status = isautorun($_,$col);
print "$status ";
- print " | ";
- print " | ";
- my $status = &isrunningaddon($_);
+ print " | ";
+ print " | ";
+ my $status = &isrunningaddon($_,$col);
$status =~ s/\\[[0-1]\;[0-9]+m//g;
chomp($status);
@@ -217,33 +220,75 @@ END
&Header::closepage();
}
-sub isautorun{
- my $cmd = $_[0];
- my $status = " | ";
- my $init = `find /etc/rc.d/rc3.d/S??${cmd} 2>/dev/null`;
- chomp ($init);
- if ($init ne ''){
- $status = " | ";
- }
- $init = `find /etc/rc.d/rc3.d/off/S??${cmd} 2>/dev/null`;
- chomp ($init);
- if ($init ne ''){
- $status = " | ";
+sub isautorun (@) {
+ my ($cmd, $col) = @_;
+
+ # Init directory.
+ my $initdir = "/etc/rc.d/rc3.d/";
+
+ my $status = " | ";
+
+ # Check if autorun for the given cmd is enabled.
+ if ( &find_init("$cmd", "$initdir") ) {
+ # Adjust status.
+ $status = " | ";
+ } else {
+ # Adjust status.
+ $status = " | ";
}
+ # Return the status.
return $status;
}
-sub isrunning{
- my $cmd = $_[0];
- my $status = "$Lang::tr{'stopped'} | | ";
+sub find_init (@) {
+ my ($cmd, $dir) = @_;
+
+ # Open given init directory.
+ opendir (INITDIR, "$dir") || die "Cannot opendir $dir: $!";
+
+ # Read-in init files from directory.
+ my @inits = readdir(INITDIR);
+
+ # Close directory handle.
+ closedir(INITDIR);
+
+ # Loop through the directory.
+ foreach my $init (@inits) {
+ # Check if the current processed file belongs to the given command.
+ if ($init =~ /S\d+\d+$cmd\z/) {
+ # Found, return "1" - True.
+ return "1";
+ }
+ }
+
+ # Nothing found, return nothing.
+ return;
+}
+
+sub isrunning (@) {
+ my ($cmd, $col) = @_;
+ my $status = "$Lang::tr{'stopped'} | | ";
my $pid = '';
my $testcmd = '';
my $exename;
my $memory;
$cmd =~ /(^[a-z]+)/;
- $exename = $1;
+
+ # Check if the exename needs to be overwritten.
+ # This happens if the expected process name string
+ # differs from the real one. This may happened if
+ # a service uses multiple processes or threads.
+ if (exists($overwrite_exename_hash{$1})) {
+ # Grab the string which will be reported by
+ # the process from the corresponding hash.
+ $exename = $overwrite_exename_hash{$1};
+ } else {
+ # Directly expect the launched command as
+ # process name.
+ $exename = $1;
+ }
if (open(FILE, "/var/run/${cmd}.pid")){
$pid = ; chomp $pid;
@@ -267,21 +312,23 @@ sub isrunning{
close(FILE);
}
if ($testcmd =~ /$exename/){
- $status = "$Lang::tr{'running'} | $pid | $memory | ";
+ $status = "$Lang::tr{'running'} | $pid | $memory | ";
}
}
return $status;
}
-sub isrunningaddon{
- my $cmd = $_[0];
- my $status = "$Lang::tr{'stopped'} | | ";
+sub isrunningaddon (@) {
+ my ($cmd, $col) = @_;
+
+ my $status = "$Lang::tr{'stopped'} | | ";
my $pid = '';
my $testcmd = '';
my $exename;
my @memory;
- my $testcmd = `/usr/local/bin/addonctrl $_ status 2>/dev/null`;
+ my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$cmd", "status");
+ my $testcmd = @testcmd[0];
if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){
$status = "$Lang::tr{'running'} | ";
@@ -293,7 +340,7 @@ sub isrunningaddon{
$testcmd =~ s///gi;
my @pid = split(/\s/,$testcmd);
- $status .="$pid[0] | ";
+ $status .="$pid[0] | ";
my $memory = 0;
@@ -305,9 +352,9 @@ sub isrunningaddon{
}
$memory+=$memory[0];
}
- $status .="$memory KB | ";
+ $status .="$memory KB | ";
}else{
- $status = "$Lang::tr{'stopped'} | | ";
+ $status = "$Lang::tr{'stopped'} | | ";
}
return $status;
}