Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit code fix #373

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions emba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,12 @@ main()
if [[ -f "$HTML_PATH"/index.html ]]; then
print_output "[*] Open the web-report with$ORANGE firefox $(abs_path "$HTML_PATH/index.html")$NC\\n" "main"
fi
cleaner
cleaner 0
fi
exit 0
else
print_output "[-] EMBA failed in docker mode!" "main"
cleaner
cleaner 0
write_notification "EMBA failed analysis in default mode"
exit 1
fi
Expand Down Expand Up @@ -1057,6 +1057,8 @@ main()
# we need to change the permissions of the LOG_DIR to the orig. user from the host
restore_permissions
fi
cleaner 0
exit 0
}

main "$@"
23 changes: 16 additions & 7 deletions helpers/helpers_emba_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ max_pids_protection() {
done
}

# $1 - 1 some interrupt detected
# $1 - 0 default exit 0
cleaner() {
print_output "[*] User interrupt detected!" "no_log"
INTERRUPT_CLEAN="${1:-1}"
if [[ "$INTERRUPT_CLEAN" -eq 1 ]]; then
print_output "[*] User interrupt detected!" "no_log"
fi
print_output "[*] Final cleanup started." "no_log"

# stop inotifywait on host
if pgrep -f "inotifywait.*$LOG_DIR.*" &> /dev/null 2>&1; then
if [[ "$IN_DOCKER" -eq 0 ]] && pgrep -f "inotifywait.*$LOG_DIR.*" &> /dev/null 2>&1; then
print_output "[*] Stopping inotify ..."
pkill -f "inotifywait.*$LOG_DIR.*" || true
fi

Expand Down Expand Up @@ -130,13 +136,14 @@ cleaner() {
restore_permissions
fi

if pgrep -f "find ./external/trickest" &> /dev/null 2>&1; then
if [[ "$IN_DOCKER" -eq 0 ]] && pgrep -f "find ./external/trickest" &> /dev/null 2>&1; then
pkill -f "find ./external/trickest" 2>/dev/null || true
fi

if [[ "$NOTIFICATION_PID" != "NA" ]]; then
kill "$NOTIFICATION_PID" 2>/dev/null || true
fi
# what a quick fix - need to come back to this!
#if [[ "$NOTIFICATION_PID" != "NA" ]]; then
# kill "$NOTIFICATION_PID" 2>/dev/null || true
#fi
if [[ -f "$TMP_DIR"/orig_logdir ]]; then
LOG_DIR_HOST=$(cat "$TMP_DIR"/orig_logdir)
pkill -f "inotifywait.*$LOG_DIR_HOST" 2>/dev/null || true
Expand All @@ -150,7 +157,9 @@ cleaner() {
rm -r "$TMP_DIR" 2>/dev/null || true
fi
print_output "[!] Test ended on ""$(date)"" and took about ""$(date -d@"$SECONDS" -u +%H:%M:%S)"" \\n" "no_log"
exit 1
if [[ "$INTERRUPT_CLEAN" -eq 1 ]]; then
exit 1
fi
}

emba_updater() {
Expand Down