enable bash loadable module for sleep when available; fixes #3754
Costa Tsaousis (ktsaou) committed
May 26, 2018 at 14:48 UTC
15a2734a19f1e47022bd8efda99deee1442a102e
1 file changed
+27
plugins.d/loopsleepms.sh.inc
+27
@@ -102,6 +102,33 @@ mysleep_read() {
102
fi
103
}
104
105
+# -----------------------------------------------------------------------------
106
+# use bash loadable module for sleep
107
+
108
+# BASH_LOADABLE_MODULES_DIR can be used in various netdata config files to
109
+# set the directory the loadable bash modules can be found.
110
+
111
+if [ "$((BASH_VERSINFO[0] +0))" -ge 3 ]
112
+ then
113
+ # enable modules only for bash version 3+
114
+
115
+ for bash_modules_path in "${BASH_LOADABLE_MODULES_DIR}" "/usr/lib/bash" "/lib/bash" "/lib64/bash" "/usr/local/lib/bash" "/usr/local/lib64/bash"
116
+ do
117
+ [ -z "${bash_modules_path}" -o ! -d "${bash_modules_path}" ] && continue
118
+
119
+ # check for sleep
120
+ if [ -f "${bash_modules_path}/sleep" ]
121
+ then
122
+ if enable -f "${bash_modules_path}/sleep" sleep 2>/dev/null
123
+ then
124
+ mysleep="sleep"
125
+ #echo >&2 "$0: Using bash loadable ${bash_modules_path}/sleep for sleep"
126
+ break
127
+ fi
128
+ fi
129
+ done
130
+fi
131
+
132
133
# -----------------------------------------------------------------------------
134
# this function is used to sleep a fraction of a second