Hi,

This another patch for the init script which adds a check_config
function and call it prior of, start and reload.

It should be applied on top the other patch I sent on 2nd Sep.

Cheers,
Pavlos
From 2bffdb2363ca63537281ef542808bfe7bb60015e Mon Sep 17 00:00:00 2001
From: Pavlos Parissis <[email protected]>
Date: Sun, 5 Oct 2014 21:32:03 +0200
Subject: [PATCH] bird.init: Added a check_config function and call it prior of
 start and reload

Bird always checks for the validity of the configuration before it loads it
and logs if configuration is not valid. But, the init script returns exit code 0
in this case. This patch makes init to report back to the caller that the current
configuration is invalid and doesn't proceed to reload or start.
---
 misc/bird.init | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/misc/bird.init b/misc/bird.init
index d47fbbd..0ec1edc 100755
--- a/misc/bird.init
+++ b/misc/bird.init
@@ -36,12 +36,22 @@ BIRD6ARGS=
 [ -e /etc/sysconfig/bird ] && . /etc/sysconfig/bird
 
 RETVAL=0
+check_config() {
+	local _bird=$1 && shift
+	/usr/sbin/"${_bird}" -p -c /etc/"${_bird}".conf
+	if [ $? -ne 0 ]
+	then
+		echo "Configuration invalid"
+		exit 1
+	fi
+}
 
 # See how we were called.
 case "$1" in
   start)
 	if [ "$BIRD4" = "yes" ]
 	then
+		check_config "bird"
 		echo -n "Starting BIRD for IPv4: "
 		daemon bird ${BIRD4ARGS}
 		RETVAL=$?
@@ -50,6 +60,7 @@ case "$1" in
 	fi
 	if [ "$BIRD6" = "yes" ]
 	then
+		check_config "bird6"
 		echo -n "Starting BIRD for IPv6: "
 		daemon bird6 ${BIRD6ARGS}
 		RETVAL=$?
@@ -96,6 +107,7 @@ case "$1" in
   reload)
 	if [ "$BIRD4" = "yes" ]
 	then
+		check_config "bird"
 		echo -n "Reloading BIRD for IPv4: "
 		killproc bird -HUP
 		RETVAL=$?
@@ -103,6 +115,7 @@ case "$1" in
 	fi
 	if [ "$BIRD6" = "yes" ]
 	then
+		check_config "bird6"
 		echo -n "Reloading BIRD for IPv6: "
 		killproc bird6 -HUP
 		RETVAL=$?
-- 
2.1.0

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to