You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/10/25 17:08:04 UTC

[karaf] branch master updated: Put JAVA_OPTS between quotes for handling parameters with spaces

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 3bbde62  Put JAVA_OPTS between quotes for handling parameters with spaces
     new 548e3e0  Merge pull request #955 from mdonkers/patch-1
3bbde62 is described below

commit 3bbde624957cec0520a3cbeb388ad07306654695
Author: Miel Donkers <mi...@instana.com>
AuthorDate: Tue Oct 15 17:19:50 2019 +0200

    Put JAVA_OPTS between quotes for handling parameters with spaces
    
    Certain Java options might contain spaces, for example the `-XX:OnError` which can be used to execute a command or script and takes the parameter `%p` as placeholder for the current PID of the Java process. However, due to the way e.g. Bash handles variables in scripts, it makes a lot of difference whether these are placed between quotes. Without quotes, spaces are handled so that they break up parameters.
    This causes e.g. the following `export JAVA_OPTS="-XX:OnError=\"echo %p\""` to be handled as two separate arguments resulting in the error: `Error: Could not find or load main class %p`
    
    The only downside I found from quoting is if e.g. a user has a script `export JAVA_OPTS="${JAVA_OPTS} ${MY_OPTS}"` and `JAVA_OPTS` was not previously set, an additional space is introduced which is not handled nicely.
---
 .../features/base/src/main/filtered-resources/resources/bin/karaf     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/assemblies/features/base/src/main/filtered-resources/resources/bin/karaf b/assemblies/features/base/src/main/filtered-resources/resources/bin/karaf
index e51bb8d..28ea80a 100644
--- a/assemblies/features/base/src/main/filtered-resources/resources/bin/karaf
+++ b/assemblies/features/base/src/main/filtered-resources/resources/bin/karaf
@@ -299,7 +299,7 @@ run() {
 
         if [ "${ROOT_INSTANCE_RUNNING}" = "false" ] || [ "${CHECK_ROOT_INSTANCE_RUNNING}" = "false" ] ; then
             if [ "${VERSION}" -gt "8" ]; then
-                ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
+                ${KARAF_EXEC} "${JAVA}" "${JAVA_OPTS}" \
                     --add-reads=java.xml=java.logging \
                     --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED \
                     --patch-module java.base=lib/endorsed/org.apache.karaf.specs.locator-@@project.version@@.jar \
@@ -330,7 +330,7 @@ run() {
                     -classpath "${CLASSPATH}" \
                     ${MAIN} "$@"
             else
-                ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
+                ${KARAF_EXEC} "${JAVA}" "${JAVA_OPTS}" \
                     -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" \
                     -Djava.ext.dirs="${JAVA_EXT_DIRS}" \
                     -Dkaraf.instances="${KARAF_HOME}/instances" \