]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Daemon.pm
tools: add fchownat syscall
[pve-common.git] / src / PVE / Daemon.pm
index 55a03fca3eacbdc9d18c34de4fac50b366a0f8d6..e3e43d9b3f0561998c6318eaf16d2a856ffd360d 100644 (file)
@@ -3,7 +3,7 @@ package PVE::Daemon;
 # Abstract class to implement Daemons
 #
 # Features:
-# * lock and write PID file /var/run/$name.pid to make sure onyl
+# * lock and write PID file /var/run/$name.pid to make sure only
 #   one instance is running.
 # * keep lock open during restart
 # * correctly daemonize (redirect STDIN/STDOUT)
@@ -102,9 +102,9 @@ my $lockpidfile = sub {
 
        my ($running, $pid) = $self->running();
        if ($running) {
-           die "can't aquire lock '$lkfn' - daemon already started (pid = $pid)\n";
+           die "can't acquire lock '$lkfn' - daemon already started (pid = $pid)\n";
        } else {
-           die "can't aquire lock '$lkfn' - $err\n";
+           die "can't acquire lock '$lkfn' - $err\n";
        }
     }
 };
@@ -192,21 +192,16 @@ my $terminate_server = sub {
 
     $self->{terminate} = 1; # set flag to avoid worker restart
 
-    if (!$self->{max_workers}) {
-       eval { $self->shutdown(); };
-       warn $@ if $@;
-       return;
-    }
-
     eval { $self->shutdown(); };
     warn $@ if $@;
 
+    return if !$self->{max_workers}; # if we have no workers we're done here
 
     # if configured, leave children running on HUP
     return if $allow_open_children && $self->{leave_children_open_on_reload};
 
     # else send TERM to all (old and current) child workers
-    kill 15, keys %{$self->@{'workers','old_workers'}};
+    kill 15, (keys %{$self->{workers}}, keys %{$self->{old_workers}});
 
     # nicely shutdown childs (give them max 10 seconds to shut down)
     my $previous_alarm = alarm(10);
@@ -285,7 +280,12 @@ sub setup {
 
     if ($restart && $self->{max_workers}) {
        if (my $wpids = $ENV{PVE_DAEMON_WORKER_PIDS}) {
-           $self->{old_workers}->{$_} = 1 foreach (split(':', $wpids));
+           foreach my $pid (split(':', $wpids)) {
+               # check & untaint
+               if ($pid =~ m/^(\d+)$/) {
+                   $self->{old_workers}->{$1} = 1;
+               }
+           }
        }
     }
 
@@ -495,7 +495,7 @@ sub restart_daemon {
     }
 
     if ($self->{max_workers}) {
-       my @workers = keys %{$self->{workers}}, keys %{$self->{old_workers}};
+       my @workers = (keys %{$self->{workers}}, keys %{$self->{old_workers}});
        $ENV{PVE_DAEMON_WORKER_PIDS} = join(':', @workers);
     }