[packages] olsrd: use system-logger instead of dumping to stdout

packages: olsrd: use system-logger instead of dumping to stdout,
which is cleaner and also seen if not interactive called. minor
cleanups in some messages, also show function-name in messages.
by using 'logger -s' we can see the message on screen and in logs.

Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>

git-svn-id: svn://svn.openwrt.org/openwrt/packages@35678 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
zioproto 2013-02-19 17:01:34 +00:00
parent 633dd52427
commit f3b6f348d4

View File

@ -20,6 +20,11 @@ T=' '
N=' N='
' '
log()
{
logger -t olsrd -p daemon.info -s "$1"
}
validate_varname() { validate_varname() {
local varname="$1" local varname="$1"
[ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1 [ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1
@ -75,6 +80,7 @@ olsrd_find_config_file() {
} }
warning_invalid_value() { warning_invalid_value() {
local funcname="warning_invalid_value"
local package="$1" local package="$1"
validate_varname "$package" || package= validate_varname "$package" || package=
local config="$2" local config="$2"
@ -82,14 +88,12 @@ warning_invalid_value() {
local option="$3" local option="$3"
validate_varname "$option" || option= validate_varname "$option" || option=
echo -n "Warning: Invalid value" 1>&2
if [ -n "$package" -a -n "$config" ]; then if [ -n "$package" -a -n "$config" ]; then
echo -n " in option '$package.$config${option:+.}$option'" 1>&2 log "$funcname() in option '$package.$config${option:+.}$option', skipped"
else
log "$funcname() skipped"
fi fi
echo ", skipped" 1>&2
return 0 return 0
} }
@ -127,6 +131,7 @@ olsrd_write_option() {
} }
olsrd_write_plparam() { olsrd_write_plparam() {
local funcname="olsrd_write_plparam"
local param="$1" local param="$1"
local cfg="$2" local cfg="$2"
validate_varname "$cfg" || return 1 validate_varname "$cfg" || return 1
@ -163,9 +168,9 @@ olsrd_write_plparam() {
if [ "$option" = 'NonOlsrIf' ]; then if [ "$option" = 'NonOlsrIf' ]; then
if validate_varname "$value"; then if validate_varname "$value"; then
if network_get_device ifname "$value"; then if network_get_device ifname "$value"; then
echo "Info: mdns Interface '$value' ifname '$ifname' found" 1>&2 log "$funcname() Info: mdns Interface '$value' ifname '$ifname' found"
else else
echo "Warning: mdns Interface '$value' not found, skipped" 1>&2 log "$funcname() Warning: mdns Interface '$value' not found, skipped"
fi fi
else else
warning_invalid_value olsrd "$cfg" "NonOlsrIf" warning_invalid_value olsrd "$cfg" "NonOlsrIf"
@ -399,6 +404,7 @@ olsrd_write_hna6() {
} }
olsrd_write_loadplugin() { olsrd_write_loadplugin() {
local funcname="olsrd_write_loadplugin"
local cfg="$1" local cfg="$1"
validate_varname "$cfg" || return 0 validate_varname "$cfg" || return 0
local ignore local ignore
@ -417,7 +423,7 @@ olsrd_write_loadplugin() {
return 0 return 0
fi fi
if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then
echo "Warning: Plugin library '$library' not found, skipped" 1>&2 log "$funcname() Warning: Plugin library '$library' not found, skipped"
return 0 return 0
fi fi
@ -462,6 +468,7 @@ olsrd_write_loadplugin() {
} }
olsrd_write_interface() { olsrd_write_interface() {
local funcname="olsrd_write_interface"
local cfg="$1" local cfg="$1"
validate_varname "$cfg" || return 0 validate_varname "$cfg" || return 0
local ignore local ignore
@ -480,7 +487,7 @@ olsrd_write_interface() {
ifnames="$ifnames \"$IFNAME\"" ifnames="$ifnames \"$IFNAME\""
ifsglobal="$ifsglobal $IFNAME" ifsglobal="$ifsglobal $IFNAME"
else else
echo "Warning: Interface '$interface' not found, skipped" 1>&2 log "$funcname() Warning: Interface '$interface' not found, skipped"
fi fi
else else
warning_invalid_value olsrd "$cfg" "interface" warning_invalid_value olsrd "$cfg" "interface"
@ -552,8 +559,11 @@ olsrd_write_config() {
} }
olsrd_setup_smartgw_rules() { olsrd_setup_smartgw_rules() {
local funcname="olsrd_setup_smartgw_rules"
# Check if ipip is installed # Check if ipip is installed
[ ! -e /etc/modules.d/[0-9]*-ipip ] && echo "Warning: kmod-ipip is missing. SmartGateway will not work until you install it." [ -e /etc/modules.d/[0-9]*-ipip ] || {
log "$funcname() Warning: kmod-ipip is missing. SmartGateway will not work until you install it."
}
wanifnames=$(ip r l e 0/0 t all | sed -e 's/^.* dev //' |cut -d " " -f 1 | sort | uniq) wanifnames=$(ip r l e 0/0 t all | sed -e 's/^.* dev //' |cut -d " " -f 1 | sort | uniq)
nowan=0 nowan=0
@ -577,7 +587,7 @@ olsrd_setup_smartgw_rules() {
while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done
if [ "$smartgateway" == "yes" ]; then if [ "$smartgateway" == "yes" ]; then
echo "Notice: Inserting firewall rules for SmartGateway" log "$funcname() Notice: Inserting firewall rules for SmartGateway"
if [ ! "$smartgatewayuplink" == "none" ]; then if [ ! "$smartgatewayuplink" == "none" ]; then
if [ "$smartgatewayuplink" == "ipv4" ]; then if [ "$smartgatewayuplink" == "ipv4" ]; then
# Allow everything to be forwarded to tnl_+ and use NAT for it # Allow everything to be forwarded to tnl_+ and use NAT for it
@ -622,7 +632,7 @@ olsrd_setup_smartgw_rules() {
} }
error() { error() {
echo "${initscript}:" "$@" 1>&2 log "error() ${initscript}: $@"
} }
start() { start() {
@ -674,14 +684,14 @@ start() {
SERVICE_PID_FILE="$PID6" SERVICE_PID_FILE="$PID6"
if service_check /usr/sbin/olsrd; then if service_check /usr/sbin/olsrd; then
error "there already is an IPv6 instance of olsrd running ($(cat $PID6)), not starting." error "there is already an IPv6 instance of olsrd running (pid: '$(cat $PID6)'), not starting."
else else
service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv6 -nofork service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv6 -nofork
fi fi
SERVICE_PID_FILE="$PID" SERVICE_PID_FILE="$PID"
if service_check /usr/sbin/olsrd; then if service_check /usr/sbin/olsrd; then
error "there already is an IPv4 instance of olsrd running ($(cat $PID)), not starting." error "there is already an IPv4 instance of olsrd running (pid: '$(cat $PID)'), not starting."
else else
service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv4 -nofork service_start /usr/sbin/olsrd -f /var/etc/olsrd.conf.ipv4 -nofork
fi fi
@ -697,7 +707,7 @@ start() {
SERVICE_PID_FILE="$PID" SERVICE_PID_FILE="$PID"
if service_check /usr/sbin/olsrd; then if service_check /usr/sbin/olsrd; then
error "there already is an IPv4 instance of olsrd running ($(cat $PID)), not starting." error "there is already an IPv4 instance of olsrd running (pid: '$(cat $PID)'), not starting."
return 1 return 1
else else
service_start /usr/sbin/olsrd -f "$OLSRD_CONFIG_FILE" -nofork service_start /usr/sbin/olsrd -f "$OLSRD_CONFIG_FILE" -nofork