diff options
author | shtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2> | 2013-07-10 05:18:12 +0000 |
---|---|---|
committer | shtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2> | 2013-07-10 05:18:12 +0000 |
commit | 883813db4f7ea304f72dee8c01aa6c73bf89dcf6 (patch) | |
tree | 2e03a7b1481f904172456e142be90a8993c4ba0e | |
parent | 59c232421670fbe207fcb79465fdf741e9dd1f11 (diff) |
Use PID file rather than unreliable grep chain to detect already running processes.
git-svn-id: svn+ssh://scm.narf.ssji.net/svn/shtrom/scripts@1553 1991c358-8f32-0410-a49a-990740bdf4c2
-rwxr-xr-x | openbsd/denyhost.sh | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/openbsd/denyhost.sh b/openbsd/denyhost.sh index 714fefb..a1cafa3 100755 --- a/openbsd/denyhost.sh +++ b/openbsd/denyhost.sh @@ -23,13 +23,17 @@ NUM_TRIES=3 TMP_DIR=/var/tmp NEW_BLOCKERS_FILE=`mktemp ${TMP_DIR}/blockers.list.XXXXXX` DEST_ADDR=root@`hostname` +PIDFILE=/var/run/denyhost.sh MAIL=mail # Exit if another instance is already running. -# Selecting on 'R+' is a bit of a kludge to avoid getting yet to be named -# processes forks for the pipe of this very check... -ps ax | grep $0 | grep -v "R+" | grep -v $$ | grep -qv grep && exit 1 +if test -e $PIDFILE && kill -0 `cat $PIDFILE` > /dev/null; then + echo "$0 process already running (`cat $PIDFILE`), exiting" >&2 + exit 0 +else + echo $$ > $PIDFILE +fi function process_ip { @@ -143,3 +147,5 @@ pfctl -t kiddies -T expire 25200 1>/dev/null 2>&1 # Add new entries mv $NEW_BLOCKERS_FILE ${TMP_DIR}/blockers.list pfctl -t kiddies -Tadd -f ${TMP_DIR}/blockers.list 1>/dev/null 2>&1 + +rm $PIDFILE |