[Python-checkins] gh-96055: Update faulthandler to emit proper unexpect signal number (gh-99162)

miss-islington webhook-mailer at python.org
Sun Nov 6 21:46:29 EST 2022


https://github.com/python/cpython/commit/58c8c1dee798d394344b5b56e890a2cff1c41082
commit: 58c8c1dee798d394344b5b56e890a2cff1c41082
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-11-06T18:45:54-08:00
summary:

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

(cherry picked from commit f626b7b504df454d289527a4f922b09deeae9e21)

Co-authored-by: Dong-hee Na <donghee.na at python.org>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-11-06-22-59-02.gh-issue-96055.TmQuJn.rst
M Modules/faulthandler.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-11-06-22-59-02.gh-issue-96055.TmQuJn.rst b/Misc/NEWS.d/next/Core and Builtins/2022-11-06-22-59-02.gh-issue-96055.TmQuJn.rst
new file mode 100644
index 000000000000..c72fb21942e6
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-11-06-22-59-02.gh-issue-96055.TmQuJn.rst	
@@ -0,0 +1,2 @@
+Update :mod:`faulthandler` to emit an error message with the proper
+unexpected signal number. Patch by Dong-hee Na.
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 4847c1cb87bc..04995d2e7457 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -334,14 +334,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) */
@@ -351,9 +354,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);



More information about the Python-checkins mailing list