Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Improve error handling for invalid applications
Browse files Browse the repository at this point in the history
If an invalid application name is given (no process matches the name),
we should abort and error out instead of trying to pass bogus arguments
to jmap/jstack.
  • Loading branch information
nicktelford committed Oct 19, 2016
1 parent f2fca3f commit e4628fc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jdump.sh
Expand Up @@ -98,7 +98,11 @@ JSTACK="$(which jstack 2>/dev/null)"

[[ -z "$JSTACK" ]] && not_found "jstack"

PID=$($JPS 2>/dev/null | grep -i "$APP_NAME" | awk '{print $1}')
PID=$($JPS 2>/dev/null | grep -i "$APP_NAME" 2>/dev/null | head -n1 | awk '{print $1}')
if (( $? > 1 )); then
error "Failed to get PID for: $APP_NAME"
fi

if [[ -z "$PID" ]]; then
# try again, as root
if [[ "$USER" != "root" ]]
Expand Down

0 comments on commit e4628fc

Please sign in to comment.