diff options
author | Jim Pryor <profjim@jimpryor.net> | 2009-08-11 14:04:50 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-08-15 04:28:25 +0200 |
commit | 4ede76fb6a5ba81b92b0e3452e954d9eea431a74 (patch) | |
tree | 35a778707c544d6604a01aca3027df4924408f8a /contrib | |
parent | 4ebad5f88abda1b0788ef7ad3cd46d8cd8cfa6d7 (diff) | |
download | netctl-4ede76fb6a5ba81b92b0e3452e954d9eea431a74.tar.gz netctl-4ede76fb6a5ba81b92b0e3452e954d9eea431a74.tar.xz |
Add contrib dir and logging hooks
* Add contrib/logging.hook
* Update Makefile and manpage
* Propose that hooks go into /etc, not /usr---latter
should be shareable and possibly read-only, not
good spot for user-configurable files like these.
* Since we have hooks/arch as part of the package,
this commit attempts to load hooks from both
/usr/lib/network/hooks and /etc/network.d/hooks.
(Executable hooks in /etc take precedence over
hooks with same name from /usr.)
* Need to load /etc/rc.conf before /etc/rc.d/functions
(e.g. for USECOLORS)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/logging.hook | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/contrib/logging.hook b/contrib/logging.hook new file mode 100755 index 0000000..b314dd1 --- /dev/null +++ b/contrib/logging.hook @@ -0,0 +1,89 @@ +### Sample netcfg hook script for logging/debugging connections +### To install, make this executable and put it in /etc/network.d/hooks + + +. /etc/rc.conf +. /etc/rc.d/functions + + +# if NETCFG_DEBUG is set, debugging messages go to stderr instead of syslog + +# What facility to send log messages to? if set to "", nothing will be sent to syslog +NETCFG_LOG="${NETCFG_LOG-local0}" + + + +function report_log { + if [[ -n "$NETCFG_LOG" ]]; then + local caller level="$1" + shift + case "$0" in + net-auto|netcfg-auto-*) caller=net-auto;; + net-profiles) caller=net-profiles;; + net-rename) caller=net-rename;; + *) caller=netcfg;; + esac + logger -p "${NETCFG_LOG}.$level" -t "$caller" -- "$*" + fi +} + + +function report_err { + report_log err "$*" + printhl "$*" +} + +function report_warn { + report_log warning "$*" + # printhl "$*" + [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2 +} + + + +function report_notify { + report_log notice "$*" + # print "$*" >&2 + [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2 +} + +function report_debug { + if [[ -n "$NETCFG_DEBUG" ]]; then + echo "DEBUG: $*" >&2 + else + report_log debug "$*" + fi +} + + + +function report_try { + report_log notice "trying $*..." + stat_busy "$*" + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + report_log err "$*" + if [[ -n "$REPORT_TRYING" ]]; then + stat_append "- $*" + REPORT_TRYING= + stat_fail + else + printhl "$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + REPORT_TRYING= + stat_fail + fi +} + +function report_success { + if [[ -n "$*" ]]; then + stat_append "- $*" + fi + report_log notice "${*:-succeeded}" + stat_done +} + |