Skip to content

Commit 3618cef

Browse files
fix(crashtracking): Fix case when Bash associative array are not supported (#7956)
Associative arrays require Bash 4. I replaced them with dynamic variable names.
1 parent cd1b746 commit 3618cef

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/notify_oome.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,25 @@ fi
2222
# The expected contents are:
2323
# - agent: Path to the agent jar
2424
# - tags: Comma-separated list of tags to be sent with the OOME event; key:value pairs are supported
25-
declare -A config
2625
while IFS="=" read -r key value; do
27-
config["$key"]="$value"
26+
declare "config_$key"="$value"
2827
done < "$configFile"
2928

29+
# Exiting early if configuration is missing
30+
if [ -z "${config_agent}" ] || [ -z "${config_tags}" ]; then
31+
echo "Error: Missing configuration"
32+
exit 1
33+
fi
34+
3035
# Debug: Print the loaded values (Optional)
31-
echo "Agent Jar: ${config[agent]}"
32-
echo "Tags: ${config[tags]}"
36+
echo "Agent Jar: ${config_agent}"
37+
echo "Tags: ${config_tags}"
3338
echo "PID: $PID"
3439

3540
# Execute the Java command with the loaded values
36-
java -Ddd.dogstatsd.start-delay=0 -jar "${config[agent]}" sendOomeEvent "${config[tags]}"
41+
java -Ddd.dogstatsd.start-delay=0 -jar "${config_agent}" sendOomeEvent "${config_tags}"
3742
RC=$?
38-
rm -f ${configFile} # Remove the configuration file
43+
rm -f "${configFile}" # Remove the configuration file
3944

4045
if [ $RC -eq 0 ]; then
4146
echo "OOME Event generated successfully"

dd-java-agent/agent-crashtracking/src/main/resources/com/datadog/crashtracking/upload_crash.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ fi
3030
# The expected contents are:
3131
# - agent: Path to the agent jar
3232
# - hs_err: Path to the hs_err log file
33-
declare -A config
3433
while IFS="=" read -r key value; do
35-
config["$key"]="$value"
34+
declare "config_$key"="$value"
3635
done < "$configFile"
3736

37+
# Exiting early if configuration is missing
38+
if [ -z "${config_agent}" ] || [ -z "${config_hs_err}" ]; then
39+
echo "Error: Missing configuration"
40+
exit 1
41+
fi
42+
3843
# Debug: Print the loaded values (Optional)
39-
echo "Agent Jar: ${config[agent]}"
40-
echo "Error Log: ${config[hs_err]}"
44+
echo "Agent Jar: ${config_agent}"
45+
echo "Error Log: ${config_hs_err}"
4146
echo "PID: $PID"
4247

4348
# Execute the Java command with the loaded values
44-
java -jar "${config[agent]}" uploadCrash "${config[hs_err]}"
49+
java -jar "${config_agent}" uploadCrash "${config_hs_err}"
4550
RC=$?
46-
rm -f ${configFile} # Remove the configuration file
51+
rm -f "${configFile}" # Remove the configuration file
4752

4853
if [ $RC -eq 0 ]; then
49-
echo "Error file ${config[hs_err]} was uploaded successfully"
54+
echo "Error file ${config_hs_err} was uploaded successfully"
5055
else
51-
echo "Error: Failed to upload error file ${config[hs_err]}"
56+
echo "Error: Failed to upload error file ${config_hs_err}"
5257
exit $RC
5358
fi

0 commit comments

Comments
 (0)