]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgpolicy: improve pre_server_close_hook
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Feb 2017 11:33:39 +0000 (12:33 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Feb 2017 11:33:39 +0000 (12:33 +0100)
wait for children

bin/pmg-smtp-filter
bin/pmgpolicy

index 1dd6d6a703e1c622e1d229ca15e9a290418df9e7..8e86948f26a21ca0977b76b2ef32bbdf7e099919 100755 (executable)
@@ -885,12 +885,14 @@ sub pre_server_close_hook {
     }
 
     # nicely shutdown childs (give them max 30 seconds to shut down)
-    my $previous_alarm = alarm (30);
+    my $previous_alarm = alarm(30);
     eval {
        local $SIG{ALRM} = sub { die "Timed Out!\n" };
 
        my $pid;
        1 while ((($pid = waitpid (-1, 0)) > 0) || ($! == EINTR));
+
+       alarm(0); # avoid race
     };
     alarm ($previous_alarm);
 }
index 94e2b1cb3f1929fb75ce86ca1775a76fde3226e0..742aca3609bf31c917255ebd8af14a265703d265 100755 (executable)
@@ -254,7 +254,7 @@ sub pre_loop_hook {
        # reloading server configuration
        if (defined $prop->{children}) {
            foreach my $pid (keys %{$prop->{children}}) {
-               kill (10, $pid); # SIGUSR1 childs
+               kill(10, $pid); # SIGUSR1 childs
            }
        }
     };
@@ -757,6 +757,24 @@ sub pre_server_close_hook {
     if (defined $prop->{_HUP}) {
        undef $prop->{pid_file_unlink};
     }
+
+    if (defined $prop->{children}) {
+       foreach my $pid (keys %{$prop->{children}}) {
+           kill(1, $pid); # HUP childs
+       }
+    }
+
+    # nicely shutdown childs (give them max 30 seconds to shut down)
+    my $previous_alarm = alarm(30);
+    eval {
+       local $SIG{ALRM} = sub { die "Timed Out!\n" };
+
+       my $pid;
+       1 while ((($pid = waitpid(-1, 0)) > 0) || ($! == EINTR));
+
+       alarm(0); # avoid race
+    };
+    alarm ($previous_alarm);
 }
 
 sub setup_fork_signal_mask {