Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b5a62b

Browse files
gh-96055: Update faulthandler to emit proper unexpect signal number (gh-99162)
(cherry picked from commit f626b7b) Co-authored-by: Dong-hee Na <[email protected]>
1 parent 0d5b25b commit 1b5a62b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update :mod:`faulthandler` to emit an error message with the proper
2+
unexpected signal number. Patch by Dong-hee Na.

Modules/faulthandler.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,17 @@ faulthandler_fatal_error(int signum)
349349
size_t i;
350350
fault_handler_t *handler = NULL;
351351
int save_errno = errno;
352+
int found = 0;
352353

353354
if (!fatal_error.enabled)
354355
return;
355356

356357
for (i=0; i < faulthandler_nsignals; i++) {
357358
handler = &faulthandler_handlers[i];
358-
if (handler->signum == signum)
359+
if (handler->signum == signum) {
360+
found = 1;
359361
break;
362+
}
360363
}
361364
if (handler == NULL) {
362365
/* faulthandler_nsignals == 0 (unlikely) */
@@ -366,9 +369,18 @@ faulthandler_fatal_error(int signum)
366369
/* restore the previous handler */
367370
faulthandler_disable_fatal_handler(handler);
368371

369-
PUTS(fd, "Fatal Python error: ");
370-
PUTS(fd, handler->name);
371-
PUTS(fd, "\n\n");
372+
if (found) {
373+
PUTS(fd, "Fatal Python error: ");
374+
PUTS(fd, handler->name);
375+
PUTS(fd, "\n\n");
376+
}
377+
else {
378+
char unknown_signum[23] = {0,};
379+
snprintf(unknown_signum, 23, "%d", signum);
380+
PUTS(fd, "Fatal Python error from unexpected signum: ");
381+
PUTS(fd, unknown_signum);
382+
PUTS(fd, "\n\n");
383+
}
372384

373385
faulthandler_dump_traceback(fd, fatal_error.all_threads,
374386
fatal_error.interp);

0 commit comments

Comments
 (0)