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

Skip to content

Commit 879d827

Browse files
corona10miss-islington
authored andcommitted
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 c4408d3 commit 879d827

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
@@ -334,14 +334,17 @@ faulthandler_fatal_error(int signum)
334334
size_t i;
335335
fault_handler_t *handler = NULL;
336336
int save_errno = errno;
337+
int found = 0;
337338

338339
if (!fatal_error.enabled)
339340
return;
340341

341342
for (i=0; i < faulthandler_nsignals; i++) {
342343
handler = &faulthandler_handlers[i];
343-
if (handler->signum == signum)
344+
if (handler->signum == signum) {
345+
found = 1;
344346
break;
347+
}
345348
}
346349
if (handler == NULL) {
347350
/* faulthandler_nsignals == 0 (unlikely) */
@@ -351,9 +354,18 @@ faulthandler_fatal_error(int signum)
351354
/* restore the previous handler */
352355
faulthandler_disable_fatal_handler(handler);
353356

354-
PUTS(fd, "Fatal Python error: ");
355-
PUTS(fd, handler->name);
356-
PUTS(fd, "\n\n");
357+
if (found) {
358+
PUTS(fd, "Fatal Python error: ");
359+
PUTS(fd, handler->name);
360+
PUTS(fd, "\n\n");
361+
}
362+
else {
363+
char unknown_signum[23] = {0,};
364+
snprintf(unknown_signum, 23, "%d", signum);
365+
PUTS(fd, "Fatal Python error from unexpected signum: ");
366+
PUTS(fd, unknown_signum);
367+
PUTS(fd, "\n\n");
368+
}
357369

358370
faulthandler_dump_traceback(fd, fatal_error.all_threads,
359371
fatal_error.interp);

0 commit comments

Comments
 (0)