cros_sdk: simplify exit status handling
The big comment block here about exit behavior with interactive mode
doesn't make much sense as it's currently written. That's because it
was for code that used to print an error message before exiting. But
when that logic changed to not print a message, the comment block was
left in place. Since we want to keep the behavior of passing the exit
code back up, let's simplify by deleting the comment and just passing
the exit status back all the time.
This means now we pass the non-zero exit status back when in interactive
mode, but as the stale comment explains, that situation shouldn't really
matter that much.
This also means the decision to exit or return a value is left to the
main loop rather than this helper function. That makes more sense, and
will help in follow up commits where we move these into libraries.
BUG=b:191307774
TEST=`cros_sdk` still works
Change-Id: I619ddf65fb10e17df570bffbac5661fbe361a0d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3252647
Reviewed-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 286354d..440f7f5 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -206,14 +206,7 @@
logging.notice(
'Raising vm.max_map_count from %s to %s', max_map_count, file_limit)
open('/proc/sys/vm/max_map_count', 'w').write(f'{file_limit}\n')
- ret = cros_build_lib.dbg_run(cmd, check=False)
- # If we were in interactive mode, ignore the exit code; it'll be whatever
- # they last ran w/in the chroot and won't matter to us one way or another.
- # Note this does allow chroot entrance to fail and be ignored during
- # interactive; this is however a rare case and the user will immediately
- # see it (nor will they be checking the exit code manually).
- if ret.returncode != 0 and additional_args:
- raise SystemExit(ret.returncode)
+ return cros_build_lib.dbg_run(cmd, check=False)
def _ImageFileForChroot(chroot):
@@ -1177,7 +1170,8 @@
lock.read_lock()
if not mounted:
cros_sdk_lib.MountChrootPaths(options.chroot)
- EnterChroot(options.chroot, options.cache_dir, options.chrome_root,
- options.chrome_root_mount, options.goma_dir,
- options.goma_client_json, options.working_dir,
- chroot_command)
+ ret = EnterChroot(options.chroot, options.cache_dir, options.chrome_root,
+ options.chrome_root_mount, options.goma_dir,
+ options.goma_client_json, options.working_dir,
+ chroot_command)
+ sys.exit(ret.returncode)