[PATCH] Use SIGKILL to be able to immediately start a new dnsmasq afterwards



Hey,

attached you will find a patch which fixes a problem with dnsmasq for me. Quote
from the commit message:

Use SIGKILL to be able to immediately start a new dnsmasq afterwards

This fixes the problem that when updating the DNS configuration, dnsmasq would
fail to start up with a message like this:

May  5 14:43:47 x200 dnsmasq[5172]: failed to create listening socket for
127.0.0.1: Address already in use
May  5 14:43:47 x200 dnsmasq[5172]: FAILED to start up

The reason for that is that the other dnsmasq instance is still running — it
doesn’t react to SIGTERM at all, so it was still running and NM was waiting for
the 2-second timeout to happen.

You can easily verify that dnsmasq doesn’t react to SIGTERM:

x200 ~ $ ps aux | grep '[d]nsmasq'
nobody   26820  0.0  0.0  31136  1320 ?        S    14:58   0:00
/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces
--pid-file=/var/run/nm-dns-dnsmasq.pid --listen-address=127.0.0.1
--conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=400 --proxy-dnssec
x200 ~ $ sudo kill -TERM 26820
x200 ~ $ ps aux | grep '[d]nsmasq'
nobody   26820  0.0  0.0  31136  1320 ?        S    14:58   0:00
/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces
--pid-file=/var/run/nm-dns-dnsmasq.pid --listen-address=127.0.0.1
--conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=400 --proxy-dnssec

(This is dnsmasq 2.58)

Best regards,
Michael
>From 2ea9960a9d8f4b878adda2526d06e935899a9ccf Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael stapelberg de>
Date: Sat, 5 May 2012 14:56:51 +0200
Subject: [PATCH] Use SIGKILL to be able to immediately start a new dnsmasq
 afterwards
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes the problem that when updating the DNS configuration, dnsmasq would
fail to start up with a message like this:

May  5 14:43:47 x200 dnsmasq[5172]: failed to create listening socket for
127.0.0.1: Address already in use
May  5 14:43:47 x200 dnsmasq[5172]: FAILED to start up

The reason for that is that the other dnsmasq instance is still running — it
doesn’t react to SIGTERM at all, so it was still running and NM was waiting for
the 2-second timeout to happen.

You can easily verify that dnsmasq doesn’t react to SIGTERM:

x200 ~ $ ps aux | grep '[d]nsmasq'
nobody   26820  0.0  0.0  31136  1320 ?        S    14:58   0:00
/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces
--pid-file=/var/run/nm-dns-dnsmasq.pid --listen-address=127.0.0.1
--conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=400 --proxy-dnssec
x200 ~ $ sudo kill -TERM 26820
x200 ~ $ ps aux | grep '[d]nsmasq'
nobody   26820  0.0  0.0  31136  1320 ?        S    14:58   0:00
/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces
--pid-file=/var/run/nm-dns-dnsmasq.pid --listen-address=127.0.0.1
--conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=400 --proxy-dnssec

(This is dnsmasq 2.58)
---
 src/dns-manager/nm-dns-plugin.c |   21 ++++++---------------
 1 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/dns-manager/nm-dns-plugin.c b/src/dns-manager/nm-dns-plugin.c
index e997948..f7dc074 100644
--- a/src/dns-manager/nm-dns-plugin.c
+++ b/src/dns-manager/nm-dns-plugin.c
@@ -224,21 +224,12 @@ gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self)
 	}
 
 	if (priv->pid) {
-		KillInfo *info;
-
-		if (kill (priv->pid, SIGTERM) == 0) {
-			info = g_malloc0 (sizeof (KillInfo));
-			info->pid = priv->pid;
-			info->progname = g_strdup (priv->progname);
-			g_timeout_add_seconds (2, ensure_killed, info);
-		} else {
-			kill (priv->pid, SIGKILL);
-
-			/* ensure the child is reaped */
-			nm_log_dbg (LOGD_DNS, "waiting for %s pid %d to exit", priv->progname, priv->pid);
-			waitpid (priv->pid, NULL, 0);
-			nm_log_dbg (LOGD_DNS, "%s pid %d cleaned up", priv->progname, priv->pid);
-		}
+		kill (priv->pid, SIGKILL);
+
+		/* ensure the child is reaped */
+		nm_log_dbg (LOGD_DNS, "waiting for %s pid %d to exit", priv->progname, priv->pid);
+		waitpid (priv->pid, NULL, 0);
+		nm_log_dbg (LOGD_DNS, "%s pid %d cleaned up", priv->progname, priv->pid);
 		priv->pid = 0;
 		g_free (priv->progname);
 		priv->progname = NULL;
-- 
1.7.5.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]