[pmg-devel] [PATCH pmg-api 2/2] test_greylist: remove use of system

Stoiko Ivanov s.ivanov at proxmox.com
Tue Apr 21 12:43:30 CEST 2020


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 at proxmox.com>
---
 src/tests/test_greylist.pl | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/tests/test_greylist.pl b/src/tests/test_greylist.pl
index de7267b..258a682 100755
--- a/src/tests/test_greylist.pl
+++ b/src/tests/test_greylist.pl
@@ -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";
 
-- 
2.20.1




More information about the pmg-devel mailing list