From: Marcin Siodelski Date: Fri, 18 Dec 2015 16:40:00 +0000 (+0100) Subject: [4249] Fixed race conditions when killing kea-lfc. X-Git-Tag: trac4263_base~8^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6540d59fc35316d67733de184fbad6453398b244;p=thirdparty%2Fkea.git [4249] Fixed race conditions when killing kea-lfc. --- diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index 641706f909..b9df2eb221 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -215,6 +215,28 @@ get_pid() { fi } +# Kills processes specified by name. +# +# This function kills all processes having a specified name. +# It uses 'pgrep' to obtain pids of those processes. +# This function should be used when identifying process by +# the value in its PID file is not relevant. +kill_processes() { + local proc_name=${1} # Process name + if [ -z ${proc_name} ]; then + test_lib_error "get_pids requires process name" + clean_exit 1 + fi + # Obtain PIDs of running processes. + local pids=$( pgrep ${proc_name} ) + # For each PID found, send kill signal. + for pid in ${pids} + do + printf "Shutting down Kea process ${proc_name} having pid %d.\n" ${pid} + kill -9 ${pid} + done +} + # Returns the number of occurrences of the Kea log message in the log file. # Return value: # _GET_LOG_MESSAGES: number of log message occurrences. @@ -274,6 +296,15 @@ cleanup() { fi done + # Kill any running LFC processes. Even though 'kea-lfc' creates PID + # file we rather want to use 'pgrep' to find the process PID, because + # kea-lfc execution is not controlled from the test and thus there + # is possibility that process is already/still running but the PID + # file doesn't exist for it. As a result, the process will not + # be killed. This is not a problem for other processes because + # tests control launching them and monitor when they are shut down. + kill_pids "kea-lfc" + # Remove temporary files. rm -rf ${LOG_FILE} # Use asterisk to remove all files starting with the given name,