$ac = $ARGV[1];
&ui_print_header(undef, $text{'edit_title'}, "");
$file = &action_filename($ac);
- open(FILE, $file);
- while(<FILE>) {
- $data .= $_;
- if (/^\s*(['"]?)([a-z]+)\1\)/i) {
- $hasarg{$2}++;
- }
- }
- close(FILE);
+ $data = &read_file_contents($file);
+ $hasarg = &get_action_args($file);
}
elsif ($ty == 1) {
# Editing an action in one of the runlevels
}
# Show if action is currently running
- if ($hasarg{'status'} && $config{'status_check'}) {
- $out = &backquote_command("$file status</dev/null 2>/dev/null");
- if ($out =~ /not\s+running/i ||
- $out =~ /no\s+server\s+running/i) {
+ if ($hasarg->{'status'} && $config{'status_check'}) {
+ $r = &action_running($file);
+ if ($r == 0) {
$status = "<font color=#ff0000>$text{'no'}</font>";
}
- elsif ($out =~ /running/i) {
+ elsif ($r == 1) {
$status = $text{'yes'};
}
- elsif ($out =~ /stopped/i) {
- $status = "<font color=#ff0000>$text{'no'}</font>";
- }
else {
$status = "<i>$text{'edit_unknown'}</i>";
}
$args = join("+", @ARGV);
print &ui_hidden("back", "edit_action.cgi?$args");
foreach $a (@action_buttons) {
- if ($a eq 'start' || $a eq 'stop' || $hasarg{$a}) {
+ if ($a eq 'start' || $a eq 'stop' || $hasarg->{$a}) {
push(@buts, [ $a, $text{'edit_'.$a.'now'} ]);
}
}
push(@cols, $order);
}
if ($config{'status_check'} == 2) {
- if ($actsl[$i] =~ /^0/) {
- local $out = $has{'status'} ?
- `$actsf[$i] status` : '';
- if ($out =~ /not\s+running/i ||
- $out =~ /no\s+server\s+running/i) {
+ if ($actsl[$i] =~ /^0/ && $has{'status'}) {
+ local $r = &action_running($actsf[$i]);
+ if ($r == 0) {
push(@cols,
"<font color=#ff0000>".
"$text{'no'}</font>");
}
- elsif ($out =~ /running/i) {
+ elsif ($r == 1) {
push(@cols, $text{'yes'});
}
- elsif ($out =~ /stopped/i) {
- push(@cols,
- "<font color=#ff0000>".
- "$text{'no'}</font>");
- }
else {
push(@cols, undef);
}
my $l = glob("/etc/rc$rl.d/S*$a");
$s->{'boot'} = $l ? 'start' : 'stop';
$s->{'desc'} = &init_description($f);
- my $out = &backquote_command("$f status 2>&1 </dev/null");
- if ($out =~ /not\s+running/i ||
- $out =~ /no\s+server\s+running/i ||
- $out =~ /not\s+access\s+PID/i) {
- $s->{'status'} = 'waiting';
- }
- elsif ($out =~ /running/i) {
- $s->{'status'} = 'running';
- }
- elsif ($out =~ /stopped/) {
- $s->{'status'} = 'waiting';
+ my $hasarg = &get_action_args($f);
+ if ($hasarg->{'status'}) {
+ my $r = &action_running($f);
+ if ($r == 0) {
+ $s->{'status'} = 'waiting';
+ }
+ elsif ($r == 1) {
+ $s->{'status'} = 'running';
+ }
}
push(@rv, $s);
}
&system_logged("$config{'shutdown_command'} >$null_file 2>$null_file");
}
+# get_action_args(filename)
+# Returns the args that this action script appears to support, like stop, start
+# and status.
+sub get_action_args
+{
+my ($file) = @_;
+my %hasarg;
+open(FILE, $file);
+while(<FILE>) {
+ if (/^\s*(['"]?)([a-z]+)\1\)/i) {
+ $hasarg{$2}++;
+ }
+ }
+close(FILE);
+return \%hasarg;
+}
+
+# action_running(filename)
+# Assuming some init.d action supports the status parameter, returns a 1 if
+# running, 0 if not, or -1 if unknown
+sub action_running
+{
+my ($file) = @_;
+my $out = &backquote_command("$file status");
+if ($out =~ /not\s+running/i ||
+ $out =~ /no\s+server\s+running/i) {
+ return 0;
+ }
+elsif ($out =~ /running/i) {
+ return 1;
+ }
+elsif ($out =~ /stopped/i) {
+ return 0;
+ }
+return -1;
+}
+
1;