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

Skip to content

Commit f626b7b

Browse files
authored
gh-96055: Update faulthandler to emit proper unexpect signal number (gh-99162)
1 parent 57a4052 commit f626b7b

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

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

340341
for (i=0; i < faulthandler_nsignals; i++) {
341342
handler = &faulthandler_handlers[i];
342-
if (handler->signum == signum)
343+
if (handler->signum == signum) {
344+
found = 1;
343345
break;
346+
}
344347
}
345348
if (handler == NULL) {
346349
/* faulthandler_nsignals == 0 (unlikely) */
@@ -350,9 +353,18 @@ faulthandler_fatal_error(int signum)
350353
/* restore the previous handler */
351354
faulthandler_disable_fatal_handler(handler);
352355

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

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

0 commit comments

Comments
 (0)