From 9a707fd11e02dd02021a9cff2f003db9ea81e1dd Mon Sep 17 00:00:00 2001 From: Bruce Bujon Date: Thu, 14 Nov 2024 15:59:24 +0100 Subject: [PATCH] fix(crashtracking): Fix case when Bash associative array are not supported Associative arrays require Bash 4. I replaced them with dynamic variable names. --- .../com/datadog/crashtracking/notify_oome.sh | 17 +++++++++------ .../com/datadog/crashtracking/upload_crash.sh | 21 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/notify_oome.sh b/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/notify_oome.sh index 2d0eace2d6e..85ee5ef08ca 100644 --- a/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/notify_oome.sh +++ b/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/notify_oome.sh @@ -22,20 +22,25 @@ fi # The expected contents are: # - agent: Path to the agent jar # - tags: Comma-separated list of tags to be sent with the OOME event; key:value pairs are supported -declare -A config while IFS="=" read -r key value; do - config["$key"]="$value" + declare "config_$key"="$value" done < "$configFile" +# Exiting early if configuration is missing +if [ -z "${config_agent}" ] || [ -z "${config_tags}" ]; then + echo "Error: Missing configuration" + exit 1 +fi + # Debug: Print the loaded values (Optional) -echo "Agent Jar: ${config[agent]}" -echo "Tags: ${config[tags]}" +echo "Agent Jar: ${config_agent}" +echo "Tags: ${config_tags}" echo "PID: $PID" # Execute the Java command with the loaded values -java -Ddd.dogstatsd.start-delay=0 -jar "${config[agent]}" sendOomeEvent "${config[tags]}" +java -Ddd.dogstatsd.start-delay=0 -jar "${config_agent}" sendOomeEvent "${config_tags}" RC=$? -rm -f ${configFile} # Remove the configuration file +rm -f "${configFile}" # Remove the configuration file if [ $RC -eq 0 ]; then echo "OOME Event generated successfully" diff --git a/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/upload_crash.sh b/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/upload_crash.sh index 160609e259d..7b417dcc1be 100644 --- a/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/upload_crash.sh +++ b/dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/upload_crash.sh @@ -30,24 +30,29 @@ fi # The expected contents are: # - agent: Path to the agent jar # - hs_err: Path to the hs_err log file -declare -A config while IFS="=" read -r key value; do - config["$key"]="$value" + declare "config_$key"="$value" done < "$configFile" +# Exiting early if configuration is missing +if [ -z "${config_agent}" ] || [ -z "${config_hs_err}" ]; then + echo "Error: Missing configuration" + exit 1 +fi + # Debug: Print the loaded values (Optional) -echo "Agent Jar: ${config[agent]}" -echo "Error Log: ${config[hs_err]}" +echo "Agent Jar: ${config_agent}" +echo "Error Log: ${config_hs_err}" echo "PID: $PID" # Execute the Java command with the loaded values -java -jar "${config[agent]}" uploadCrash "${config[hs_err]}" +java -jar "${config_agent}" uploadCrash "${config_hs_err}" RC=$? -rm -f ${configFile} # Remove the configuration file +rm -f "${configFile}" # Remove the configuration file if [ $RC -eq 0 ]; then - echo "Error file ${config[hs_err]} was uploaded successfully" + echo "Error file ${config_hs_err} was uploaded successfully" else - echo "Error: Failed to upload error file ${config[hs_err]}" + echo "Error: Failed to upload error file ${config_hs_err}" exit $RC fi