diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-02-13 17:32:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 17:32:18 +0100 |
commit | 13bc01034d287ffdf1249138ddfbdbb1866b5a93 (patch) | |
tree | 755a97aa42b8e98699927543ffe7766f5b847a0f /src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient | |
parent | 233c463b4cf6f8ca4d3e2a1a3a30e5c62ce42061 (diff) | |
parent | e39f2ead18c17fa4a8fdfe35437202fb202e983a (diff) | |
download | vyos-1x-13bc01034d287ffdf1249138ddfbdbb1866b5a93.tar.gz vyos-1x-13bc01034d287ffdf1249138ddfbdbb1866b5a93.zip |
Merge pull request #218 from zdc/T1987
dhclient-script: T1987: Multiple fixes in dhclient-script
Diffstat (limited to 'src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient')
-rw-r--r-- | src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient b/src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient new file mode 100644 index 000000000..d5d90632c --- /dev/null +++ b/src/etc/dhcp/dhclient-enter-hooks.d/02-vyos-stopdhclient @@ -0,0 +1,27 @@ +# skip all of this if dhclient-script running by stop command defined below +if [ -z ${CONTROLLED_STOP} ] ; then + # stop dhclient for this interface, if it is not current one + # get PID for current dhclient + current_dhclient=`ps --no-headers --format ppid --pid $$ | awk '{ print $1 }'` + + # get PID for master process (current can be a fork) + master_dhclient=`ps --no-headers --format ppid --pid $current_dhclient | awk '{ print $1 }'` + + # get IP version for current dhclient + ipversion_arg=`ps --no-headers --format args --pid $current_dhclient | awk '{ print $2 }'` + + # get list of all dhclient running for current interface + dhclients_pids=(`ps --no-headers --format pid,args -C dhclient | awk -v IFACE="/sbin/dhclient $ipversion_arg .*$interface$" '$0 ~ IFACE { print $1 }'`) + + logmsg info "Current dhclient PID: $current_dhclient, Parent PID: $master_dhclient, IP version: $ipversion_arg, All dhclients for interface $interface: ${dhclients_pids[@]}" + # stop all dhclients for current interface, except current one + for dhclient in ${dhclients_pids[@]}; do + if ([ $dhclient -ne $current_dhclient ] && [ $dhclient -ne $master_dhclient ]); then + logmsg info "Stopping dhclient with PID: ${dhclient}" + # get path to PID-file of dhclient process + local dhclient_pidfile=`ps --no-headers --format args --pid $dhclient | awk 'match($0, ".*-pf (/.*pid) .*", PF) { print PF[1] }'` + # stop dhclient with native command - this will run dhclient-script with correct reason unlike simple kill + dhclient -e CONTROLLED_STOP=yes -x -pf $dhclient_pidfile + fi + done +fi |