]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: implement ha_panic()
authorWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 11:48:29 +0000 (13:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 14:51:30 +0000 (16:51 +0200)
This function dumps all existing threads using the thread dump mechanism
then aborts. This will be used by the lockup detection and by debugging
tools.

include/common/debug.h
src/debug.c

index 4f3baedb791ea49e85330aa90fc77bbe76908ad7..1038041b1ed19d518a3225b623065d885c6a4b72 100644 (file)
@@ -87,6 +87,7 @@ struct buffer;
 void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx);
 void ha_thread_dump(struct buffer *buf, int thr, int calling_tid);
 void ha_thread_dump_all_to_trash();
+void ha_panic();
 
 /* This one is useful to automatically apply poisonning on an area returned
  * by malloc(). Only "p_" is required to make it work, and to define a poison
index fce23c389b87d8294e632184cb5afbc0cce464be..3e38bfa6c225aad79000b1220b79b994e18a2671 100644 (file)
@@ -136,6 +136,17 @@ static int cli_io_handler_show_threads(struct appctx *appctx)
        return 1;
 }
 
+/* dumps a state of all threads into the trash and on fd #2, then aborts. */
+void ha_panic()
+{
+       chunk_reset(&trash);
+       chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid);
+       ha_thread_dump_all_to_trash();
+       write(2, trash.area, trash.data);
+       for (;;)
+               abort();
+}
+
 #ifndef USE_THREAD_DUMP
 
 /* This function dumps all threads' state to the trash. This version is the