From 65c353350af29228372e97471a41c42f31def887 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 17 Aug 2017 22:50:27 -0400 Subject: [PATCH] Add safer empty variable checking for Windows We need to check if JAVA_TOOL_OPTIONS, and JAVA_OPTS are set, and if ES_PATH_CONF is not set. However, if these variables are defined and contain quotes, the current mechanism busts on them. Instead, we should use safer mechanism for checking if these variable are defined or not. This commit does that. Relates #26268 --- distribution/src/main/resources/bin/elasticsearch-env.bat | 6 +++--- .../src/main/resources/bin/elasticsearch-keystore.bat | 2 ++ .../src/main/resources/bin/elasticsearch-plugin.bat | 2 ++ .../src/main/resources/bin/elasticsearch-service.bat | 2 ++ .../src/main/resources/bin/elasticsearch-translog.bat | 2 ++ distribution/src/main/resources/bin/elasticsearch.bat | 2 ++ 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/distribution/src/main/resources/bin/elasticsearch-env.bat b/distribution/src/main/resources/bin/elasticsearch-env.bat index 626ea3b8c6f..00cc7fa0980 100644 --- a/distribution/src/main/resources/bin/elasticsearch-env.bat +++ b/distribution/src/main/resources/bin/elasticsearch-env.bat @@ -29,14 +29,14 @@ if not exist %JAVA% ( ) rem do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default) -if not "%JAVA_TOOL_OPTIONS%" == "" ( +if defined JAVA_TOOL_OPTIONS ( echo warning: ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS% set JAVA_TOOL_OPTIONS= ) rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we rem warn them that we are not observing the value of %JAVA_OPTS% -if not "%JAVA_OPTS%" == "" ( +if defined JAVA_OPTS ( (echo|set /p=warning: ignoring JAVA_OPTS=%JAVA_OPTS%; ) echo pass JVM parameters via ES_JAVA_OPTS ) @@ -46,6 +46,6 @@ rem check the Java version set HOSTNAME=%COMPUTERNAME% -if "%ES_PATH_CONF%" == "" ( +if not defined ES_PATH_CONF ( set ES_PATH_CONF=!ES_HOME!\config ) diff --git a/distribution/src/main/resources/bin/elasticsearch-keystore.bat b/distribution/src/main/resources/bin/elasticsearch-keystore.bat index f12ffd60092..7e131a80a1b 100644 --- a/distribution/src/main/resources/bin/elasticsearch-keystore.bat +++ b/distribution/src/main/resources/bin/elasticsearch-keystore.bat @@ -1,6 +1,7 @@ @echo off setlocal enabledelayedexpansion +setlocal enableextensions call "%~dp0elasticsearch-env.bat" || exit /b 1 @@ -13,3 +14,4 @@ call "%~dp0elasticsearch-env.bat" || exit /b 1 %* endlocal +endlocal diff --git a/distribution/src/main/resources/bin/elasticsearch-plugin.bat b/distribution/src/main/resources/bin/elasticsearch-plugin.bat index 95de9c1c417..1d059aaacee 100644 --- a/distribution/src/main/resources/bin/elasticsearch-plugin.bat +++ b/distribution/src/main/resources/bin/elasticsearch-plugin.bat @@ -1,6 +1,7 @@ @echo off setlocal enabledelayedexpansion +setlocal enableextensions call "%~dp0elasticsearch-env.bat" || exit /b 1 @@ -13,3 +14,4 @@ call "%~dp0elasticsearch-env.bat" || exit /b 1 %* endlocal +endlocal diff --git a/distribution/src/main/resources/bin/elasticsearch-service.bat b/distribution/src/main/resources/bin/elasticsearch-service.bat index b1270ec0298..8326c689b28 100644 --- a/distribution/src/main/resources/bin/elasticsearch-service.bat +++ b/distribution/src/main/resources/bin/elasticsearch-service.bat @@ -1,6 +1,7 @@ @echo off setlocal enabledelayedexpansion +setlocal enableextensions call "%~dp0elasticsearch-env.bat" || exit /b 1 @@ -266,3 +267,4 @@ set "%~2=%conv%" goto:eof endlocal +endlocal diff --git a/distribution/src/main/resources/bin/elasticsearch-translog.bat b/distribution/src/main/resources/bin/elasticsearch-translog.bat index 9b375f283c2..4f15e9b3792 100644 --- a/distribution/src/main/resources/bin/elasticsearch-translog.bat +++ b/distribution/src/main/resources/bin/elasticsearch-translog.bat @@ -1,6 +1,7 @@ @echo off setlocal enabledelayedexpansion +setlocal enableextensions call "%~dp0elasticsearch-env.bat" || exit /b 1 @@ -13,3 +14,4 @@ call "%~dp0elasticsearch-env.bat" || exit /b 1 %* endlocal +endlocal diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index 057e686cdad..51f20476790 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -1,6 +1,7 @@ @echo off setlocal enabledelayedexpansion +setlocal enableextensions SET params='%*' @@ -51,3 +52,4 @@ for /F "usebackq delims=" %%a in (`findstr /b \- "%ES_JVM_OPTIONS%"`) do set JVM %JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! endlocal +endlocal