]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1961] quote "local a=${b}" expressions for dash
authorAndrei Pavel <andrei@isc.org>
Mon, 5 Jul 2021 17:46:52 +0000 (20:46 +0300)
committerAndrei Pavel <andrei@isc.org>
Mon, 5 Jul 2021 17:46:52 +0000 (20:46 +0300)
In dash if ${b} contains spaces, a is assigned the first word instead of
the whole expression in the "local a=${b}" expression format. Empirically,
there seem to be several solutions:
* local a="${b}"
* local a
  a=${b}
* a=${b} - losing the non-posix "local"

This commit adds the quotes like in the first solution above to all
expressions that match the format above.

src/bin/admin/kea-admin.in
src/bin/admin/tests/memfile_tests.sh.in
src/bin/d2/tests/d2_process_tests.sh.in
src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
src/bin/keactrl/keactrl.in
src/lib/testutils/dhcp_test_lib.sh.in
src/lib/testutils/xml_reporting_test_lib.sh.in
tools/print-generated-files.sh

index 78c98a02d258c0d5d662e21f6c674ee89ed7a5d9..b05c9e61ec431a7224ba5963fb734246de50a097 100644 (file)
@@ -445,7 +445,7 @@ cql_upgrade() {
 # if so notifies the user and provides them the opportunity
 # to abort the current command.
 check_file_overwrite () {
-    local file=$1
+    local file="${1}"
     if [ -e "${file}" ]
     then
         echo "Output file, $file, exists and will be overwritten."
@@ -465,7 +465,7 @@ check_file_overwrite () {
 # SQL text needed to dump the lease data for the current backend
 # and protocol
 get_dump_query() {
-    local version=$1
+    local version="${1}"
 
     case ${backend} in
     mysql)
index 0fc3e6542f46d9e19ea7274c0039de21cb5670d3..09ff9650f810d06bee607385d840a8bdd8245014 100644 (file)
@@ -33,13 +33,13 @@ clean_up() {
 
 # Print location of CSV file. Accepts 4 or 6 as parameter.
 csv_file() {
-    local v=${1}
+    local v="${1}"
     printf '%s' "@abs_top_builddir@/src/bin/admin/tests/kea-dhcp${v}.csv"
 }
 
 # Print location of kea-dhcp[46] binaries. Accepts 4 or 6 as parameter.
 kea_dhcp() {
-    local v=${1}
+    local v="${1}"
     printf '%s' "@abs_top_builddir@/src/bin/dhcp${v}/kea-dhcp${v}"
 }
 
@@ -81,7 +81,7 @@ server_id_v6() {
 # Starts Kea and sets PID. It logs to stdout and stderr if DEBUG is enabled.
 # Accepts 4 or 6 as parameter.
 start_kea_dhcp() {
-    local v=${1}
+    local v="${1}"
     if test -n "${DEBUG+x}"; then
         "$(kea_dhcp "${v}")" -c "${config_file}" &
     else
index 99e6baf6063cb7849cd2afdd105137d7e42f3a72..895b9a2d921bdbd5f3211fc5842519d635162c3f 100644 (file)
@@ -266,8 +266,8 @@ dynamic_reconfiguration_test() {
 # This test verifies that DHCPv4 server is shut down gracefully when it
 # receives a SIGINT or SIGTERM signal.
 shutdown_test() {
-    local test_name=${1}    # Test name
-    local signum=${2}       # Signal number
+    local test_name="${1}"  # Test name
+    local signum="${2}"     # Signal number
     # Log the start of the test and print test name.
     test_start "${test_name}"
     # Create new configuration file.
index 1b134ed0c987b08079196b444c14f8543217cec8..0265ec62a886e66665a81b7ecd9bd4f3178e089a 100644 (file)
@@ -312,8 +312,8 @@ returned %d."
 # This test verifies that DHCPv6 server is shut down gracefully when it
 # receives a SIGINT or SIGTERM signal.
 shutdown_test() {
-    local test_name=${1}    # Test name
-    local signum=${2}       # Signal number
+    local test_name="${1}"  # Test name
+    local signum="${2}"     # Signal number
 
     # Log the start of the test and print test name.
     test_start "${test_name}"
index eb4901b7cacca88180451a11abc320f15b7b5524..ae5bd8ee8672cfb13f3eee75f690d0954872691b 100644 (file)
@@ -93,7 +93,7 @@ usage() {
 #
 # shellcheck disable=SC2154
 get_pid_from_file() {
-    local proc_name=${1} # Process name.
+    local proc_name="${1}"  # Process name.
 
     local kea_config_file=
     case ${proc_name} in
@@ -144,7 +144,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.
+    local proc_name="${1}"  # Process name.
     # Initially mark the process as not running.
     _running=0
 
@@ -161,8 +161,8 @@ 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.
+    local sig="${1}"        # Signal number
+    local proc_name="${2}"  # Process name.
 
     get_pid_from_file "${proc_name}"
     if [ "${_pid}" -eq 0 ]; then
@@ -261,7 +261,7 @@ print_version() {
 # Check if the Kea configuration file location has been specified in the
 # keactrl configuration file. If not, it is a warning or a fatal error.
 check_kea_conf() {
-    local conf_file=${1-} # Kea config file name.
+    local conf_file="${1-}"     # Kea config file name.
     if [ -z "${conf_file}" ]; then
         log_error "Configuration file for Kea not specified."
         exit 1
@@ -280,10 +280,10 @@ 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
+    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
 
     # 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.
index 4003fea4c43f6a6ab2bc24aae92f3bd0bc7a782e..d2c7ae81f36ae660428c8172f6c6a2242c4ca10d 100644 (file)
@@ -57,9 +57,9 @@ fi
 
 # Prints error message.
 test_lib_error() {
-    local s=${1-}            # Error message.
-    local no_new_line=${2-}  # If specified, the message not terminated with
-                             # new line.
+    local s="${1-}"             # Error message.
+    local no_new_line="${2-}"   # If specified, the message is not terminated
+                                # with new line.
     printf "ERROR/test_lib: %s" "${s}"
     if [ -z "${no_new_line}" ]; then
         printf '\n'
@@ -68,9 +68,9 @@ test_lib_error() {
 
 # Prints info message.
 test_lib_info() {
-    local s=${1-}            # Info message.
-    local no_new_line=${2-}  # If specified, the message is not terminated with
-                             # new line.
+    local s="${1-}"             # Info message.
+    local no_new_line="${2-}"   # If specified, the message is not terminated
+                                # with new line.
     printf "INFO/test_lib: %s" "${s}"
     if [ -z "${no_new_line}" ]; then
         printf '\n'
@@ -254,7 +254,7 @@ test_start() {
 # Prints test result an cleans up after the test.
 test_finish() {
     # Exit code to be returned by the exit function
-    local exit_code=${1}
+    local exit_code="${1}"
 
     # Stop timer and set duration.
     FINISH_TIME=$(get_current_time)
@@ -443,8 +443,8 @@ set_logger() {
 #   _GET_PID: holds a PID if process is running
 #   _GET_PIDS_NUM: holds 1 if process is running, 0 otherwise
 get_pid() {
-    local proc_name=${1-}       # Process name
-    local cfg_file_name=${2-}   # Configuration file name without extension.
+    local proc_name="${1-}"         # Process name
+    local cfg_file_name="${2-}"     # Configuration file name without extension.
 
     # Reset PID results.
     _GET_PID=0
@@ -487,7 +487,7 @@ get_pid() {
 
 # Get the name of the process identified by PID.
 get_process_name() {
-    local pid=${1-}
+    local pid="${1-}"
     if test -z "${pid}"; then
         test_lib_error 'expected PID parameter in get_process_name'
         clean_exit 1
@@ -498,14 +498,14 @@ get_process_name() {
 
 # Wait for file to be created.
 wait_for_file() {
-    local file=${1-}
+    local file="${1-}"
     if test -z "${file}"; then
         test_lib_error 'expected file parameter in wait_for_file'
         clean_exit 1
     fi
 
     local timeout='4' # seconds
-    local deadline=$(($(date +%s) + timeout))
+    local deadline="$(($(date +%s) + timeout))"
     while ! test -f "${file}"; do
         if test "${deadline}" -lt "$(date +%s)"; then
             # Time is up.
@@ -519,14 +519,14 @@ wait_for_file() {
 
 # Wait for process identified by PID to die.
 wait_for_process_to_stop() {
-    local pid=${1-}
+    local pid="${1-}"
     if test -z "${pid}"; then
         test_lib_error 'expected PID parameter in wait_for_process_to_stop'
         clean_exit 1
     fi
 
     local timeout='4' # seconds
-    local deadline=$(($(date +%s) + timeout))
+    local deadline="$(($(date +%s) + timeout))"
     while ps "${pid}" >/dev/null; do
         if test "${deadline}" -lt "$(date +%s)"; then
             # Time is up.
@@ -550,7 +550,7 @@ wait_for_process_to_stop() {
 # names, add this before pgrep:
 # proc_name=$(printf '%s' "${proc_name}" | cut -c1-15)
 kill_processes_by_name() {
-    local proc_name=${1-}  # Process name
+    local proc_name="${1-}"     # Process name
     if [ -z "${proc_name}" ]; then
         test_lib_error "kill_processes_by_name requires process name"
         clean_exit 1
@@ -692,7 +692,7 @@ clean_exit() {
 # Starts Kea process in background using a configuration file specified
 # in the global variable ${CFG_FILE}.
 start_kea() {
-    local bin=${1-}
+    local bin="${1-}"
     if [ -z "${bin}" ]; then
         test_lib_error "binary name must be specified for start_kea"
         clean_exit 1
@@ -712,7 +712,7 @@ start_kea() {
 # Return value:
 #    _WAIT_FOR_KEA: 0 if Kea hasn't started, 1 otherwise
 wait_for_kea() {
-    local timeout=${1-} # Desired timeout in seconds.
+    local timeout="${1-}"   # Desired timeout in seconds.
     if test -z "${timeout}"; then
         test_lib_error 'expected timeout parameter in wait_for_kea'
         clean_exit 1
@@ -831,8 +831,8 @@ wait_for_server_down() {
 
 # Sends specified signal to the Kea process.
 send_signal() {
-    local sig=${1-}       # Signal number.
-    local proc_name=${2-} # Process name
+    local sig="${1-}"           # Signal number.
+    local proc_name="${2-}"     # Process name
 
     # Validate signal
     case ${sig} in
index 03fa1cefcef41bcd068ea35267a27636023df6e0..0d9b235bfab92347fd2ec447fcbe6454249c8ed1 100644 (file)
@@ -24,9 +24,9 @@ report_test_result_in_xml() {
     fi
 
     # Declarations
-    local test_name=${1}; shift
-    local exit_code=${1}; shift
-    local duration=${1}; shift # milliseconds
+    local test_name="${1}"; shift
+    local exit_code="${1}"; shift
+    local duration="${1}"; shift # milliseconds
     local now
     local test_case
     local test_suite
@@ -72,9 +72,9 @@ report_test_result_in_xml() {
 
 # Add ${string} after ${reference} in ${file}.
 _add_after() {
-    local string=${1}; shift
-    local reference=${1}; shift
-    local file=${1}; shift
+    local string="${1}"; shift
+    local reference="${1}"; shift
+    local file="${1}"; shift
 
     # Escape all slashes.
     string=$(printf '%s' "${string}" | sed 's#\/#\\\/#g')
@@ -98,9 +98,9 @@ ${string}
 
 # Add ${string} before ${reference} in ${file}.
 _add_before() {
-    local string=${1}; shift
-    local reference=${1}; shift
-    local file=${1}; shift
+    local string="${1}"; shift
+    local reference="${1}"; shift
+    local file="${1}"; shift
 
     # Get the line number of the reference line.
     local line_number
@@ -127,8 +127,8 @@ ${string}
 }
 
 _add_failure_tag() {
-    local test_case_tag=${1}; shift
-    local xml=${1}; shift
+    local test_case_tag="${1}"; shift
+    local xml="${1}"; shift
 
     local closing_tag='    </testcase>'
     local failure_tag
@@ -151,12 +151,12 @@ _add_failure_tag() {
 
 # Add test result if not in file.
 _add_test_case() {
-    local test_suite=${1}; shift
-    local test_case=${1}; shift
-    local result=${1}; shift
-    local duration=${1}; shift
-    local xml=${1}; shift
-    local now=${1}; shift
+    local test_suite="${1}"; shift
+    local test_case="${1}"; shift
+    local result="${1}"; shift
+    local duration="${1}"; shift
+    local xml="${1}"; shift
+    local now="${1}"; shift
 
     # Determine the test case tag.
     local closing_backslash
@@ -219,9 +219,9 @@ _add_test_case() {
 
 # Add a set of test suite tags if not already present in the XML.
 _add_test_suite() {
-    local test_suite=${1}; shift
-    local xml=${1}; shift
-    local now=${1}; shift
+    local test_suite="${1}"; shift
+    local xml="${1}"; shift
+    local now="${1}"; shift
     local test_suite_line
     local all_test_suites
 
@@ -267,8 +267,8 @@ _create_xml() {
         return;
     fi
 
-    local xml=${1}; shift
-    local now=${1}; shift
+    local xml="${1}"; shift
+    local now="${1}"; shift
 
     mkdir -p "$(dirname "${xml}")"
     printf \
@@ -297,9 +297,9 @@ _create_xml() {
 # Print the lines between two matching regex patterns from a file. Excludes the
 # lines that contain the patterns themselves. Matches only the first occurrence.
 _print_lines_between_matching_patterns() {
-    local start_pattern=${1}; shift
-    local end_pattern=${1}; shift
-    local file=${1}; shift
+    local start_pattern="${1}"; shift
+    local end_pattern="${1}"; shift
+    local file="${1}"; shift
 
     # Escape all slashes.
     start_pattern=$(printf '%s' "${start_pattern}" | sed 's#\/#\\\/#g')
@@ -313,10 +313,10 @@ _print_lines_between_matching_patterns() {
 # Update the test suite XML attributes with metrics collected from the child
 # test cases.
 _update_test_suite_metrics() {
-    local test_suite=${1}; shift
-    local all_test_cases=${1}; shift
-    local xml=${1}; shift
-    local now=${1}; shift
+    local test_suite="${1}"; shift
+    local all_test_cases="${1}"; shift
+    local xml="${1}"; shift
+    local now="${1}"; shift
 
     # Get the metrics on the parent test suite.
     local duration
index ce219c302953afb2cf9006aaadedbf0ce446dda4..e752bdf1c94d7bdeb6de76cb9450b3cb03a45b08 100755 (executable)
@@ -95,9 +95,9 @@ mandatory_commands() {
 print_lines_between_matching_patterns() {
   mandatory_commands sed
 
-  local start_pattern=${1}; shift
-  local end_pattern=${1}; shift
-  local file=${1}; shift
+  local start_pattern="${1}"; shift
+  local end_pattern="${1}"; shift
+  local file="${1}"; shift
 
   # Escape all slashes.
   start_pattern=$(printf '%s' "${start_pattern}" | sed 's#\/#\\\/#g')
@@ -110,7 +110,7 @@ print_lines_between_matching_patterns() {
 
 # Print file name if a file with that name exists.
 print_file_name() {
-  local file_name=${1}
+  local file_name="${1}"
   if test -f "${file_name}"; then
     printf '%s\n' "${file_name}" | cut -d '/' -f '2-'
   fi
@@ -121,8 +121,8 @@ print_file_name() {
 # SC1003: Want to escape a single quote? echo 'This is how it'\''s done'
 # reason: No, we don't want to escape a single quote, we want a backslash.
 print_generated_messages() {
-  local makefile_am=${1}; shift
-  local directory=${1}; shift
+  local makefile_am="${1}"; shift
+  local directory="${1}"; shift
 
   for j in $(grep -F 'messages:' "${makefile_am}" | cut -d ':' -f '2-' | \
     cut -d '\' -f 1); do
@@ -138,8 +138,8 @@ print_generated_messages() {
 
 # Generated parsers
 print_generated_parsers() {
-  local makefile_am=${1}; shift
-  local directory=${1}; shift
+  local makefile_am="${1}"; shift
+  local directory="${1}"; shift
 
   for j in $(grep -F 'parser:' "${makefile_am}" | cut -d ':' -f '2-'); do
     print_file_name "${directory}/${j}"
@@ -148,8 +148,8 @@ print_generated_parsers() {
 
 # Other generated files
 print_built_sources() {
-  local makefile_am=${1}; shift
-  local directory=${1}; shift
+  local makefile_am="${1}"; shift
+  local directory="${1}"; shift
 
   for j in $(grep -E 'BUILT_SOURCES (=|\+=)' "${makefile_am}" | cut -d '=' -f '2-'); do
     print_file_name "${directory}/${j}"
@@ -158,7 +158,7 @@ print_built_sources() {
 
 # Print all files of interest sorted alphabetically.
 print_all_sorted() {
-  local built_sources=${1-true}
+  local built_sources="${1-true}"
 
   for i in $(find . -type f -name 'Makefile.am'); do
     directory=$(dirname "${i}")