File 0012-netconfig-improved-troubleshooting-capabilities.patch of Package sysconfig.2730
From 36fe7d1c2ca6862ac5c121a294f3d53f9b8ab560 Mon Sep 17 00:00:00 2001
From: Marius Tomaschewski <mt@suse.com>
Date: Wed, 19 Mar 2014 13:44:05 +0100
Subject: [PATCH] netconfig: improved troubleshooting capabilities
References: bnc#860644, bnc#868323
Upstream: yes
Added NETCONFIG_VERBOSE and NETCONFIG_FORCE_REPLACE config
variables allowing to run all netconfig calls in debug mode
and force update of modified files as default. Show service,
policy resolving info and log the commandline in debug mode.
Fixed to log info/warnings that were printed to stderr only
before (bnc#860644, bnc#868323).
---
config/sysconfig.config-network | 23 ++++++++++++++++++++
scripts/functions.netconfig | 45 +++++++++++++++++++++++++++++++---------
scripts/netconfig | 31 +++++++++++++++------------
scripts/netconfig.d/dns-bind | 4 ++--
scripts/netconfig.d/dns-dnsmasq | 4 ++--
scripts/netconfig.d/dns-resolver | 4 ++--
scripts/netconfig.d/nis | 4 ++--
scripts/netconfig.d/ntp-runtime | 4 ++--
8 files changed, 86 insertions(+), 33 deletions(-)
diff --git a/config/sysconfig.config-network b/config/sysconfig.config-network
index f70ca01..4393526 100644
--- a/config/sysconfig.config-network
+++ b/config/sysconfig.config-network
@@ -231,6 +231,29 @@ NM_ONLINE_TIMEOUT="0"
#
NETCONFIG_MODULES_ORDER="dns-resolver dns-bind dns-dnsmasq nis ntp-runtime"
+## Type: yesno
+## Default: no
+#
+# Enable netconfig verbose reporting.
+#
+NETCONFIG_VERBOSE="no"
+
+## Type: yesno
+## Default: no
+#
+# This variable enables netconfig to always force a replace of modified
+# files and automatically enables the -f | --force-replace parameter.
+#
+# The purpose is to use it as workaround, when some other tool trashes
+# the files, e.g. /etc/resolv.conf and you observe messages like this
+# in your logs on in "netconfig update" output:
+# ATTENTION: You have modified /etc/resolv.conf. Leaving it untouched.
+#
+# Please do not forget to also report a bug as we have a system policy
+# to use netconfig.
+#
+NETCONFIG_FORCE_REPLACE="no"
+
## Type: string
## Default: "auto"
#
diff --git a/scripts/functions.netconfig b/scripts/functions.netconfig
index 28f8b0f..a4045a1 100644
--- a/scripts/functions.netconfig
+++ b/scripts/functions.netconfig
@@ -29,36 +29,59 @@ test -z "$MD5DIR" && {
}
debug () {
+ test "$QUIET" = "yes" && return
test "$VERBOSE" = "yes" || return
echo -e "debug: $*" >&2
}
warn () {
test "$QUIET" = "yes" && return
- echo -e "$*" >&2
+ logger -s -p warn -t "$PROGNAME" "$*"
}
log () {
- logger -t "$PROGNAME" "$*"
- debug "$*"
- if [ "$ACTION" = "cleanup" -a "$QUIET" != "yes" ] ; then
- echo -e "$*" >&2
- fi
+ test "$QUIET" = "yes" && return
+ logger -s -t "$PROGNAME" "$*"
+}
+
+find_current_service()
+{
+ local name=$1
+ local pfx file link
+ for pfx in /etc/systemd /var/run/systemd /run/systemd ; do
+ file="$pfx/system/$name"
+ test -f "$file" || continue
+ link=`readlink -f "$file" 2>/dev/null`
+ test "X$link" = "X" -o "X$link" = "X$name" && continue
+ echo "${link##*/}"
+ return 0
+ done
+ echo "$name"
+ return 1
}
netconfig_policy()
{
local policy="$1"
+ local hint="${2:+$2-}"
local Id=`systemctl --no-pager -p Id show network.service 2>/dev/null`
+ local service=${Id#Id=}
+
+ service=${service%.service}
+ if test "X$service" = "X" ; then
+ debug "Systemd did not reported any enabled network service"
+ service=`find_current_service "network.service" 2>/dev/null`
+ service=${service%.service}
+ debug "Using '$service' as network service"
+ fi
- case ${Id#Id=} in
- NetworkManager.service)
+ case ${service} in
+ NetworkManager)
#
# Use NetworkManager policy merged data
#
test "x$policy" = "xauto" && \
policy='STATIC_FALLBACK NetworkManager'
- echo "$policy"
;;
network.service|*)
#
@@ -67,9 +90,11 @@ netconfig_policy()
#
test "x$policy" = "xauto" && \
policy='STATIC *'
- echo "$policy"
;;
esac
+ debug "Resolved ${hint}policy '$1' for service '${service}' to '$policy'"
+
+ echo "$policy"
}
function get_variable()
diff --git a/scripts/netconfig b/scripts/netconfig
index f2506fb..3d50ba0 100755
--- a/scripts/netconfig
+++ b/scripts/netconfig
@@ -52,7 +52,7 @@ function modify() {
fi
if test "x${LEASEFILE}" != x -a ! -r "${LEASEFILE}" ; then
- echo "Unable to read specified input file '${LEASEFILE}'" >&2
+ warn "Unable to read specified input file '${LEASEFILE}'"
exit 1
fi
@@ -77,7 +77,7 @@ function modify() {
(SERVICE|INTERFACE)
eval "_$key='$val'"
if test "x${!key}" != x -a "x${!key}" != "x$val" ; then
- echo "Input value $key conflicts with command line argument" >&1
+ warn "Input value $key conflicts with command line argument"
exit 1
fi
;;
@@ -89,11 +89,11 @@ function modify() {
VALS[${#VALS[@]}]=$val
done < <(netconfig_kv_filter ${LEASEFILE:+"$LEASEFILE"})
if test $err -ne 0 ; then
- echo "Invalid syntax in ${LEASEFILE:+${LEASEFILE}, }line $err" >&2
+ warn "Invalid syntax in ${LEASEFILE:+${LEASEFILE}, }line $err"
exit 1
fi
else
- echo "Unsupported lease file / input format '$INPUTFORMAT'" >&2
+ warn "Unsupported lease file / input format '$INPUTFORMAT'"
exit 1
fi
@@ -352,12 +352,17 @@ EOT
exit 1
}
-COMMANDLINE="$@"
+COMMANDLINE="$*"
ACTION=""
SERVICE=""
INTERFACE=""
VARIABLE=""
MODFILTER=""
+FORCE_REPLACE=false
+QUIET=no
+VERBOSE=no
+test "X$NETCONFIG_VERBOSE" = "Xyes" && VERBOSE="yes"
+test "X$NETCONFIG_FORCE_REPLACE" = "Xyes" && FORCE_REPLACE="true"
while true ; do
# Interface is checked against sysfs before the data is used;
# reject just the most the ugliest characters...
@@ -371,9 +376,10 @@ while true ; do
-l|--lease-file) VARIABLE=LEASEFILE;;
-I|--input-file) VARIABLE=LEASEFILE;;
-F|--input-format) VARIABLE=INPUTFORMAT;;
- -f|--force-replace) FORCE_REPLACE="true";;
- -v|--verbose) VERBOSE="yes";;
-m|--module-only) VARIABLE=MODFILTER;;
+ -f|--force-replace) FORCE_REPLACE="true";;
+ -v|--verbose) VERBOSE="yes"; QUIET="no";;
+ -q|--quiet) QUIET="yes"; VERBOSE="no";;
-h|--help) usage;;
"") break ;;
--)
@@ -409,21 +415,20 @@ done
test -z "$ACTION" && usage No action was given
-if [ "$VERBOSE" = "yes" ]; then
- export VERBOSE=$VERBOSE
-fi
+test "X$VERBOSE" = "Xyes" && log "Executing '$COMMANDLINE' for pid $PPID"
+export VERBOSE QUIET
#
# before we start, check for root
#
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ log "You must be root to start $0."
exit 1
fi
# Check if we can write in /tmp
if ! touch $r/tmp &>/dev/null; then
- echo "Filesystem read only: Cannot modify anything" >&2
+ log "Filesystem read only: Cannot modify anything"
exit 1
fi
@@ -432,7 +437,7 @@ umask 0022
# Create state directory
if ! mkdir -p "$STATEDIR" ; then
- echo "Unable to create netconfig state directory '$STATEDIR'" >&2
+ log "Unable to create netconfig state directory '$STATEDIR'"
exit 1
fi
diff --git a/scripts/netconfig.d/dns-bind b/scripts/netconfig.d/dns-bind
index 09e19d8..05ac697 100755
--- a/scripts/netconfig.d/dns-bind
+++ b/scripts/netconfig.d/dns-bind
@@ -23,7 +23,7 @@
unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ warn "You must be root to start $0."
exit 1
fi
@@ -174,7 +174,7 @@ case "$_NETCONFIG_DNS_RANKING" in
esac
# just for the case we need the original value...
-_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY"`
+_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY" dns`
if [ "x$_NETCONFIG_DNS_POLICY" = "x" ]; then
#
# empty policy means do not touch anything.
diff --git a/scripts/netconfig.d/dns-dnsmasq b/scripts/netconfig.d/dns-dnsmasq
index 8853df4..67e08b2 100755
--- a/scripts/netconfig.d/dns-dnsmasq
+++ b/scripts/netconfig.d/dns-dnsmasq
@@ -23,7 +23,7 @@
unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ warn "You must be root to start $0."
exit 1
fi
@@ -176,7 +176,7 @@ case "$_NETCONFIG_DNS_RANKING" in
esac
# just for the case we need the original value...
-_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY"`
+_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY" dns`
if [ "x$_NETCONFIG_DNS_POLICY" = "x" ]; then
#
# empty policy means do not touch anything.
diff --git a/scripts/netconfig.d/dns-resolver b/scripts/netconfig.d/dns-resolver
index 96a4f63..8d6172c 100755
--- a/scripts/netconfig.d/dns-resolver
+++ b/scripts/netconfig.d/dns-resolver
@@ -22,7 +22,7 @@
unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ warn "You must be root to start $0." >&2
exit 1
fi
@@ -226,7 +226,7 @@ case "$_NETCONFIG_DNS_RANKING" in
esac
# just for the case we need the original value...
-_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY"`
+_NETCONFIG_DNS_POLICY=`netconfig_policy "$NETCONFIG_DNS_POLICY" dns`
if [ "x$_NETCONFIG_DNS_POLICY" = "x" ]; then
#
# empty policy means do not touch anything.
diff --git a/scripts/netconfig.d/nis b/scripts/netconfig.d/nis
index 3ff4818..af5aff9 100755
--- a/scripts/netconfig.d/nis
+++ b/scripts/netconfig.d/nis
@@ -22,7 +22,7 @@
unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ warn "You must be root to start $0."
exit 1
fi
@@ -357,7 +357,7 @@ function manage_interfaceconfig()
# just for the case we need the original value...
-_NETCONFIG_NIS_POLICY=`netconfig_policy "$NETCONFIG_NIS_POLICY"`
+_NETCONFIG_NIS_POLICY=`netconfig_policy "$NETCONFIG_NIS_POLICY" nis`
if [ "x$_NETCONFIG_NIS_POLICY" = "x" ]; then
#
# empty policy means do not touch anything.
diff --git a/scripts/netconfig.d/ntp-runtime b/scripts/netconfig.d/ntp-runtime
index 2ce253a..3da49bf 100755
--- a/scripts/netconfig.d/ntp-runtime
+++ b/scripts/netconfig.d/ntp-runtime
@@ -22,7 +22,7 @@
unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features
if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
- echo "You must be root to start $0." >&2
+ warn "You must be root to start $0."
exit 1
fi
@@ -151,7 +151,7 @@ function manage_interfaceconfig()
# *********************
# just for the case we need the original value...
-_NETCONFIG_NTP_POLICY=`netconfig_policy "$NETCONFIG_NTP_POLICY"`
+_NETCONFIG_NTP_POLICY=`netconfig_policy "$NETCONFIG_NTP_POLICY" ntp`
if [ "x$_NETCONFIG_NTP_POLICY" = "x" ]; then
#
# empty policy means do not touch anything.
--
1.8.4.5