Make reload function resilient to miniserv not running as well
authorJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:41:58 +0000 (15:41 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 2 May 2011 22:41:58 +0000 (15:41 -0700)
web-lib-funcs.pl

index 1c122e9..b1e9ee1 100755 (executable)
@@ -1949,6 +1949,10 @@ sub reload_miniserv
 return undef if (&is_readonly_mode());
 my %miniserv;
 &get_miniserv_config(\%miniserv) || return;
+if ($main::webmin_script_type eq 'web' && !$ENV{"MINISERV_CONFIG"}) {
+       # Running under some web server other than miniserv, so do nothing
+       return;
+       }
 
 if ($gconfig{'os_type'} ne 'windows') {
        # Send a USR1 signal to re-read the config
@@ -1956,11 +1960,22 @@ if ($gconfig{'os_type'} ne 'windows') {
        $miniserv{'inetd'} && return;
        $pid = $ENV{'MINISERV_PID'};
        if (!$pid) {
-               open(PID, $miniserv{'pidfile'}) ||
-                       &error("Failed to open PID file $miniserv{'pidfile'}");
+               if (!open(PID, $miniserv{'pidfile'})) {
+                       print STDERR "PID file $miniserv{'pidfile'} does ",
+                                    "not exist\n";
+                       return;
+                       }
                chop($pid = <PID>);
                close(PID);
-               $pid || &error("Invalid PID file $miniserv{'pidfile'}");
+               if (!$pid) {
+                       print STDERR "Invalid PID file $miniserv{'pidfile'}\n";
+                       return;
+                       }
+               if (!kill(0, $pid)) {
+                       print STDERR "PID $pid from file $miniserv{'pidfile'} ",
+                                    "is not valid\n";
+                       return;
+                       }
                }
        &kill_logged('USR1', $pid) || &error("Incorrect Webmin PID $pid");