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 fi
} }
exit_with_hooks() { # run given script
exit_status="${1}" run_hook() {
local script
local exit_status
script="${1}"
if [ -x ${ETCDIR}/dhclient-exit-hooks ]; then if [ -f ${script} ]; then
. ${ETCDIR}/dhclient-exit-hooks . ${script}
fi 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() { quad2num() {
@ -488,7 +518,7 @@ dhconfig() {
ip -4 addr replace "${alias_ip_address}/${alias_prefix}" broadcast "${alias_broadcast_address}" dev "${interface}" label "${interface}:0" ip -4 addr replace "${alias_ip_address}/${alias_prefix}" broadcast "${alias_broadcast_address}" dev "${interface}" label "${interface}:0"
ip -4 route replace "${alias_ip_address}/32" dev "${interface}" ip -4 route replace "${alias_ip_address}/32" dev "${interface}"
fi fi
# After dhclient brings an interface UP with a new IP address, subnet mask, # After dhclient brings an interface UP with a new IP address, subnet mask,
# and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks". # and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks".
if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] || if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
@ -498,7 +528,7 @@ dhconfig() {
[ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] || [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
[ ! "${old_routers}" = "${new_routers}" ] || [ ! "${old_routers}" = "${new_routers}" ] ||
[ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
if [ -x "${ETCDIR}/dhclient-${interface}-up-hooks" ]; then if [ -x "${ETCDIR}/dhclient-${interface}-up-hooks" ]; then
. "${ETCDIR}/dhclient-${interface}-up-hooks" . "${ETCDIR}/dhclient-${interface}-up-hooks"
elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then
@ -629,16 +659,9 @@ dh6config() {
# ### MAIN # ### MAIN
# #
if [ -x ${ETCDIR}/dhclient-enter-hooks ]; then # Invoke the local dhcp client enter hooks, if they exist.
exit_status=0 run_hook "${ETCDIR}/dhclient-enter-hooks" || exit $?
run_hookdir "${ETCDIR}/dhclient-enter-hooks.d" || exit $?
# 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
if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then
echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2 echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2

View File

@ -18,7 +18,7 @@
Summary: Dynamic host configuration protocol software Summary: Dynamic host configuration protocol software
Name: dhcp Name: dhcp
Version: 4.3.2 Version: 4.3.2
Release: 5%{?dist} Release: 6%{?dist}
# NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to # NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to
# dcantrell maintaining the package) made incorrect use of the epoch and # 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. # 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/ %doc doc/html/
%changelog %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 * Tue Apr 21 2015 Jiri Popelka <jpopelka@redhat.com> - 12:4.3.2-5
- dhclient-script: add a minute to address lifetimes (#1188423) - dhclient-script: add a minute to address lifetimes (#1188423)