From: Tomek Mrugalski Date: Sat, 2 Mar 2019 02:34:40 +0000 (+0100) Subject: [#480,!245] More fixes X-Git-Tag: 465-add-subnet4-update-and-subnet6-update-commands-to-subnet-cmds-hook_base2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdd3dc62817af92f785315c8f12eb4f3647fcba3;p=thirdparty%2Fkea.git [#480,!245] More fixes --- diff --git a/src/bin/keactrl/keactrl.in b/src/bin/keactrl/keactrl.in index afe0e0dc79..8c3684a9b1 100644 --- a/src/bin/keactrl/keactrl.in +++ b/src/bin/keactrl/keactrl.in @@ -37,8 +37,8 @@ log_info() { # is to determine whether the keactrl command belongs to the list of # supported commands. is_in_list() { - local member=${1} # Value to be checked - local list="${2}" # Comma separated list of items + member=${1} # Value to be checked + list="${2}" # Comma separated list of items _inlist=0 # Return value: 0 if not in list, 1 otherwise. if [ -z "${member}" ]; then log_error "missing ${member}" @@ -56,7 +56,7 @@ is_in_list() { # Prints keactrl usage. usage() { - printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" $( basename ${0} ) + printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" "$( basename ${0} )" printf "commands: start stop reload status version\n" } @@ -67,9 +67,9 @@ usage() { # be read the function exists with a error message. Note the PID file name # is always returned in $_pid_file. get_pid_from_file() { - local proc_name=${1} # Process name. + proc_name=${1} # Process name. - local kea_config_file= + kea_config_file= case ${proc_name} in kea-dhcp4) kea_config_file=${kea_dhcp4_config_file} @@ -89,13 +89,13 @@ get_pid_from_file() { esac # Extract the name portion of the config file - local conf_name=$(basename "${kea_config_file}" | cut -f1 -d'.') + conf_name=$(basename "${kea_config_file}" | cut -f1 -d'.') # Default the directory to --localstatedir - local pid_file_dir=@localstatedir@/@PACKAGE@ + pid_file_dir=@localstatedir@/@PACKAGE@ # Use directory override if set (primarily for testing only) - if [ ! -z $KEA_PIDFILE_DIR ]; then + if [ ! -z "$KEA_PIDFILE_DIR" ]; then pid_file_dir=${KEA_PIDFILE_DIR} fi @@ -103,8 +103,8 @@ get_pid_from_file() { _pid_file="${pid_file_dir}/${conf_name}.${proc_name}.pid" # Grab the PID if the file exists - if [ -e ${_pid_file} ]; then - _pid=`cat ${_pid_file}` + if [ -e "${_pid_file}" ]; then + _pid=$(cat ${_pid_file}) if [ $? -ne 0 ]; then log_error "Error reading PID file: ${_pid_file}" fi @@ -119,7 +119,7 @@ get_pid_from_file() { # PID file and checking the PID it contains. If the file does # not exist, the process is assumed to not be running. check_running() { - local proc_name=${1} # Process name. + proc_name=${1} # Process name. # Initially mark the process as not running. _running=0 @@ -137,15 +137,15 @@ check_running() { # Sends a signal to a process based on its PID file send_signal() { - local sig=${1} # Signal number - local proc_name=${2} # Process name. + sig=${1} # Signal number + proc_name=${2} # Process name. get_pid_from_file ${proc_name} if [ ${_pid} -eq 0 ]; then log_info "Skip sending signal ${sig} to process ${proc_name}: \ process is not running\n" else - kill -${sig} ${_pid} + kill "-${sig}" "${_pid}" if [ $? -ne 0 ]; then log_error "Failed to send signal ${sig} to process ${proc_name}, PID {$_pid}.\n" fi @@ -158,9 +158,9 @@ start_server() { binary_path=${1} # Full path to the binary. full_command=$@ # Binary and arguments. # Extract the name of the binary from the path. - local binary_name=$(basename ${binary_path}) + binary_name=$(basename "${binary_path}") # Use the binary name to check if the process is already running. - check_running ${binary_name} + check_running "${binary_name}" # If process is running, don't start another one. Just log a message. if [ ${_running} -ne 0 ]; then log_info "${binary_name} appears to be running, see: \ @@ -175,12 +175,12 @@ PID ${_pid}, PID file: ${_pid_file}." # Instruct Kea process to shutdown by sending it signal 15 stop_server() { binary_path=${1} # Full path to the binary. - local sig=15 + sig=15 # Extract the name of the binary from the path. - local binary_name=$(basename ${binary_path}) + binary_name=$(basename "${binary_path}") # Use the binary name to check if the process is already running. - check_running ${binary_name} + check_running "${binary_name}" # If process isn't running, don't start another one. Just log a message. if [ ${_running} -eq 0 ]; then log_info "${binary_name} isn't running." @@ -197,9 +197,9 @@ to process ${proc_name}, PID ${_pid}.\n" # Instruct Kea process to reload config by sending it signal 1 reload_server() { binary_path=${1} # Full path to the binary. - local sig=1 + sig=1 # Extract the name of the binary from the path. - local binary_name=$(basename ${binary_path}) + binary_name=$(basename "${binary_path}") # Use the binary name to check if the process is already running. check_running ${binary_name} @@ -221,8 +221,8 @@ print_version() { name=${1} binary_path=${2} - if [ -e ${binary_path} ]; then - ver=`${binary_path} -v` + if [ -e "${binary_path}" ]; then + ver=$(${binary_path} -v) if [ $? -ne 0 ]; then log_error "Error checking version of binary file: ${binary_path}" fi @@ -240,10 +240,10 @@ print_version() { # keactrl configuration file. If not, it is a warning or a fatal error. check_kea_conf() { local conf_file=${1} # Kea config file name. - if [ -z ${conf_file} ]; then + if [ -z "${conf_file}" ]; then log_error "Configuration file for Kea not specified." exit 1 - elif [ ! -f ${conf_file} ]; then + elif [ ! -f "${conf_file}" ]; then log_error "Configuration file for Kea does not exist: ${conf_file}." exit 1 fi @@ -258,16 +258,16 @@ check_kea_conf() { # and be set to yes, e.g. ${dhcp4} should be equal to yes if server name # is dhcp4 run_conditional() { - local server=${1} # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf - local commands="${2}" # Commands to execute - local check_file_cfg=${3} # Check if server enabled in the configuration file - local is_all=0 # is all servers or a specific one + server=${1} # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf + commands="${2}" # Commands to execute + check_file_cfg=${3} # Check if server enabled in the configuration file + is_all=0 # is all servers or a specific one # If keyword "all" is not on the list of servers we will have to check # if our specific server is on the list. If, not return. is_in_list "all" "${servers}" if [ ${_inlist} -eq 0 ]; then - is_in_list ${server} "${servers}" + is_in_list "${server}" "${servers}" if [ ${_inlist} -eq 0 ]; then return fi @@ -275,8 +275,8 @@ run_conditional() { is_all=1 fi # Return for for netconf when not available. - if [ ${server} = "netconf" ]; then - if [ ${have_netconf} -eq 0 ]; then + if [ "${server}" = "netconf" ]; then + if [ "${have_netconf}" -eq 0 ]; then return fi # reload is not supported for netconf. @@ -292,13 +292,13 @@ run_conditional() { # Get the configuration value of the keactrl which indicates whether # the server should be enabled or not. Variables that hold these values # are: ${dhcp4}, ${dhcp6}, ${dhcp_ddns}. - local file_config=$( eval printf "%s" \${$server} ) + file_config=$( eval printf "%s" "\${$server}" ) # Get the location of the current Kea configuration file. This will be used # to check that the file exists before it is used. - local kea_config_location=$( eval printf "%s" "\$kea_${server}_config_file" ) + kea_config_location=$( eval printf "%s" "\$kea_${server}_config_file" ) # Run the commands if we ignore the configuration setting or if the # setting is "yes". - if [ ${check_file_cfg} -eq 0 ] || [ "${file_config}" = "yes" ]; then + if [ "${check_file_cfg}" -eq 0 ] || [ "${file_config}" = "yes" ]; then ${commands} fi } @@ -311,13 +311,13 @@ run_conditional() { # Note that when the configuration is applied this location may be # altered and only the handful of initial messages will be logged # to the default file. -if [ -z ${KEA_LOGGER_DESTINATION} ]; then +if [ -z "${KEA_LOGGER_DESTINATION}" ]; then prefix=@prefix@ export KEA_LOGGER_DESTINATION=@localstatedir@/@PACKAGE@/kea.log fi command=${1} -if [ -z ${command} ]; then +if [ -z "${command}" ]; then log_error "missing command" usage exit 1 @@ -350,7 +350,7 @@ do -c|--ctrl-config) shift keactrl_conf=${1} - if [ -z ${keactrl_conf} ]; then + if [ -z "${keactrl_conf}" ]; then log_error "keactrl-config-file not specified" usage exit 1