[Ovirt-devel] [RFC][PATCH] ovirt-node-image : edit-livecd : fail on error in arbitrary code
abhishek misra
fishy at linux.vnet.ibm.com
Tue Nov 10 13:41:38 UTC 2009
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 <fishy at linux.vnet.ibm.com>
---
--- 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
More information about the ovirt-devel
mailing list