Purpose : fail iso build on encountering error in arbitrary code '$CODE'

1. export 'WDIR' , for 'CODE' to pick-up location to create 'fail' file to indicate failure, note that it may not always be possible to return some error code on failure in 'CODE'
2.    'set' commands enclosing 'CODE' will not be required
3. 'CODE' is expected to use 'set -e and trap signals like EXIT (which are generated when some command fails ) and write a 'fail' file
4.    look for 'fail' file once 'CODE'  has completed
if positive then unmount proc ( note that if 'CODE', proc still remains mounted; this is not unmounted by existing trap in edit-livecd script )
      rest of the cleanup is taken care off by existing trap statement

Signed-off-by: Abhishek Misra <[email protected]>

---

--- a/edit-livecd    2009-11-10 17:23:21.000000000 +0530
+++ b/edit-livecd    2009-11-10 18:39:11.000000000 +0530
@@ -159,13 +159,14 @@ cp -pr $WDIR/sq $WDIR/sq-w
# mount root filesystem
mnt "-t ext2 $WDIR/sq-w/LiveOS/ext3fs.img -o rw,loop" ex

+# exporting for tarp in 'CODE'
+# $CODE can 'trap' EXIT signal and touch '$WDIR/fail' to notify this script of its failure
+
echo ">>> Updating CD content"
if [ -n "$CODE" ]; then
    (
      cd $WDIR/ex
-      set +e
      eval "$CODE"
-      set -e
    )
else
    echo "***"
@@ -174,6 +175,14 @@ else
    read
fi

+# exit if $CODE failed. Look if '$WDIR/fail' exists
+if [ -a $WDIR/fail ] ; then
+    rm $WDIR/fail
+ # need to explictly look for proc as failure in $CODE leaves it mounted causing 'umount $WDIR/ex-rw' to fail
+    mount | grep livecd | grep proc && addExit "umount -v $WDIR/ex-rw/proc"
+    exit
+fi
+
# Try to unmount.  But this is likely to fail, so let the user retry,
# e.g., if he forgot to "cd" out of $WDIR/ex.
while :; do

_______________________________________________
Ovirt-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/ovirt-devel

Reply via email to