[Ovirt-devel] [RFC][PATCH] ovirt-node-image : edit-livecd : fail on error in arbitrary code

David Huff dhuff at redhat.com
Wed Nov 11 21:46:33 UTC 2009


I took a look at this today, I am not sure that a requirement for 'CODE'
to touch a "fail" file is the best way to address this.

I assume your script is mounting proc inside the ext filesystem, ie to
use yum or something.  And using trap and a similar mnt function, like
what is in edit-livecd, is not cleaning up all the mounts in this case?

A fix may be to use /proc/mounts instead of df when adding the Exits in
the mnt function.

Also can you clarify the statement, "note that it may not always be
possible to return some error code on failure in 'CODE'" I am not really
sure what you mean here.

Does this make sense?

-D


On 11/10/2009 08:41 AM, abhishek misra wrote:
> 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
> 
> _______________________________________________
> Ovirt-devel mailing list
> Ovirt-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/ovirt-devel




More information about the ovirt-devel mailing list