[PATCHES] selftest: improvements to cleanup_child()

Michael Adam obnox at samba.org
Tue May 24 07:33:22 UTC 2016


Hi,

While working on the clusteredmember selftest target,
these small improvements to cleanup_child() dropped out below... :-)

Review appreciated.

Thanks - Michael
-------------- next part --------------
From 62183b9b62f4de8a24ce531fd9338ab88599dc97 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 14 May 2016 00:38:48 +0200
Subject: [PATCH 1/4] selftest: fix printf in cleanup_child()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 selftest/target/Samba.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm
index 3e535a5..51163a8 100644
--- a/selftest/target/Samba.pm
+++ b/selftest/target/Samba.pm
@@ -322,7 +322,7 @@ sub cleanup_child($$)
 
     if ($childpid == 0) {
     } elsif ($childpid < 0) {
-	printf STDERR "%s child process %d isn't here any more\n",
+	printf STDERR "%s child process %d isn't here any more\n", $name, $pid;
 	return $childpid;
     }
     elsif ($? & 127) {
-- 
2.5.5


From 7f2670ea55bc50d211dfbd912469556ea286a562 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 14 May 2016 00:44:18 +0200
Subject: [PATCH 2/4] selftest: improve misleading indentation in
 cleanup_child()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 selftest/target/Samba.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm
index 51163a8..16c9788 100644
--- a/selftest/target/Samba.pm
+++ b/selftest/target/Samba.pm
@@ -327,7 +327,7 @@ sub cleanup_child($$)
     }
     elsif ($? & 127) {
 	printf STDERR "%s child process %d, died with signal %d, %s coredump\n",
-	$name, $childpid, ($? & 127),  ($? & 128) ? 'with' : 'without';
+		$name, $childpid, ($? & 127),  ($? & 128) ? 'with' : 'without';
     } else {
 	printf STDERR "%s child process %d exited with value %d\n", $name, $childpid, $? >> 8;
     }
-- 
2.5.5


From b07808fb96339eb2f70339d648da176b51fc20fb Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 14 May 2016 00:49:40 +0200
Subject: [PATCH 3/4] selftest: improve logic in cleanup_child() with early
 return

Signed-off-by: Michael Adam <obnox at samba.org>
---
 selftest/target/Samba.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm
index 16c9788..9293211 100644
--- a/selftest/target/Samba.pm
+++ b/selftest/target/Samba.pm
@@ -314,12 +314,14 @@ sub get_interface($)
 sub cleanup_child($$)
 {
     my ($pid, $name) = @_;
-    my $childpid = -1;
 
-    if (defined($pid)) {
-        $childpid = waitpid($pid, WNOHANG);
+    if (!defined($pid)) {
+        print STDERR "cleanup_child: pid not defined ... not calling waitpid\n";
+        return -1;
     }
 
+    my $childpid = waitpid($pid, WNOHANG);
+
     if ($childpid == 0) {
     } elsif ($childpid < 0) {
 	printf STDERR "%s child process %d isn't here any more\n", $name, $pid;
-- 
2.5.5


From 755fec4b3087dc6309ed393320395dc9380df023 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Sat, 14 May 2016 00:51:19 +0200
Subject: [PATCH 4/4] selftest: systematize formatting of if/elseif/else
 indentation in cleanup_child

Signed-off-by: Michael Adam <obnox at samba.org>
---
 selftest/target/Samba.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/selftest/target/Samba.pm b/selftest/target/Samba.pm
index 9293211..fcf2be3 100644
--- a/selftest/target/Samba.pm
+++ b/selftest/target/Samba.pm
@@ -326,8 +326,7 @@ sub cleanup_child($$)
     } elsif ($childpid < 0) {
 	printf STDERR "%s child process %d isn't here any more\n", $name, $pid;
 	return $childpid;
-    }
-    elsif ($? & 127) {
+    } elsif ($? & 127) {
 	printf STDERR "%s child process %d, died with signal %d, %s coredump\n",
 		$name, $childpid, ($? & 127),  ($? & 128) ? 'with' : 'without';
     } else {
-- 
2.5.5

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160524/1e949287/signature.sig>


More information about the samba-technical mailing list