Skip to content

Commit

Permalink
修复linux下脚本无法执行的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dongchenxu committed Feb 3, 2019
1 parent b81d57e commit aa00c37
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions bin/sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,36 @@ check_permission()
reset_for_env()
{

# use the target PID's java for SANDBOX_JAVA_BIN
SANDBOX_JAVA_BIN="$(ps aux|grep ${TARGET_JVM_PID}|grep java|awk '{print $11}')"
[[ ! -x "${SANDBOX_JAVA_BIN}" ]] \
&& exit_on_err 1 "permission denied, ${SANDBOX_JAVA_BIN} is not executable."

# check the jvm version, we need 1.6+
local JAVA_VERSION=$("${SANDBOX_JAVA_BIN}" -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}')
# use the env JAVA_HOME for default
[[ ! -z ${JAVA_HOME} ]] \
&& SANDBOX_JAVA_HOME="${JAVA_HOME}"

# use the target JVM for SANDBOX_JAVA_HOME
[[ -z ${SANDBOX_JAVA_HOME} ]] \
&& SANDBOX_JAVA_HOME="$(\
ps aux\
|grep ${TARGET_JVM_PID}\
|grep java\
|awk '{print $11}'\
|xargs ls -l\
|awk '{if($1~/^l/){print $11}else{print $9}}'\
|sed 's/\/bin\/java//g'\
)"

[[ ! -x "${SANDBOX_JAVA_HOME}" ]] \
&& exit_on_err 1 "permission denied, ${SANDBOX_JAVA_HOME} is not accessible! please set JAVA_HOME"

[[ ! -x "${SANDBOX_JAVA_HOME}/bin/java" ]] \
&& exit_on_err 1 "permission denied, ${SANDBOX_JAVA_HOME}/bin/java is not executable!"

# check the jvm version, we need 6+
local JAVA_VERSION=$("${SANDBOX_JAVA_HOME}/bin/java" -version 2>&1|awk -F '"' '/version/&&$2>"1.5"{print $2}')
[[ -z ${JAVA_VERSION} ]] \
&& exit_on_err 1 "illegal java version: ${JAVA_VERSION}, please make sure target java process: ${TARGET_JVM_PID} run int JDK[6,11]"

[[ -f "${SANDBOX_JAVA_HOME}"/lib/tools.jar ]] \
&& SANDBOX_JVM_OPS="${SANDBOX_JVM_OPS} -Xbootclasspath/a:${SANDBOX_JAVA_HOME}/lib/tools.jar"

}


Expand All @@ -215,7 +235,7 @@ function attach_jvm() {
local token=`date |head|cksum|sed 's/ //g'`

# attach target jvm
"${SANDBOX_JAVA_BIN}"\
"${SANDBOX_JAVA_HOME}/bin/java" \
${SANDBOX_JVM_OPS} \
-jar ${SANDBOX_LIB_DIR}/sandbox-core.jar \
${TARGET_JVM_PID} \
Expand Down

0 comments on commit aa00c37

Please sign in to comment.