Skip to content

Commit 2bd05ad

Browse files
committed
corelens: gracefully handle interrupt and broken pipe
SIGINT and SIGPIPE are handled by Python as exceptions. It's common to get a SIGINT with a keyboard interrupt, and in these cases the user typically doesn't want a traceback, they just want to stop corelens. For broken pipe, this is relatively common for "corelens ... | head -n $num" commands where a user wants to get just the first few lines. An exception here would print more than they expect, and would be unhelpful. Handle both of these so corelens behaves more like other system utilities. Signed-off-by: Stephen Brennan <[email protected]>
1 parent 04347b8 commit 2bd05ad

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drgn_tools/corelens.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ def _run_module(
549549
if print_header:
550550
print(f"\n====== MODULE {mod.name} ======")
551551
mod.run(prog, args)
552+
except (KeyboardInterrupt, BrokenPipeError):
553+
raise
552554
except Exception:
553555
formatted = traceback.format_exc()
554556
errors.append(
@@ -791,4 +793,9 @@ def cl(cl_cmd: str) -> None:
791793
# terrible, terrible corner of Python.
792794
import drgn_tools.corelens
793795

794-
drgn_tools.corelens.main()
796+
try:
797+
drgn_tools.corelens.main()
798+
except KeyboardInterrupt:
799+
sys.exit("interrupted")
800+
except BrokenPipeError:
801+
pass

0 commit comments

Comments
 (0)