gh-96055: Update faulthandler to emit proper unexpect signal number (gh-99162)

(cherry picked from commit f626b7b504)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
This commit is contained in:
Miss Islington (bot) 2022-11-06 22:05:20 -08:00 committed by GitHub
parent 0d5b25bd87
commit 1b5a62b88a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -0,0 +1,2 @@
Update :mod:`faulthandler` to emit an error message with the proper
unexpected signal number. Patch by Dong-hee Na.

View file

@ -349,14 +349,17 @@ faulthandler_fatal_error(int signum)
size_t i;
fault_handler_t *handler = NULL;
int save_errno = errno;
int found = 0;
if (!fatal_error.enabled)
return;
for (i=0; i < faulthandler_nsignals; i++) {
handler = &faulthandler_handlers[i];
if (handler->signum == signum)
if (handler->signum == signum) {
found = 1;
break;
}
}
if (handler == NULL) {
/* faulthandler_nsignals == 0 (unlikely) */
@ -366,9 +369,18 @@ faulthandler_fatal_error(int signum)
/* restore the previous handler */
faulthandler_disable_fatal_handler(handler);
PUTS(fd, "Fatal Python error: ");
PUTS(fd, handler->name);
PUTS(fd, "\n\n");
if (found) {
PUTS(fd, "Fatal Python error: ");
PUTS(fd, handler->name);
PUTS(fd, "\n\n");
}
else {
char unknown_signum[23] = {0,};
snprintf(unknown_signum, 23, "%d", signum);
PUTS(fd, "Fatal Python error from unexpected signum: ");
PUTS(fd, unknown_signum);
PUTS(fd, "\n\n");
}
faulthandler_dump_traceback(fd, fatal_error.all_threads,
fatal_error.interp);