]> git.proxmox.com Git - pmg-api.git/commitdiff
test_greylist: remove use of system
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 21 Apr 2020 10:43:30 +0000 (12:43 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 21 Apr 2020 16:42:37 +0000 (18:42 +0200)
the pmgpolicy daemon started for the tests needs to be stopped (by sending
a SIGTERM).
Instead of resorting to system, use perl's builtin kill.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/tests/test_greylist.pl

index de7267b514b8965e06d785f5acfb20d3144719c5..258a6826021d36a9f58ab4dd056c4eee72744fd8 100755 (executable)
@@ -25,6 +25,17 @@ my $testpidfn = "greylist-test-$$.pid";
 
 system ("perl -I.. ../bin/pmgpolicy -d $testdb -t --port $testport --pidfile '$testpidfn'");
 
+sub exit_test_pmgpolicy {
+    my $pid = PVE::Tools::file_read_firstline($testpidfn);
+    die "could not read pidfile: $!\n" if !$pid;
+
+    die "could not find pid in pidfile\n" if $pid !~ m/^(\d+)$/;
+    $pid = $1;
+
+    kill ('TERM', $pid);
+    unlink($testpidfn);
+}
+
 sub reset_gldb {
     my $dbh = PMG::DBTools::open_ruledb($testdb);
     $dbh->do ("DELETE FROM CGreylist");
@@ -56,7 +67,7 @@ sub gltest {
     chomp $res;
     if ($res !~ m/^action=$eres(\s.*)?/) {
        my $timediff = $ttime - $starttime;
-       system("kill `cat $testpidfn`") if -f $testpidfn;
+       exit_test_pmgpolicy();
        die "unexpected result at time $timediff: $res != $eres\n$data"
     }
 }
@@ -215,8 +226,7 @@ _EOD
 
 gltest ($data_fail, $testtime, 'reject');
 
-system("kill `cat $testpidfn`") if -f $testpidfn;
-unlink($testpidfn);
+exit_test_pmgpolicy();
 
 print "ALL TESTS OK\n";