hal/tools/callouts fstab-update.sh,1.6,1.7

Joe Shaw joe at pdx.freedesktop.org
Fri May 7 10:41:41 PDT 2004


Update of /cvs/hal/hal/tools/callouts
In directory pdx:/tmp/cvs-serv5754/tools/callouts

Modified Files:
	fstab-update.sh 
Log Message:
2004-05-07  Joe Shaw  <joe at ximian.com>

	* doc/TODO: Add an item about clean daemon shutdown.

	* tools/callouts/fstab-update.sh: Add locking on the fstab so
	things don't race for it.  Timeout after 10 seconds.  Also be
	overly cautious about when we remove the block device from the
	fstab and check to make sure that the resulting fstab exists and
	is larger than 0 bytes in size.

Index: fstab-update.sh
===================================================================
RCS file: /cvs/hal/hal/tools/callouts/fstab-update.sh,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/fstab-update.sh	5 May 2004 20:46:34 -0000	1.6
+++ b/fstab-update.sh	7 May 2004 17:41:33 -0000	1.7
@@ -39,6 +39,22 @@
 MEDIAROOT="/mnt"
 MOUNTPOINT="$MEDIAROOT/hal/disk-$HAL_PROP_BLOCK_MAJOR-$HAL_PROP_BLOCK_MINOR-"
 
+max_loops=10
+loop_times=0
+while [ -e /etc/fstab-lock -a $loop_times -lt $max_loops ]; do
+    loop_times=$((loop_times+1))
+    echo "waiting for fstab lock... ($HAL_PROP_BLOCK_DEVICE: $loop_times of $max_loops)"
+    sleep 1
+done
+
+# Took too long!
+if [ $loop_times -eq $max_loops ]; then
+    echo "couldn't get lock after $max_loops seconds.  bailing out!"
+    exit 1
+fi
+
+touch /etc/fstab-lock
+
 if test "$1" = "add"; then
 
     if [ ! -d $MOUNTPOINT ]; then
@@ -66,7 +82,11 @@
 
 elif test "$1" = "remove"; then
     grep -v "$MOUNTPOINT" /etc/fstab > /etc/fstab-tmp
-    mv -f /etc/fstab-tmp /etc/fstab
+
+    # Make sure it's here
+    if [ -f /etc/fstab-tmp -a -s /etc/fstab-tmp ]; then
+	mv -f /etc/fstab-tmp /etc/fstab
+    fi
 
     if [ -d $MOUNTPOINT ]; then
 	rmdir $MOUNTPOINT
@@ -75,3 +95,5 @@
 else
     echo "invalid action!"
 fi
+
+rm /etc/fstab-lock
\ No newline at end of file





More information about the hal-commit mailing list