block-mount: Fixed mount deadlocks due to buggy use of locks in /lib/functions/block.sh
authorcshore <cshore@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 29 Jun 2010 10:07:45 +0000 (10:07 +0000)
committercshore <cshore@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 29 Jun 2010 10:07:45 +0000 (10:07 +0000)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@21987 3c298f89-4303-0410-b956-a3cf2f4a3e73

package/block-mount/files/block.sh

index b8a473a..72d6c3a 100644 (file)
@@ -118,15 +118,18 @@ config_create_swap_fstab_entry() {
 
        [ -n "$device" ] || return 0
 
-       local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+       local fstabnew
        
        mkdir -p /var/lock
-       lock /var/lock/fstab.lck
-       cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" >>"$fstabnew"
-       [ "$enabled" -eq 1 ] && echo "$device   none    swap    sw      0       0" >> "$fstabnew"
-       cat "$fstabnew" >/tmp/fstab
-       lock -u /var/lock/fstab.lck
-       rm -f $fstabnew
+       lock -w /var/lock/fstab.lck && {
+               lock /var/lock/fstab.lck
+               fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+               cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" >>"$fstabnew"
+               [ "$enabled" -eq 1 ] && echo "$device   none    swap    sw      0       0" >> "$fstabnew"
+               cat "$fstabnew" >/tmp/fstab
+               rm -f $fstabnew
+               lock -u /var/lock/fstab.lck
+       }
 }
 
 config_create_mount_fstab_entry() {
@@ -140,15 +143,18 @@ config_create_mount_fstab_entry() {
        [ -n "$target" ] || return 0
        [ -n "$device" ] || return 0
 
-       local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+       local fstabnew
        
        mkdir -p /var/lock
-       lock /var/lock/fstab.lck
-       cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" | grep -v "$target" >>"$fstabnew"
-       echo "$device   $target $fstype $options        0       0" >>"$fstabnew"
-       cat "$fstabnew" >/tmp/fstab             
-       lock -u /var/lock/fstab.lck
-       rm -f $fstabnew
+       lock -w /var/lock/fstab.lck && {
+               lock /var/lock/fstab.lck
+               fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+               cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" | grep -v "$target" >>"$fstabnew"
+               echo "$device   $target $fstype $options        0       0" >>"$fstabnew"
+               cat "$fstabnew" >/tmp/fstab             
+               rm -f $fstabnew
+               lock -u /var/lock/fstab.lck
+       }
 }
 
 libmount_find_token() {
This page took 0.028076 seconds and 4 git commands to generate.