GP-2987: No longer using eval in launch.sh

This commit is contained in:
Ryan Kurtz 2023-01-05 11:51:14 -05:00
parent 70a155cb70
commit 1640b544c3
3 changed files with 39 additions and 20 deletions

View file

@ -32,8 +32,8 @@ function showUsage() {
echo " <max-memory>: maximum memory heap size in MB (e.g., 768M or 2G). Use empty \"\" if default" echo " <max-memory>: maximum memory heap size in MB (e.g., 768M or 2G). Use empty \"\" if default"
echo " should be used. This will generally be upto 1/4 of the physical memory available" echo " should be used. This will generally be upto 1/4 of the physical memory available"
echo " to the OS." echo " to the OS."
echo " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\") - use" echo " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\"). Use"
echo " empty \"\" if vmargs not needed" echo " empty \"\" if vmargs not needed. Spaces are not supported."
echo " <app-classname>: application classname (e.g., ghidra.GhidraRun )" echo " <app-classname>: application classname (e.g., ghidra.GhidraRun )"
echo " <app-args>...: arguments to be passed to the application" echo " <app-args>...: arguments to be passed to the application"
echo " " echo " "
@ -44,10 +44,12 @@ function showUsage() {
} }
VMARG_LIST= VMARGS_FROM_CALLER= # Passed in from the outer script as one long string, no spaces
VMARGS_FROM_LAUNCH_SH=() # Defined in this script, added to array
VMARGS_FROM_LAUNCH_PROPS=() # Retrieved from LaunchSupport, added to array
ARGS=() ARGS=()
INDEX=0 INDEX=0
WHITESPACE="[[:space:]]" WHITESPACE="[[:space:]]"
for AA in "$@" for AA in "$@"
@ -72,17 +74,13 @@ do
;; ;;
5) 5)
if [ "$AA" != "" ]; then if [ "$AA" != "" ]; then
VMARG_LIST=$AA VMARGS_FROM_CALLER=$AA
fi fi
;; ;;
6) 6)
CLASSNAME=$AA CLASSNAME=$AA
;; ;;
*) *)
# Preserve quoted arguments
if [[ $AA =~ $WHITESPACE ]]; then
AA="\"$AA\""
fi
ARGS[${#ARGS[@]}]=$AA ARGS[${#ARGS[@]}]=$AA
;; ;;
esac esac
@ -147,20 +145,21 @@ fi
JAVA_CMD="${JAVA_HOME}/bin/java" JAVA_CMD="${JAVA_HOME}/bin/java"
# Get the configurable VM arguments from the launch properties # Get the configurable VM arguments from the launch properties
VMARG_LIST+=" $(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -vmargs)" while IFS= read -r line; do
VMARGS_FROM_LAUNCH_PROPS+=("$line")
done < <(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -vmargs)
# Add extra macOS VM arguments # Add extra macOS VM arguments
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
VMARG_LIST+=" -Xdock:name=${APPNAME}" VMARGS_FROM_LAUNCH_SH+=("-Xdock:name=${APPNAME}")
fi fi
# Set Max Heap Size if specified # Set Max Heap Size if specified
if [ "${MAXMEM}" != "" ]; then if [ "${MAXMEM}" != "" ]; then
VMARG_LIST+=" -Xmx${MAXMEM}" VMARGS_FROM_LAUNCH_SH+=("-Xmx${MAXMEM}")
fi fi
BACKGROUND=false BACKGROUND=false
if [ "${MODE}" = "debug" ] || [ "${MODE}" = "debug-suspend" ]; then if [ "${MODE}" = "debug" ] || [ "${MODE}" = "debug-suspend" ]; then
SUSPEND=n SUSPEND=n
@ -173,8 +172,8 @@ if [ "${MODE}" = "debug" ] || [ "${MODE}" = "debug-suspend" ]; then
SUSPEND=y SUSPEND=y
fi fi
VMARG_LIST+=" -Dlog4j.configurationFile=\"${DEBUG_LOG4J}\"" VMARGS_FROM_LAUNCH_SH+=("-Dlog4j.configurationFile=${DEBUG_LOG4J}")
VMARG_LIST+=" -agentlib:jdwp=transport=dt_socket,server=y,suspend=${SUSPEND},address=${DEBUG_ADDRESS}" VMARGS_FROM_LAUNCH_SH+=("-agentlib:jdwp=transport=dt_socket,server=y,suspend=${SUSPEND},address=${DEBUG_ADDRESS}")
elif [ "${MODE}" = "fg" ]; then elif [ "${MODE}" = "fg" ]; then
@ -189,7 +188,7 @@ else
fi fi
if [ "${BACKGROUND}" = true ]; then if [ "${BACKGROUND}" = true ]; then
eval "\"${JAVA_CMD}\" ${VMARG_LIST} -showversion -cp \"${CPATH}\" ghidra.Ghidra ${CLASSNAME} ${ARGS[@]}" &>/dev/null & "${JAVA_CMD}" "${VMARGS_FROM_LAUNCH_PROPS[@]}" "${VMARGS_FROM_LAUNCH_SH[@]}" ${VMARGS_FROM_CALLER} -showversion -cp "${CPATH}" ghidra.Ghidra ${CLASSNAME} "${ARGS[@]}" &>/dev/null &
# If our process dies immediately, output something so the user knows to run in debug mode. # If our process dies immediately, output something so the user knows to run in debug mode.
# Otherwise they'll never see any error output from background mode. # Otherwise they'll never see any error output from background mode.
@ -202,7 +201,7 @@ if [ "${BACKGROUND}" = true ]; then
fi fi
exit 0 exit 0
else else
eval "(set -o noglob; \"${JAVA_CMD}\" ${VMARG_LIST} -showversion -cp \"${CPATH}\" ghidra.Ghidra ${CLASSNAME} ${ARGS[@]})" set -o noglob; "${JAVA_CMD}" "${VMARGS_FROM_LAUNCH_PROPS[@]}" "${VMARGS_FROM_LAUNCH_SH[@]}" ${VMARGS_FROM_CALLER} -showversion -cp "${CPATH}" ghidra.Ghidra ${CLASSNAME} "${ARGS[@]}"
exit $? exit $?
fi fi

View file

@ -278,8 +278,8 @@ public class LaunchSupport {
/** /**
* Handles getting the VM arguments. If they are successfully determined, they are printed * Handles getting the VM arguments. If they are successfully determined, they are printed
* to STDOUT as a string that can be added to the command line, and an exit code that * to STDOUT as a new-line delimited string that can be parsed and added to the command line,
* indicates success is returned. * and an exit code that indicates success is returned.
* @param javaConfig The Java configuration that defines what we support. * @param javaConfig The Java configuration that defines what we support.
* @return A suggested exit code based on whether or not the VM arguments were successfully * @return A suggested exit code based on whether or not the VM arguments were successfully
@ -291,7 +291,7 @@ public class LaunchSupport {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
System.out.println(javaConfig.getLaunchProperties().getVmArgs()); javaConfig.getLaunchProperties().getVmArgList().forEach(arg -> System.out.println(arg));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }

View file

@ -100,6 +100,26 @@ public class LaunchProperties {
return sb.toString(); return sb.toString();
} }
/**
* Gets a {@link List} of VM arguments to use for the launch for the current
* {@link Platform platform}.
*
* @return A {@link List} of VM arguments to use for the launch for the current
* {@link Platform}
*/
public List<String> getVmArgList() {
List<String> ret = new ArrayList<>();
List<String> vmargList = propertyMap.get(VMARGS);
if (vmargList != null) {
ret.addAll(vmargList);
}
List<String> vmargPlatformList = propertyMap.get(VMARGS_PLATFORM);
if (vmargPlatformList != null) {
ret.addAll(vmargPlatformList);
}
return ret;
}
/** /**
* Parses and gets the launch properties from the given launch properties file. * Parses and gets the launch properties from the given launch properties file.
* *