diff --git a/dist/tools/jlink/jlink.sh b/dist/tools/jlink/jlink.sh index ee25a4dc6d..b48015b982 100755 --- a/dist/tools/jlink/jlink.sh +++ b/dist/tools/jlink/jlink.sh @@ -236,15 +236,16 @@ do_term() { JLINK_PIDFILE=$(mktemp -t "jilnk_pid.XXXXXXXXXX") # will be called by trap cleanup() { - JLINK_PID="$(cat ${JLINK_PIDFILE})" - kill ${JLINK_PID} - rm -r "${JLINK_PIDFILE}" + if [ -f $JLINK_PIDFILE ]; then + JLINK_PID="$(cat ${JLINK_PIDFILE})" + kill ${JLINK_PID} + rm -r "${JLINK_PIDFILE}" + fi exit 0 } # cleanup after script terminates - trap "cleanup ${JLINK_PIDFILE}" EXIT - # don't trapon Ctrl+C, because JLink keeps running - trap '' INT + trap "cleanup ${JLINK_PIDFILE}" EXIT INT + # start Jlink as RTT server sh -c "${JLINK} ${JLINK_SERIAL} \ -ExitOnError 1 \