Skip to contentSkip to conversation

clone/clone07: only kill child if clone() succeeded

PATCH New Han Pingtian 2 participants 2 messages Apr 14, 2016 – Apr 19, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clone/clone07: only kill child if clone() succeeded

Or when -1 passed as pid to kill(), a lot of processes will be killed.

---
 testcases/kernel/syscalls/clone/clone07.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/clone/clone07.c +6 -1
index 8c723de..ed59670 100644
@@ -64,6 +64,10 @@ int main(int ac, char **av)
 
 		child_pid = ltp_clone(SIGCHLD, do_child, NULL,
 				      CHILD_STACK_SIZE, child_stack);
+
+		if (child_pid < 0)
+			tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
 		if ((wait(&status)) == -1)
 			tst_brkm(TBROK | TERRNO, cleanup,
 				 "wait failed, status: %d", status);
@@ -107,7 +111,8 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	kill(child_pid, SIGKILL);
+	if (child_pid > 0)
+		kill(child_pid, SIGKILL);
 }
 
 static int do_child(void)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 clone/clone07: only kill child if clone() succeeded

Hi!

testcases/kernel/syscalls/clone/clone07.c static void setup(void) · line 116

Quoted 6 lines

static void cleanup(void)
{

testcases/kernel/syscalls/clone/clone07.c +2 -1
-	kill(child_pid, SIGKILL);
+	if (child_pid > 0)
+		kill(child_pid, SIGKILL);
 }

Looking at the code, the child does just return 0 (which exits the child process). There is no need to kill the child_pid in cleanup at all. So I've removed the cleanup function and pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]