bkctld-rm: fix lock file management

logic was badly implemented
This commit is contained in:
Jérémy Lecour 2020-04-18 19:11:08 +02:00 committed by Jérémy Lecour
parent 723c8511e1
commit 096fe95b2f

View file

@ -36,17 +36,21 @@ delete_inc_ext4() {
if [ -f "${lock_file}" ]; then if [ -f "${lock_file}" ]; then
# Get Process ID from the lock file # Get Process ID from the lock file
pid=$(cat "${lock_file}") pid=$(cat "${lock_file}")
if kill -0 ${pid} 2> /dev/null; then if [ -n "${pid}" ]; then
# Kill the children if kill -0 ${pid} 2> /dev/null; then
pkill -9 --parent "${pid}" # Kill the children
# Kill the parent pkill -9 --parent "${pid}"
kill -9 "${pid}" # Kill the parent
# Remove the lock file kill -9 "${pid}"
rm -f ${lock_file} warning "Process ${pid} has been killed. Only one ${0} can run in parallel, the latest wins."
warning "Process ${pid} has been killed. Only one ${0} can run in parallel, the latest wins." else
warning "Process not found at PID \`${pid}'. Ignoring lock file \`${lock_file}'."
fi
else else
error "Empty lockfile '${lock_file}'. It should contain a PID." error "Empty lockfile \`${lock_file}'. It should contain a PID."
fi fi
# Remove the lock file
rm -f ${lock_file}
fi fi
mkdir --parents "${LOCKDIR}" && echo $$ > ${lock_file} || error "Failed to acquire lock file '${lock_file}'" mkdir --parents "${LOCKDIR}" && echo $$ > ${lock_file} || error "Failed to acquire lock file '${lock_file}'"
@ -60,6 +64,8 @@ delete_inc_ext4() {
rsync --archive --delete "${empty}/" "${inc_path}/" rsync --archive --delete "${empty}/" "${inc_path}/"
rmdir "${inc_path}/" rmdir "${inc_path}/"
fi fi
# Remove the lock file
rm -f ${lock_file}
end=$(current_time) end=$(current_time)
notice "${jail_name}: inc '${inc_name}' has been deleted [${start}/${end}]" notice "${jail_name}: inc '${inc_name}' has been deleted [${start}/${end}]"