aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Kaspar [Dee'Kej] <dkaspar@redhat.com>2017-07-21 11:25:28 +0200
committerDee'Kej <deekej@linuxmail.org>2017-08-07 13:23:56 +0200
commit3bd816fb3a30e085cfac69d14f61243920472f65 (patch)
tree83e4439be1d31ee9576c300d5b3545561a51e1e5
parent19ebbffd7d90e8d8d018581b05e22619b7f3a65e (diff)
downloadinitscripts-3bd816fb3a30e085cfac69d14f61243920472f65.tar
initscripts-3bd816fb3a30e085cfac69d14f61243920472f65.tar.gz
initscripts-3bd816fb3a30e085cfac69d14f61243920472f65.tar.bz2
initscripts-3bd816fb3a30e085cfac69d14f61243920472f65.tar.xz
initscripts-3bd816fb3a30e085cfac69d14f61243920472f65.zip
init.d/functions: convert2sec() function added
And network-scripts/network-functions was patched to use convert2sec(). This function can be used to convert the value of its first parameter to a number of seconds - based on the time unit (specified as the second parameter). This is mostly useful for converting values for use with the sleep(1).
-rw-r--r--rc.d/init.d/functions16
-rw-r--r--sysconfig/network-scripts/network-functions2
2 files changed, 17 insertions, 1 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index 3acd1707..d54361c3 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -625,6 +625,22 @@ is_ignored_file() {
return 1
}
+# Convert the value ${1} of time unit ${2}-seconds into seconds:
+convert2sec() {
+ local retval=""
+
+ case "${2}" in
+ deci) retval=$(awk "BEGIN {printf \"%.1f\", ${1} / 10}") ;;
+ centi) retval=$(awk "BEGIN {printf \"%.2f\", ${1} / 100}") ;;
+ mili) retval=$(awk "BEGIN {printf \"%.3f\", ${1} / 1000}") ;;
+ micro) retval=$(awk "BEGIN {printf \"%.6f\", ${1} / 1000000}") ;;
+ nano) retval=$(awk "BEGIN {printf \"%.9f\", ${1} / 1000000000}") ;;
+ piko) retval=$(awk "BEGIN {printf \"%.12f\", ${1} / 1000000000000}") ;;
+ esac
+
+ echo "${retval}"
+}
+
# Evaluate shvar-style booleans
is_true() {
case "$1" in
diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions
index 70896ff1..d7915e31 100644
--- a/sysconfig/network-scripts/network-functions
+++ b/sysconfig/network-scripts/network-functions
@@ -198,7 +198,7 @@ ethtool_set()
IFS=';';
if [ -n "${ETHTOOL_DELAY}" ]; then
# Convert microseconds to seconds:
- local ETHTOOL_DELAY_SEC=$(awk "BEGIN {printf \"%f\", ${ETHTOOL_DELAY} / 1000000}")
+ local ETHTOOL_DELAY_SEC=$(convert2sec ${ETHTOOL_DELAY} micro)
sleep ${ETHTOOL_DELAY_SEC}
fi
for opts in $ETHTOOL_OPTS ; do