From e7d2effc2701cbdf5b596f318d55b097ffc34e7b Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 19 May 2019 12:54:59 +0200 Subject: [PATCH] working background jobs, fix old pipes --- bashbot.sh | 5 ++++- modules/background.sh | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index a17fbd8..8b151f1 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev3-2-ga1a823b +#### $$VERSION$$ v0.80-dev3-3-ga3c0d31 # # Exit Codes: # - 0 sucess (hopefully) @@ -364,6 +364,9 @@ start_bot() { [[ "${DEBUG}" = *"debug" ]] && exec &>>"DEBUG.log" [ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\"" [[ "${DEBUG}" = "xdebug"* ]] && set -x + #cleaup old pipes + find "${TMPDIR}" -type p -delete + while true; do UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)" diff --git a/modules/background.sh b/modules/background.sh index abddbec..08e5814 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.80-dev3-2-ga1a823b +#### $$VERSION$$ v0.80-dev3-3-ga3c0d31 # source from commands.sh if you want ro use interactive or background jobs @@ -51,11 +51,9 @@ start_proc() { kill_proc "$1" "$3" local fifo; fifo="${TMPDIR:-.}/$(procname "$1" "$3")" mkfifo "${fifo}" - { set -f - # shellcheck disable=SC2002 - cat "${fifo}" | $2 | "${SCRIPT}" outproc "${1}" "${fifo}" - } &>>"${fifo}.log" & - disown -a + nohup bash -c "{ set -f; exec 3>\"${fifo}\" & + cat \"${fifo}\" | $2 \"\" \"\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\" + }" &>>"${fifo}.log" & } @@ -84,9 +82,12 @@ kill_back() { # $1 chatid # $2 prefix kill_proc() { - local fifo; fifo="$(procname "$1" "$2")" - kill -15 "$(proclist "${fifo}")" 2>/dev/null + local fifo prid + fifo="$(procname "$1" "$2")" + prid="$(proclist "${fifo}")" fifo="${TMPDIR:-.}/${fifo}" + # shellcheck disable=SC2086 + [ "${prid}" != "" ] && kill ${prid} [ -s "${fifo}.log" ] || rm -f "${fifo}.log" [ -p "${fifo}" ] && rm -f "${fifo}"; }