cros_generate_update_payload: Fix up error handling/cleanup code.

Stop using set -e, detect cleanup from signals explicitly instead of counting
on there being no arguments when called automatically. Expand the scope of
signal catching to include most of the script. Let the "EXIT" signal trigger
cleanup instead of calling it explicitly.

This may help with leaked loopback devices per 393761, although I haven't
specifically identified where the devices were leaking from.

BUG=chromium:393761
TEST=Ran paygen_payload and saw it complete successfully. Preserved its temp
directory and ran cros_generate_update_payload manually. Interrupted it with
Ctrl+C, and injected faults in various places and combinations. Made sure the
output was appropriate and that resources were cleaned up properly.

Change-Id: Ie133d8f1d2610ea05eb85ae0b185469a69efe242
Reviewed-on: https://chromium-review.googlesource.com/223127
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
1 file changed