[4.1] f9526a5 Move killing the child process into separate function

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Wed Oct 12 16:12:05 CEST 2016


commit f9526a52c5cbbd3bdd3e524d2f93949da4c411b4
Author: Pål Hermunn Johansen <hermunn at varnish-software.com>
Date:   Tue Oct 4 11:01:14 2016 +0200

    Move killing the child process into separate function
    
    A new function, kill_child() is introduced, so that kill() is only
    called from this function. This is a preparation of fixing the jail
    implementation.

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index f89f6d4..8acde5e 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -457,6 +457,14 @@ mgt_launch_child(struct cli *cli)
  * Cleanup when child dies.
  */
 
+static int
+kill_child(void) {
+	if (MGT_FEATURE(FEATURE_NO_COREDUMP))
+		return (kill(child_pid, SIGKILL));
+	else
+		return (kill(child_pid, SIGQUIT));
+}
+
 static void
 mgt_reap_child(void)
 {
@@ -506,10 +514,7 @@ mgt_reap_child(void)
 		VSB_printf(vsb, "Child (%jd) not dying, killing", (intmax_t)r);
 
 		/* Kick it Jim... */
-		if (MGT_FEATURE(FEATURE_NO_COREDUMP))
-			(void)kill(child_pid, SIGKILL);
-		else
-			(void)kill(child_pid, SIGQUIT);
+		(void)kill_child();
 		r = waitpid(child_pid, &status, 0);
 	}
 	if (r != child_pid)
@@ -588,17 +593,12 @@ mgt_reap_child(void)
 void
 MGT_Child_Cli_Fail(void)
 {
-	int i;
 
 	if (child_state != CH_RUNNING)
 		return;
 	if (child_pid < 0)
 		return;
-	if (MGT_FEATURE(FEATURE_NO_COREDUMP))
-		i = kill(child_pid, SIGKILL);
-	else
-		i = kill(child_pid, SIGQUIT);
-	if (i == 0)
+	if (kill_child() == 0)
 		MGT_complain(C_ERR, "Child (%jd) not responding to CLI,"
 		    " killing it.", (intmax_t)child_pid);
 	else



More information about the varnish-commit mailing list