OS/X has a flock (v0.2.3) implementation using
brew tap discoteq/discoteq
brew install flock
The current version doesn't support -x as a parameter for
an exclusive lock but uses an exclusive lock when no parameter
is passed at all.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
# Default logging goes to stderr
LOGFILE=""
+UNAME_S=$(uname -s)
+
logit()
{
if [ -z "$LOGFILE" ]; then
fi
}
+flock_fd()
+{
+ local fd=$1
+
+ case "${UNAME_S}" in
+ Darwin)
+ flock $fd;;
+ *)
+ flock -x $fd;;
+ esac
+}
+
# Get an configuration value from an configurations file
# @param1: The file with the options
# @param2: The name of the option
touch ${LOCK}
(
# Avoid concurrent creation of next serial
- flock -x 100
+ flock_fd 100
if [ $? -ne 0 ]; then
logerr "Could not get lock ${LOCK}"
return 1
touch ${LOCK}
(
# Avoid concurrent creation of keys and certs
- flock -x 100
+ flock_fd 100
if [ $? -ne 0 ]; then
logerr "Could not get lock ${LOCK}"
return 1