help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reset a trap upon use


From: Greg Wooledge
Subject: Re: reset a trap upon use
Date: Fri, 24 Nov 2023 12:22:50 -0500

On Fri, Nov 24, 2023 at 12:07:24PM -0500, bill-auger wrote:
> On Fri, 24 Nov 2023 11:25:05 -0500 Greg wrote:
> > Did you actually need anything more than a cleanup-on-exit function?
> 
> yes, (at least semantically, and for tidiness) it should cleanup immediately
> upon return from setup() normally, and also in case the program exits
> abnormally - setup() creates and loopback mounts an OS image file to partition
> and populate it - later, the program calls another script which boots the 
> image
> with QEMU - the boot script is intended to be run independently on an image
> created by the first script, and so it has similar loop mount and unmount
> functions - i could perhaps make it work as you are suggesting (by forking i
> suppose); but that would be messy magic spaghetti - ive spent too much time
> debugging this already - id prefer to have the image cleanly unmounted and
> de-looped before calling the boot script, as it expects when run manually

If I understand this correctly, wouldn't you just do:

#!/bin/bash

setup() {
    create the thing
    mount the thing
    populate the thing
}

cleanup() {
    unmount the thing if it's mounted
}

trap cleanup EXIT

setup
cleanup
call the boot script



reply via email to

[Prev in Thread] Current Thread [Next in Thread]