[master] 07e5adfeb vas: Print a back-trace by default
Nils Goroll
nils.goroll at uplex.de
Mon May 19 13:21:05 UTC 2025
commit 07e5adfebdca301d57f73d565fa58fcd5be73a24
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date: Wed Jun 5 16:12:38 2024 +0200
vas: Print a back-trace by default
Signed-off-by: Asad Sajjad Ahmed <asadsa at varnish-software.com>
diff --git a/lib/libvarnish/vas.c b/lib/libvarnish/vas.c
index b64418cc9..bee30f5b7 100644
--- a/lib/libvarnish/vas.c
+++ b/lib/libvarnish/vas.c
@@ -36,8 +36,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include "vdef.h"
+#include "vbt.h"
#include "vas.h"
@@ -57,37 +59,53 @@ VAS_errtxt(int e)
vas_f *VAS_Fail_Func v_noreturn_;
-void v_noreturn_
-VAS_Fail(const char *func, const char *file, int line,
+static void
+vas_default(const char *func, const char *file, int line,
const char *cond, enum vas_e kind)
{
int err = errno;
+ char buf[4096];
- if (VAS_Fail_Func != NULL) {
- VAS_Fail_Func(func, file, line, cond, kind);
+ if (kind == VAS_MISSING) {
+ fprintf(stderr,
+ "Missing error handling code in %s(), %s line %d:\n"
+ " Condition(%s) not true.\n",
+ func, file, line, cond);
+ } else if (kind == VAS_INCOMPLETE) {
+ fprintf(stderr,
+ "Incomplete code in %s(), %s line %d:\n",
+ func, file, line);
+ } else if (kind == VAS_WRONG) {
+ fprintf(stderr,
+ "Wrong turn in %s(), %s line %d: %s\n",
+ func, file, line, cond);
} else {
- if (kind == VAS_MISSING) {
- fprintf(stderr,
- "Missing error handling code in %s(), %s line %d:\n"
- " Condition(%s) not true.\n",
- func, file, line, cond);
- } else if (kind == VAS_INCOMPLETE) {
- fprintf(stderr,
- "Incomplete code in %s(), %s line %d:\n",
- func, file, line);
- } else if (kind == VAS_WRONG) {
- fprintf(stderr,
- "Wrong turn in %s(), %s line %d: %s\n",
- func, file, line, cond);
- } else {
- fprintf(stderr,
- "Assert error in %s(), %s line %d:\n"
- " Condition(%s) not true.\n",
- func, file, line, cond);
- }
- if (err)
- fprintf(stderr,
- " errno = %d (%s)\n", err, strerror(err));
+ fprintf(stderr,
+ "Assert error in %s(), %s line %d:\n"
+ " Condition(%s) not true.\n",
+ func, file, line, cond);
+ }
+ if (err) {
+ fprintf(stderr,
+ " errno = %d (%s)\n", err, strerror(err));
}
+
+ if (VBT_dump(sizeof buf, buf) < 0) {
+ bprintf(buf, "Failed to print backtrace: %d (%s)",
+ errno, strerror(errno));
+ }
+
+ syslog(LOG_DEBUG, "%s", buf);
+}
+
+void v_noreturn_
+VAS_Fail(const char *func, const char *file, int line,
+ const char *cond, enum vas_e kind)
+{
+
+ if (VAS_Fail_Func != NULL)
+ VAS_Fail_Func(func, file, line, cond, kind);
+ else
+ vas_default(func, file, line, cond, kind);
abort();
}
More information about the varnish-commit
mailing list