diff mbox series

[v2,3/3] bitbake-setup: handle ctrl+c

Message ID 20251117-bitbake-setup-abort-v2-3-a73f44e83bc0@bootlin.com
State Accepted, archived
Commit b17c5db1141c112d3954553c89eca0412a3f7933
Headers show
Series bitbake-setup init improvements | expand

Commit Message

Antonin Godard Nov. 17, 2025, 8:15 a.m. UTC
Instead of printing the stack trace, print "Shutting down..." when the
user presses Ctrl+C during command executions. Mention that the
top-directory's setups might be incomplete if the topdir was already
created at this point.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 bin/bitbake-setup | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index db6428f8d2..d0a932a6b2 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -17,6 +17,8 @@  import glob
 import subprocess
 import copy
 import textwrap
+import signal
+import functools
 
 default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry")
 
@@ -783,6 +785,15 @@  def merge_settings(builtin_settings, global_settings, topdir_settings, cmdline_s
 
     return all_settings
 
+def sigint_handler(sig, frame, func, top_dir):
+    print(f'\nShutting down...')
+    if isinstance(top_dir, str) and os.path.exists(top_dir):
+        if func in [init_config, build_update]:
+            print(f'{top_dir} may contain an incomplete setup!')
+        elif func == install_buildtools:
+            print(f'{top_dir} may contain an incomplete buildtools installation!')
+    exit()
+
 def main():
     def add_setup_dir_arg(parser):
         setup_dir = get_setup_dir_via_bbpath()
@@ -888,6 +899,12 @@  def main():
         global_settings = load_settings(global_settings_path(args))
         top_dir = get_top_dir(args, merge_settings(builtin_settings, global_settings, {}, args.cmdline_settings))
 
+        # register handler now to pass top_dir
+        _handler = functools.partial(sigint_handler,
+                                     func=args.func,
+                                     top_dir=os.path.abspath(top_dir))
+        signal.signal(signal.SIGINT, _handler)
+
         # This cannot be set with the rest of the builtin settings as top_dir needs to be determined first
         builtin_settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads')