Make sure lock file is owned by blkdevalias user and group
authorBryn M. Reeves <bmr@redhat.com>
Fri, 1 Feb 2013 18:31:31 +0000 (18:31 +0000)
committerBryn M. Reeves <bmr@redhat.com>
Fri, 1 Feb 2013 18:31:31 +0000 (18:31 +0000)
Set the owner of /var/lock/blkdevalias to the configured user
and group when setting config file ownership and when locking and
unlocking the file.

blkdevalias

index 35bd96a..0f699b1 100755 (executable)
@@ -249,6 +249,7 @@ ba_chown_configs () {
     _USER="$1"
     _GROUP="$2"
     $BA_CHOWN -R "$_USER:$_GROUP" "$BA_CONF_DIR"
+    $BA_CHOWN "$_USER:$_GROUP" "$BA_LOCK_PATH"
     ls -l "$BA_CONF_DIR" | while read _OUT; do
         _debug "$FUNCNAME: $_OUT"
     done
@@ -534,6 +535,10 @@ ba_lock_map () {
     $BA_FLOCK $_FLAG -n $BA_LOCK_FD
     _STATUS="$?"
     _debug "$FUNCNAME: flock exited with status $_STATUS"
+    # we may be running as root - if so re-chown the lock file
+    if [ "$BA_REAL_UID" == "0" ] || [ "$BA_REAL_GID" == "0" ]; then
+        $BA_CHOWN "$BA_USER:$BA_GROUP" "$BA_LOCK_PATH"
+    fi
     return $_STATUS
 }
 
@@ -543,6 +548,10 @@ ba_unlock_map () {
     $BA_FLOCK -u -n $BA_LOCK_FD
     _STATUS="$?"
     _debug "$FUNCNAME: flock exited with status $_STATUS"
+    if [ "$BA_REAL_UID" == "0" ] || [ "$BA_REAL_GID" == "0" ]; then
+        $BA_CHOWN "$BA_USER:$BA_GROUP" "$BA_LOCK_PATH"
+    fi
+    _STATUS="$?"
     return $_STATUS
 }