dhclient-script: run also scripts in dhclient-[enter/exit]-hooks.d dir

Debian does it similar way.
Not yet documented in dhclient-script man page.

Initial patch by Neal Gompa.
This commit is contained in:
Jiri Popelka 2015-05-26 18:02:29 +02:00
parent 4cd2995553
commit 278a2ea405
2 changed files with 44 additions and 18 deletions

View File

@ -182,14 +182,44 @@ make_resolv_conf() {
fi
}
exit_with_hooks() {
exit_status="${1}"
# run given script
run_hook() {
local script
local exit_status
script="${1}"
if [ -x ${ETCDIR}/dhclient-exit-hooks ]; then
. ${ETCDIR}/dhclient-exit-hooks
if [ -f ${script} ]; then
. ${script}
fi
exit "${exit_status}"
if [ -n "${exit_status}" ] && [ "${exit_status}" -ne 0 ]; then
logmessage "${script} returned non-zero exit status ${exit_status}"
fi
return ${exit_status}
}
# run scripts in given directory
run_hookdir() {
local dir
dir="${1}"
if [ -d "${dir}" ]; then
for script in $(run-parts --list $dir); do
run_hook ${script} || return $?
done
fi
return 0
}
exit_with_hooks() {
# Source the documented exit-hook script, if it exists
run_hook "${ETCDIR}/dhclient-exit-hooks" || exit $?
# Now run scripts in the hooks directory.
run_hookdir "${ETCDIR}/dhclient-exit-hooks.d" || exit $?
exit ${1}
}
quad2num() {
@ -629,16 +659,9 @@ dh6config() {
# ### MAIN
#
if [ -x ${ETCDIR}/dhclient-enter-hooks ]; then
exit_status=0
# dhclient-enter-hooks can abort dhclient-script by setting
# the exit_status variable to a non-zero value
. ${ETCDIR}/dhclient-enter-hooks
if [ ${exit_status} -ne 0 ]; then
exit ${exit_status}
fi
fi
# Invoke the local dhcp client enter hooks, if they exist.
run_hook "${ETCDIR}/dhclient-enter-hooks" || exit $?
run_hookdir "${ETCDIR}/dhclient-enter-hooks.d" || exit $?
if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then
echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2

View File

@ -18,7 +18,7 @@
Summary: Dynamic host configuration protocol software
Name: dhcp
Version: 4.3.2
Release: 5%{?dist}
Release: 6%{?dist}
# NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to
# dcantrell maintaining the package) made incorrect use of the epoch and
# that's why it is at 12 now. It should have never been used, but it was.
@ -675,6 +675,9 @@ done
%doc doc/html/
%changelog
* Tue May 26 2015 Jiri Popelka <jpopelka@redhat.com> - 12:4.3.2-6
- dhclient-script: run also scripts in dhclient-[enter/exit]-hooks.d dir
* Tue Apr 21 2015 Jiri Popelka <jpopelka@redhat.com> - 12:4.3.2-5
- dhclient-script: add a minute to address lifetimes (#1188423)