]> git.treefish.org Git - backmeupscotty.git/blobdiff - backmeupscotty
Replaced flocking again with mkdir lock to prevent leaking file descriptors when...
[backmeupscotty.git] / backmeupscotty
index e0689a042a60240b16f3d0cfac77a6e0e5c52c4b..e17a4c6a215b8f02d4de9eb4e4d6b033eec3a740 100644 (file)
@@ -125,6 +125,12 @@ function scottysync {
     done
 }
 
+function deleteLock {
+    if ! rmdir /tmp/$(basename $0).lock; then
+       scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!"
+    fi
+}
+
 function cleanup_abort {
     scottyerror "Caught exit signal! Cleaning up."
 
@@ -135,6 +141,8 @@ function cleanup_abort {
        kill $(jobs -p)
     fi
 
+    deleteLock
+
     exit
 }
 
@@ -146,6 +154,11 @@ function prepare {
     scottyinfo "No prepare function was defined."
 }
 
+function cleanup_normal {
+    cleanup
+    deleteLock
+}
+
 function printhelp {
     cat <<EOF
 Usage: $(basename $0) [OPTION]...
@@ -191,14 +204,14 @@ function backmeupscotty {
     prepare
     scottysync
 
-    trap cleanup EXIT
+    trap cleanup_normal EXIT
 
     exit 0
 }
 
-exec 200>/var/run/$(basename $0).pid
-if ! flock -n 200; then
+if ! mkdir /var/run/$(basename $0).lock; then
     scottyerror "Another instance of $(basename $0) is still running!"
     exit 1
+else
+    trap deleteLock EXIT
 fi
-echo $$ 1>&200