From rea-fbsd@codelabs.ru  Wed Mar 25 19:58:14 2009
Return-Path: <rea-fbsd@codelabs.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 8AD9E106566C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 25 Mar 2009 19:58:14 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45])
	by mx1.freebsd.org (Postfix) with ESMTP id 3979F8FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 25 Mar 2009 19:58:14 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from amnesiac.at.no.dns (ppp91-77-175-43.pppoe.mtu-net.ru [91.77.175.43])
	by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256)
	id 1LmZEq-000Kq8-Qy for FreeBSD-gnats-submit@freebsd.org; Wed, 25 Mar 2009 22:58:13 +0300
Received: by amnesiac.at.no.dns (Postfix, from userid 1001)
	id 071DA17123; Wed, 25 Mar 2009 22:58:06 +0300 (MSK)
Message-Id: <20090325195806.071DA17123@amnesiac.at.no.dns>
Date: Wed, 25 Mar 2009 22:58:06 +0300 (MSK)
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Reply-To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] net/isc-dhcp30-server, net/isc-dhcp30-server: check configuration file before restart
X-Send-Pr-Version: 3.113
X-GNATS-Notify: Joerg.Pulz@frm2.tum.de Joerg.Pulz@frm2.tum.de

>Number:         133072
>Category:       ports
>Synopsis:       [patch] net/isc-dhcp30-server, net/isc-dhcp30-server: check configuration file before restart
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jpaetzel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 25 20:00:02 UTC 2009
>Closed-Date:    Sat Jun 27 17:36:17 UTC 2009
>Last-Modified:  Sat Jun 27 17:40:02 UTC 2009
>Originator:     Eygene Ryabinkin
>Release:        FreeBSD 7.2-PRERELEASE amd64
>Organization:
Code Labs
>Environment:

System: FreeBSD 7.2-PRERELEASE amd64

>Description:

Had just been beaten by the following (silly) error: I had made a
mistake in the DHCP configuration file, restarted daemon and started to
scratch my head in order to understarnd why clients aren't getting their
IPs and other stuff.  I understarnd that it is my fault, but if rc.d
script will be able to test configuration and refuse to start with the
broken config file -- it will be great.

Moreover, there is no point in doing restart with the broken
configuration file -- it is better to leave the running instance.

>How-To-Repeat:

Make a mistake in the configuration file and do
'/usr/local/etc/rc.d/isc-dhcpd restart'.  You'll see the following
output:
-----
Stopping dhcpd.
Starting dhcpd.
-----
Sounds like everything is good, but in reality dhcpd daemon will not
be running.

>Fix:

The following patch adds the check both to the rc.d script for DHCPD 3.0
and 3.1.  I had tested it for 3.0, but it should also work for 3.1.

--- implement-configuration-file-check.diff begins here ---
From 5d719245842864e73515d976b8a32f20a9437db3 Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Date: Wed, 25 Mar 2009 22:29:31 +0300

This feature is very handy, because when 'restart' cmd is run with the
broken configuration file, rc.d script will show that it stops and
starts the daemon.  And one will discover that dhcp daemon isn't running
only on the next restart or looking at the process list -- not cool.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
---
 net/isc-dhcp30-server/files/isc-dhcpd.in |   20 ++++++++++++++++++++
 net/isc-dhcp31-server/files/isc-dhcpd.in |   20 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/net/isc-dhcp30-server/files/isc-dhcpd.in b/net/isc-dhcp30-server/files/isc-dhcpd.in
index 9532d91..0bc65bb 100644
--- a/net/isc-dhcp30-server/files/isc-dhcpd.in
+++ b/net/isc-dhcp30-server/files/isc-dhcpd.in
@@ -701,6 +701,25 @@ dhcpd_uninstall ()
 	fi
 }
 
+dhcpd_checkconfig ()
+{
+	local rc_flags_saved rc_flags_our
+	rc_flags_saved="$rc_flags"
+	setup_flags
+	# Eliminate '-q' flag if it is present
+	rc_flags_our=`echo "${rc_flags}" | sed -Ee's/(^-q | -q | -q$)'//`
+	rc_flags="${rc_flags_saved}"
+	if ${command} -t -q ${rc_flags_our}; then
+		true
+	else
+		echo "Configuration file sanity check failed:"
+		echo "======================================="
+		${command} -t ${rc_flags_our}
+		echo "======================================="
+		false
+	fi
+}
+
 rcvar=${name}_enable
 load_rc_config ${name}
 
@@ -719,6 +738,7 @@ pidfile=${_dhcpd_pidfile}
 required_files=${dhcpd_conf}
 start_precmd=${name}_precmd
 stop_postcmd=${name}_postcmd
+restart_precmd="dhcpd_checkconfig"
 install_cmd=dhcpd_install
 uninstall_cmd=dhcpd_uninstall
 extra_commands="install uninstall"
diff --git a/net/isc-dhcp31-server/files/isc-dhcpd.in b/net/isc-dhcp31-server/files/isc-dhcpd.in
index 6ed05f8..b526bfb 100644
--- a/net/isc-dhcp31-server/files/isc-dhcpd.in
+++ b/net/isc-dhcp31-server/files/isc-dhcpd.in
@@ -700,6 +700,25 @@ dhcpd_uninstall ()
 	fi
 }
 
+dhcpd_checkconfig ()
+{
+	local rc_flags_saved rc_flags_our
+	rc_flags_saved="$rc_flags"
+	setup_flags
+	# Eliminate '-q' flag if it is present
+	rc_flags_our=`echo "${rc_flags}" | sed -Ee's/(^-q | -q | -q$)'//`
+	rc_flags="${rc_flags_saved}"
+	if ${command} -t -q ${rc_flags_our}; then
+		true
+	else
+		echo "Configuration file sanity check failed:"
+		echo "======================================="
+		${command} -t ${rc_flags_our}
+		echo "======================================="
+		false
+	fi
+}
+
 rcvar=${name}_enable
 load_rc_config ${name}
 
@@ -718,6 +737,7 @@ pidfile=${_dhcpd_pidfile}
 required_files=${dhcpd_conf}
 start_precmd=${name}_precmd
 stop_postcmd=${name}_postcmd
+restart_precmd="dhcpd_checkconfig"
 install_cmd=dhcpd_install
 uninstall_cmd=dhcpd_uninstall
 extra_commands="install uninstall"
-- 
1.6.1.3
--- implement-configuration-file-check.diff ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->miwi 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Mar 25 20:00:23 UTC 2009 
Responsible-Changed-Why:  
miwi@ wants his PRs (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133072 
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Wed Mar 25 20:00:31 UTC 2009 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133072 

From: Edwin Groothuis <edwin@FreeBSD.org>
To: Joerg.Pulz@frm2.tum.de
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/133072: [patch] net/isc-dhcp30-server, net/isc-dhcp30-server: check configuration file before restart
Date: Wed, 25 Mar 2009 20:00:26 UT

 Maintainer of net/isc-dhcp30-server,
 
 Please note that PR ports/133072 has just been submitted.
 
 If it contains a patch for an upgrade, an enhancement or a bug fix
 you agree on, reply to this email stating that you approve the patch
 and a committer will take care of it.
 
 The full text of the PR can be found at:
     http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/133072
 
 -- 
 Edwin Groothuis via the GNATS Auto Assign Tool
 edwin@FreeBSD.org

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Joerg.Pulz@frm2.tum.de
Cc: bug-followup@freebsd.org
Subject: Re: ports/133072: [patch] net/isc-dhcp30-server,
	net/isc-dhcp30-server: check configuration file before restart
Date: Fri, 24 Apr 2009 07:56:05 +0400

 Joerg, good day.
 
 Could you, please, say something about this PR: is it absolutely mad
 thing to do?  Or it is useful, but should be changed in some ways (tell
 me, I'll try to make the needed modifications)?  Or you just have no
 time now and I should wait a bit?
 
 Thanks!
 -- 
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook
     {_.-``-'         {_/            #

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: bug-followup@freebsd.org
Cc: edwin@FreeBSD.org, Joerg.Pulz@frm2.tum.de, miwi@FreeBSD.org
Subject: Re: ports/133072: [patch] net/isc-dhcp30-server,
	net/isc-dhcp30-server: check configuration file before restart
Date: Tue, 5 May 2009 21:30:11 +0400

 Gentlemen, can I remind you about this PR?  If it is unacceptable,
 just say why ;))
 
 Thanks!
 -- 
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook
     {_.-``-'         {_/            #
Responsible-Changed-From-To: miwi->wxs 
Responsible-Changed-By: wxs 
Responsible-Changed-When: Sun May 10 23:35:17 UTC 2009 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133072 
Responsible-Changed-From-To: wxs->jpaetzel 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue May 12 22:45:47 UTC 2009 
Responsible-Changed-Why:  
Over to new maintainer, who (since he is a committer) gets the reassignment 
from wxs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133072 
State-Changed-From-To: feedback->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Sat Jun 27 17:35:46 UTC 2009 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=133072 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/133072: commit references a PR
Date: Sat, 27 Jun 2009 17:35:17 +0000 (UTC)

 jpaetzel    2009-06-27 17:35:08 UTC
 
   FreeBSD ports repository
 
   Modified files:
     net/isc-dhcp30-server/files patch-server::dhcpd.c isc-dhcpd.in 
     net/isc-dhcp30-server Makefile 
   Log:
   - Replace jail patch with one by jhb@
   - Add a checkconfig target to rcNG script
   
   PR:     ports/133072
   Submitted by:   rea-fbsd@codelabs.ru
   Approved by:    itetcu@ (mentor)
   
   Revision  Changes    Path
   1.134     +1 -1      ports/net/isc-dhcp30-server/Makefile
   1.7       +21 -1     ports/net/isc-dhcp30-server/files/isc-dhcpd.in
   1.5       +29 -36    ports/net/isc-dhcp30-server/files/patch-server::dhcpd.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
