2007-09-23 08:04:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# lockfile.sh - handle lock files
|
2009-01-26 15:39:27 -01:00
|
|
|
# Copyright (C) 2006-2009 Daniel Baumann <daniel@debian.org>
|
2007-09-23 08:04:48 +00:00
|
|
|
#
|
|
|
|
# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
|
|
|
# This is free software, and you are welcome to redistribute it
|
|
|
|
# under certain conditions; see COPYING for details.
|
2007-09-23 08:04:46 +00:00
|
|
|
|
|
|
|
Check_lockfile ()
|
|
|
|
{
|
2007-09-23 08:04:49 +00:00
|
|
|
FILE="${1}"
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2008-11-01 12:40:21 -01:00
|
|
|
if [ -z "${FILE}" ]
|
|
|
|
then
|
|
|
|
FILE="/var/lock/${PROGRAM}.lock"
|
|
|
|
fi
|
|
|
|
|
2007-09-23 08:04:46 +00:00
|
|
|
# Checking lock file
|
2007-09-23 08:04:49 +00:00
|
|
|
if [ -f "${FILE}" ]
|
2007-09-23 08:04:46 +00:00
|
|
|
then
|
2008-11-01 12:40:21 -01:00
|
|
|
Echo_error "${PROGRAM} locked"
|
2007-09-23 08:04:46 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
Create_lockfile ()
|
|
|
|
{
|
2007-11-13 10:56:48 -01:00
|
|
|
FILE="${1}"
|
2008-11-01 12:40:21 -01:00
|
|
|
|
|
|
|
if [ -z "${FILE}" ]
|
|
|
|
then
|
|
|
|
FILE="/var/lock/${PROGRAM}.lock"
|
|
|
|
fi
|
|
|
|
|
|
|
|
DIRECTORY="$(dirname ${FILE})"
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2007-11-13 10:56:48 -01:00
|
|
|
# Creating lock directory
|
|
|
|
mkdir -p "${DIRECTORY}"
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2007-11-13 10:56:48 -01:00
|
|
|
# Creating lock trap
|
2008-10-31 04:45:05 -01:00
|
|
|
trap 'ret=${?}; '"rm -f \"${FILE}\";"' exit ${ret}' EXIT HUP INT QUIT TERM
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2007-11-13 10:56:48 -01:00
|
|
|
# Creating lock file
|
|
|
|
touch "${FILE}"
|
2007-09-23 08:04:46 +00:00
|
|
|
}
|