mirror of
https://github.com/bol-van/zapret2.git
synced 2026-10-29 06:02:05 +00:00
blockcheck2.sh: temp files sweeper fix
This commit is contained in:
1 parent
a0c928be45
commit
299f833f39
1 file changed
+32
-28
+32
-28
@@ -63,34 +63,10 @@ IPFW_RULE_NUM=${IPFW_RULE_NUM:-$(($$ % $IPFW_RULE_MAX + 1))}
|
||||
IPFW_DIVERT_PORT=${IPFW_DIVERT_PORT:-$(($$ % 64536 + 1000))}
|
||||
QNUM=${QNUM:-$(($$ % 64536 + 1000))}
|
||||
|
||||
PARALLEL_OUT=/tmp/zapret_parallel_$$
|
||||
HDRTEMP=/tmp/zapret-hdr-$$
|
||||
|
||||
sweep_stale_pidfiles()
|
||||
{
|
||||
# $1 - fixed filename prefix immediately preceding the pid
|
||||
#
|
||||
# A normal exit already removes this run's own PARALLEL_OUT/HDRTEMP
|
||||
# files (unprepare_all(), further down), which covers Ctrl+C,
|
||||
# a closed terminal, and a plain kill. kill -9 and crashes bypass
|
||||
# that, as they would for any script's cleanup, and can leave
|
||||
# stale files behind indefinitely, since nothing about a later run
|
||||
# gives it any reason to know about a different PID's leftovers.
|
||||
# Removes a matching file only once its PID (the run that created
|
||||
# it) is confirmed no longer running, so a genuinely still-running
|
||||
# concurrent instance - a different PID, its own files - is never
|
||||
# touched.
|
||||
local f pid prefix="$1"
|
||||
for f in "$prefix"*; do
|
||||
[ -e "$f" ] || continue
|
||||
pid=${f#"$prefix"}
|
||||
pid=${pid%%[!0-9]*}
|
||||
[ -n "$pid" ] || continue
|
||||
kill -0 "$pid" 2>/dev/null || rm -f "$f"
|
||||
done
|
||||
}
|
||||
sweep_stale_pidfiles /tmp/zapret_parallel_
|
||||
sweep_stale_pidfiles /tmp/zapret-hdr-
|
||||
PARALLEL_OUT_TEMPLATE=/tmp/zapret_parallel_
|
||||
PARALLEL_OUT=$PARALLEL_OUT_TEMPLATE$$
|
||||
HDRTEMP_TEMPLATE=/tmp/zapret-hdr-$$
|
||||
HDRTEMP=$HDRTEMP_TEMPLATE$$
|
||||
|
||||
NFT_TABLE=blockcheck$$
|
||||
IPT_OUT_CHAIN=blockcheck_output_$$
|
||||
@@ -1951,6 +1927,32 @@ check_dns()
|
||||
return $r
|
||||
}
|
||||
|
||||
|
||||
sweep_stale_pidfiles()
|
||||
{
|
||||
# $1 - fixed filename prefix immediately preceding the pid
|
||||
#
|
||||
# A normal exit already removes this run's own PARALLEL_OUT/HDRTEMP
|
||||
# files (unprepare_all(), further down), which covers Ctrl+C,
|
||||
# a closed terminal, and a plain kill. kill -9 and crashes bypass
|
||||
# that, as they would for any script's cleanup, and can leave
|
||||
# stale files behind indefinitely, since nothing about a later run
|
||||
# gives it any reason to know about a different PID's leftovers.
|
||||
# Removes a matching file only once its PID (the run that created
|
||||
# it) is confirmed no longer running, so a genuinely still-running
|
||||
# concurrent instance - a different PID, its own files - is never
|
||||
# touched.
|
||||
local f pid prefix="$1"
|
||||
for f in "$prefix"*; do
|
||||
[ -e "$f" ] || continue
|
||||
pid=${f#"$prefix"}
|
||||
pid=${pid%%[!0-9]*}
|
||||
[ -n "$pid" ] || continue
|
||||
kill -0 "$pid" 2>/dev/null || rm -f "$f"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
block_signals()
|
||||
{
|
||||
# prevent signal function reenter
|
||||
@@ -2003,6 +2005,8 @@ fix_sbin_path
|
||||
check_system
|
||||
check_already
|
||||
[ "$UNAME" != CYGWIN -a "$SKIP_PKTWS" != 1 ] && require_root
|
||||
sweep_stale_pidfiles $PARALLEL_OUT_TEMPLATE
|
||||
sweep_stale_pidfiles $HDRTEMP_TEMPLATE
|
||||
check_prerequisites
|
||||
trap sigint_cleanup INT
|
||||
check_dns
|
||||
|
||||
Reference in new issue
Block a user