diff mbox

[1/1] package/dnsmasq: let init script cleanup stale pidfile

Message ID 1416068836-4053-1-git-send-email-jkrause@posteo.de
State Not Applicable
Headers show

Commit Message

Jörg Krause Nov. 15, 2014, 4:27 p.m. UTC
dnsmasq does not clean up its pidfile after termination. Do this manually.

Supersedes: [PATCH 1/1] package/dnsmasq: cleanup run-time files in init script
https://patchwork.ozlabs.org/patch/411015/

Signed-off-by: Jörg Krause <jkrause@posteo.de>
---
 package/dnsmasq/S80dnsmasq | 2 ++
 1 file changed, 2 insertions(+)

Comments

Gustavo Zacarias Dec. 9, 2014, 8:04 p.m. UTC | #1
On 11/15/2014 01:27 PM, Jörg Krause wrote:

> dnsmasq does not clean up its pidfile after termination. Do this manually.
> 
> Supersedes: [PATCH 1/1] package/dnsmasq: cleanup run-time files in init script
> https://patchwork.ozlabs.org/patch/411015/

Hi.
Does it fix anything in particular other than looks?
Looking at the dnsmasq source it does an unlink() on successful
startup/fork so any previous pidfile doesn't bother it at all.
I was about to say "i'd like to see the start-stop-daemon invocation
changed" but then i realized that it doesn't remove the pidfile either,
so basically any "start-stop-daemon -K -q -x" in any initscript
"suffers" from this "problem".
So even if the pidfile is on permanent storage i don't see how this can
cause issues.
Regards.
Jörg Krause Dec. 9, 2014, 9:35 p.m. UTC | #2
On Di, 2014-12-09 at 17:04 -0300, Gustavo Zacarias wrote:
> On 11/15/2014 01:27 PM, Jörg Krause wrote:
> 
> > dnsmasq does not clean up its pidfile after termination. Do this manually.
> > 
> > Supersedes: [PATCH 1/1] package/dnsmasq: cleanup run-time files in init script
> > https://patchwork.ozlabs.org/patch/411015/
> 
> Hi.
> Does it fix anything in particular other than looks?
> Looking at the dnsmasq source it does an unlink() on successful
> startup/fork so any previous pidfile doesn't bother it at all.
> I was about to say "i'd like to see the start-stop-daemon invocation
> changed" but then i realized that it doesn't remove the pidfile either,
> so basically any "start-stop-daemon -K -q -x" in any initscript
> "suffers" from this "problem".
> So even if the pidfile is on permanent storage i don't see how this can
> cause issues.
> Regards.
> 

I want to check in a script if the dnsmasq daemon is running by testing
for the existence of the pid file.
Gustavo Zacarias Dec. 9, 2014, 9:48 p.m. UTC | #3
On 12/09/2014 06:35 PM, Jörg Krause wrote:

> I want to check in a script if the dnsmasq daemon is running by testing
> for the existence of the pid file.

Generally speaking it's bad practice to just check the pidfile to know
if some daemon is running, because if it dies unexpectedly you'll still
have the pidfile around.
You should probably use a double check of pidfile and match the process,
something like (in shell):

grep dnsmasq /proc/`cat /var/run/dnsmasq.pid`/cmdline >/dev/null 2>&1 &&
echo "YES" || echo "NO"

Regards.
Jörg Krause Dec. 9, 2014, 9:58 p.m. UTC | #4
On Di, 2014-12-09 at 18:48 -0300, Gustavo Zacarias wrote:
> On 12/09/2014 06:35 PM, Jörg Krause wrote:
> 
> > I want to check in a script if the dnsmasq daemon is running by testing
> > for the existence of the pid file.
> 
> Generally speaking it's bad practice to just check the pidfile to know
> if some daemon is running, because if it dies unexpectedly you'll still
> have the pidfile around.
> You should probably use a double check of pidfile and match the process,
> something like (in shell):
> 
> grep dnsmasq /proc/`cat /var/run/dnsmasq.pid`/cmdline >/dev/null 2>&1 &&
> echo "YES" || echo "NO"

I thought so. I've seen it in some other scripts... Many thanks for the
advice!
Gustavo Zacarias Dec. 10, 2014, 8:56 p.m. UTC | #5
On 12/09/2014 06:58 PM, Jörg Krause wrote:

> I thought so. I've seen it in some other scripts... Many thanks for the
> advice!

I'll mark the patch as "not applicable" since it doesn't really address
the core issue.
Thanks.
Regards.
diff mbox

Patch

diff --git a/package/dnsmasq/S80dnsmasq b/package/dnsmasq/S80dnsmasq
index 587751e..ca74d8b 100755
--- a/package/dnsmasq/S80dnsmasq
+++ b/package/dnsmasq/S80dnsmasq
@@ -13,6 +13,8 @@  case "$1" in
 		echo -n "Stopping dnsmasq: "
 		start-stop-daemon -K -q -x /usr/sbin/dnsmasq
 		[ $? = 0 ] && echo "OK" || echo "FAIL"
+		# dnsmasq does not clean its pid file
+		rm -f /var/run/dnsmasq.pid
 		;;
 	restart|reload)
 		$0 stop