Skip to content

Commit

Permalink
feat: set signal name during crash collection
Browse files Browse the repository at this point in the history
Signal numbers vary by architecture. So include the signal name during
crash collection to avoid getting the wrong name when reprocessing on a
different architecture.

Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
  • Loading branch information
bdrung authored and schopin-pro committed Oct 31, 2023
1 parent e99a1d2 commit c143c7c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apport/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,9 @@ def _get_ignore_dom():

def _get_signal_name(self) -> str:
signal_number = int(self["Signal"])
signal_name = self.get("SignalName")
if signal_name:
return signal_name
try:
return signal.Signals(signal_number).name
except ValueError:
Expand Down
8 changes: 7 additions & 1 deletion data/apport
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,12 @@ def process_crash(options: argparse.Namespace) -> int:
return 1


def _set_signal(report: apport.report.Report, signal_number: int) -> None:
report["Signal"] = str(signal_number)
with contextlib.suppress(ValueError):
report["SignalName"] = signal.Signals(signal_number).name


def process_crash_with_proc_pid(options: argparse.Namespace, proc_pid: ProcPid) -> int:
# TODO: Split into smaller functions/methods
# pylint: disable=too-many-branches,too-many-locals
Expand Down Expand Up @@ -939,7 +945,7 @@ def process_crash_with_proc_pid(options: argparse.Namespace, proc_pid: ProcPid)
return 0

info = apport.report.Report("Crash")
info["Signal"] = str(options.signal_number)
_set_signal(info, options.signal_number)
core_size_limit = usable_ram() * 3 / 4
# sys.stdin has type io.TextIOWrapper, not the claimed io.TextIO.
# See https://github.com/python/typeshed/issues/10093
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_standard_title(self):

# named signal crash
report["Signal"] = "11"
report["SignalName"] = "SIGSEGV"
report["ExecutablePath"] = "/bin/bash"
report["StacktraceTop"] = textwrap.dedent(
"""\
Expand All @@ -82,6 +83,7 @@ def test_standard_title(self):

# unnamed signal crash
report["Signal"] = "42"
del report["SignalName"]
self.assertEqual(
report.standard_title(), "bash crashed with signal 42 in foo()"
)
Expand All @@ -102,6 +104,7 @@ def test_standard_title(self):

# assertion message
report["Signal"] = "6"
report["SignalName"] = "SIGABRT"
report["ExecutablePath"] = "/bin/bash"
report["AssertionMessage"] = "foo.c:42 main: i > 0"
self.assertEqual(
Expand Down Expand Up @@ -240,6 +243,7 @@ def test_standard_title(self):

# matching package/system architectures
report["Signal"] = "11"
report["SignalName"] = "SIGSEGV"
report["ExecutablePath"] = "/bin/bash"
report["StacktraceTop"] = textwrap.dedent(
"""\
Expand Down Expand Up @@ -597,6 +601,7 @@ def test_gen_stacktrace_top(self):
def test_gdb_add_info_no_gdb(self):
r = apport.report.Report()
r["Signal"] = "6"
r["SignalName"] = "SIGABRT"
r["ExecutablePath"] = "/bin/bash"
r["CoreDump"] = "/var/lib/apport/coredump/core.bash"
r["AssertionMessage"] = "foo.c:42 main: i > 0"
Expand Down Expand Up @@ -769,6 +774,7 @@ def test_crash_signature(self):
# assertion failures
r = apport.report.Report()
r["Signal"] = "6"
r["SignalName"] = "SIGABRT"
r["ExecutablePath"] = "/bin/bash"
r["AssertionMessage"] = "foo.c:42 main: i > 0"
self.assertEqual(r.crash_signature(), "/bin/bash:foo.c:42 main: i > 0")
Expand Down

0 comments on commit c143c7c

Please sign in to comment.