From db43daa5e96a704b24bf4452154b9318908c0c91 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Mon, 1 Jan 2018 16:42:21 +0800 Subject: [PATCH] code cleanup - remove redundant parenthesis, reduce code indentation - utils function -> util functions --- find-in-jars | 2 +- parseOpts.sh | 2 +- show-busy-java-threads | 32 +++++++++++++++----------------- test-cases/parseOpts-test.sh | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/find-in-jars b/find-in-jars index c7b25d95..3b42dad9 100755 --- a/find-in-jars +++ b/find-in-jars @@ -144,7 +144,7 @@ else fi ################################################################################ -# utils +# util funtions ################################################################################ [ -t 1 ] && readonly is_console=true || readonly is_console=false diff --git a/parseOpts.sh b/parseOpts.sh index caeb1711..1dc07f65 100755 --- a/parseOpts.sh +++ b/parseOpts.sh @@ -19,7 +19,7 @@ # @author Jerry Lee (oldratlee at gmail dot com) ##################################################################### -# Utils Funtions +# Util Funtions ##################################################################### # NOTE: $'foo' is the escape sequence syntax of bash diff --git a/show-busy-java-threads b/show-busy-java-threads index e70d6f26..94433b5b 100755 --- a/show-busy-java-threads +++ b/show-busy-java-threads @@ -17,7 +17,7 @@ readonly -a COMMAND_LINE=("$0" "$@") readonly USER="`whoami`" ################################################################################ -# utils funtions +# util funtions ################################################################################ # NOTE: $'foo' is the escape sequence syntax of bash @@ -190,22 +190,20 @@ printStackOfThreads() { ((counter++)) local jstackFile=/tmp/${uuid}_${pid} [ -f "${jstackFile}" ] || { - { - if [ "${user}" == "${USER}" ]; then - # run without sudo, when java process user is current user - "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile} - elif [ $UID == 0 ]; then - # if java process user is not current user, must run jstack with sudo - sudo -u "${user}" "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile} - else - # current user is not root user, so can not run with sudo; print error message and rerun suggestion - redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})." - redPrint "User of java process($user) is not current user($USER), need sudo to rerun:" - yellowPrint " sudo ${COMMAND_LINE[@]}" - normalPrint - continue - fi - } || { + if [ "${user}" == "${USER}" ]; then + # run without sudo, when java process user is current user + "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile} + elif [ $UID == 0 ]; then + # if java process user is not current user, must run jstack with sudo + sudo -u "${user}" "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile} + else + # current user is not root user, so can not run with sudo; print error message and rerun suggestion + redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})." + redPrint "User of java process($user) is not current user($USER), need sudo to rerun:" + yellowPrint " sudo ${COMMAND_LINE[@]}" + normalPrint + continue + fi || { redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})." normalPrint rm ${jstackFile} diff --git a/test-cases/parseOpts-test.sh b/test-cases/parseOpts-test.sh index 6fbd8ff9..95271746 100755 --- a/test-cases/parseOpts-test.sh +++ b/test-cases/parseOpts-test.sh @@ -6,7 +6,7 @@ BASE=`dirname $0` ################################################# -# Utils Functions +# Util Functions ################################################# # NOTE: $'foo' is the escape sequence syntax of bash