Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit b8de2bf

Browse files
committed
#695: Adds lock file feature to reaper.
1 parent 1358399 commit b8de2bf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/usr/sbin/reaper

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
set -e
44

5+
function __cleanup ()
6+
{
7+
__delete_lock
8+
}
9+
10+
function __create_lock ()
11+
{
12+
if [[ -n ${lock_file} ]]
13+
then
14+
touch "${lock_file}"
15+
fi
16+
}
17+
518
function __create_state ()
619
{
720
if [[ -n ${state_file} ]]
@@ -14,6 +27,14 @@ function __create_state ()
1427
fi
1528
}
1629

30+
function __delete_lock ()
31+
{
32+
if [[ -e ${lock_file} ]]
33+
then
34+
rm -f "${lock_file}"
35+
fi
36+
}
37+
1738
function __get_reaper_timeout ()
1839
{
1940
local -r default_value="${1:-3600}"
@@ -51,10 +72,13 @@ function __reap ()
5172
kill \
5273
-s "${signal:-TERM}" \
5374
"${pid:-1}"
75+
76+
__cleanup
5477
}
5578

5679
function main ()
5780
{
81+
local -r lock_file="/var/lock/subsys/reaper"
5882
local -r state_file="/var/lib/misc/reaper"
5983
local -r timeout="$(
6084
__get_reaper_timeout
@@ -93,6 +117,18 @@ function main ()
93117
esac
94118
done
95119

120+
if [[ -e ${lock_file} ]]
121+
then
122+
>&2 printf -- \
123+
'ERROR: %s lock detected - aborting\n' \
124+
"${0##*/}"
125+
exit 1
126+
fi
127+
128+
trap __cleanup \
129+
EXIT INT TERM
130+
__create_lock
131+
96132
if (( timeout > 0 ))
97133
then
98134
trap __reap \

0 commit comments

Comments
 (0)