[master] f597b86 Drop libvarnishcompat
Federico G. Schwindt
fgsch at lodoss.net
Sat Jan 7 22:42:04 CET 2017
commit f597b86d73ca67f80b5ca9e86dac399111858963
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Sat Jan 7 21:29:16 2017 +0000
Drop libvarnishcompat
Move its remainings to libvarnishapi and include them conditionally.
diff --git a/bin/varnishadm/Makefile.am b/bin/varnishadm/Makefile.am
index 0ecc3e6..d0ca154 100644
--- a/bin/varnishadm/Makefile.am
+++ b/bin/varnishadm/Makefile.am
@@ -14,6 +14,5 @@ varnishadm_CFLAGS = @LIBEDIT_CFLAGS@ \
varnishadm_LDADD = \
$(top_builddir)/lib/libvarnish/libvarnish.a \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
${PTHREAD_LIBS} ${RT_LIBS} ${NET_LIBS} @LIBEDIT_LIBS@ ${LIBM} \
@SAN_LDFLAGS@
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 7ab414a..9203a50 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -151,7 +151,6 @@ varnishd_LDFLAGS = -export-dynamic
varnishd_LDADD = \
$(top_builddir)/lib/libvarnish/libvarnish.a \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvcc/libvcc.a \
$(top_builddir)/lib/libvgz/libvgz.a \
@SAN_LDFLAGS@ \
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index eb10008..8b6ad6d 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -29,12 +29,7 @@
#include "config.h"
-#ifndef HAVE_EXECINFO_H
-#include "compat/execinfo.h"
-#else
#include <execinfo.h>
-#endif
-
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
diff --git a/bin/varnishd/flint.sh b/bin/varnishd/flint.sh
index ba15504..50d1c4b 100755
--- a/bin/varnishd/flint.sh
+++ b/bin/varnishd/flint.sh
@@ -29,7 +29,6 @@ flexelint \
storage/*.c \
waiter/*.c \
../../lib/libvarnish/*.c \
- ../../lib/libvarnishcompat/execinfo.c \
../../lib/libvcc/*.c \
../../lib/libvmod_std/*.c \
../../lib/libvmod_debug/*.c \
diff --git a/bin/varnishhist/Makefile.am b/bin/varnishhist/Makefile.am
index e01374b..281c05a 100644
--- a/bin/varnishhist/Makefile.am
+++ b/bin/varnishhist/Makefile.am
@@ -15,7 +15,6 @@ varnishhist_CFLAGS = \
@SAN_CFLAGS@
varnishhist_LDADD = \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
-lm \
@SAN_LDFLAGS@ \
diff --git a/bin/varnishlog/Makefile.am b/bin/varnishlog/Makefile.am
index 9e309e7..28d5e67 100644
--- a/bin/varnishlog/Makefile.am
+++ b/bin/varnishlog/Makefile.am
@@ -15,7 +15,6 @@ varnishlog_CFLAGS = \
@SAN_CFLAGS@
varnishlog_LDADD = \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
@SAN_LDFLAGS@ \
${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am
index a6cbeb7..b970910 100644
--- a/bin/varnishncsa/Makefile.am
+++ b/bin/varnishncsa/Makefile.am
@@ -17,7 +17,6 @@ varnishncsa_CFLAGS = \
@SAN_CFLAGS@
varnishncsa_LDADD = \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
@SAN_LDFLAGS@ \
${RT_LIBS} ${LIBM}
diff --git a/bin/varnishstat/Makefile.am b/bin/varnishstat/Makefile.am
index 82303fa..34c7d41 100644
--- a/bin/varnishstat/Makefile.am
+++ b/bin/varnishstat/Makefile.am
@@ -17,7 +17,6 @@ varnishstat_CFLAGS = \
@SAN_CFLAGS@
varnishstat_LDADD = \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
@SAN_LDFLAGS@ \
@CURSES_LIB@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
diff --git a/bin/varnishtest/Makefile.am b/bin/varnishtest/Makefile.am
index 2149ed4..636edd4 100644
--- a/bin/varnishtest/Makefile.am
+++ b/bin/varnishtest/Makefile.am
@@ -51,7 +51,6 @@ varnishtest_SOURCES = \
varnishtest_LDADD = \
$(top_builddir)/lib/libvarnish/libvarnish.a \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
$(top_builddir)/lib/libvgz/libvgz.a \
@SAN_LDFLAGS@ \
diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am
index fdd993a..68adae8 100644
--- a/bin/varnishtop/Makefile.am
+++ b/bin/varnishtop/Makefile.am
@@ -15,7 +15,6 @@ varnishtop_CFLAGS = \
@SAN_CFLAGS@
varnishtop_LDADD = \
- $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
@SAN_LDFLAGS@ \
@CURSES_LIB@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
diff --git a/configure.ac b/configure.ac
index 27cf34e..af57936 100644
--- a/configure.ac
+++ b/configure.ac
@@ -190,7 +190,6 @@ AC_CHECK_HEADERS([sys/personality.h])
AC_CHECK_HEADERS([sys/statvfs.h])
AC_CHECK_HEADERS([sys/vfs.h])
AC_CHECK_HEADERS([endian.h])
-AC_CHECK_HEADERS([execinfo.h])
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
AC_CHECK_HEADERS([priv.h])
@@ -284,10 +283,10 @@ case $target in
esac
AC_SUBST(JEMALLOC_LDADD)
-# These functions are provided by libcompat on platforms where they
-# are not available
AC_CHECK_FUNCS([setproctitle])
-AC_SEARCH_LIBS(backtrace, [execinfo],[AC_DEFINE([HAVE_BACKTRACE],[1],[Define to 1 if the backtrace function exists])])
+AC_SEARCH_LIBS(backtrace, [execinfo], [], [
+ AC_MSG_ERROR([Could not find backtrace() support])
+])
# white lie - we don't actually test it
AC_MSG_CHECKING([whether daemon() works])
case $target in
@@ -300,6 +299,7 @@ case $target in
AC_CHECK_FUNCS([daemon])
;;
esac
+AM_CONDITIONAL(HAVE_DAEMON, [test "x$HAVE_DAEMON" != "xno"])
AC_SYS_LARGEFILE
@@ -699,7 +699,6 @@ AC_CONFIG_FILES([
lib/Makefile
lib/libvarnish/Makefile
lib/libvarnishapi/Makefile
- lib/libvarnishcompat/Makefile
lib/libvcc/Makefile
lib/libvgz/Makefile
lib/libvmod_debug/Makefile
diff --git a/include/Makefile.am b/include/Makefile.am
index 0bf9cec..34ca265 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -79,7 +79,6 @@ nobase_pkginclude_HEADERS += \
nobase_noinst_HEADERS = \
binary_heap.h \
compat/daemon.h \
- compat/execinfo.h \
vfl.h \
libvcc.h \
vcli_serve.h \
diff --git a/include/compat/execinfo.h b/include/compat/execinfo.h
deleted file mode 100644
index 7b3b2e3..0000000
--- a/include/compat/execinfo.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2003 Maxim Sobolev <sobomax at FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#ifndef COMPAT_EXECINFO_H_INCLUDED
-#define COMPAT_EXECINFO_H_INCLUDED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int backtrace(void **, int);
-char ** backtrace_symbols(void *const *, int);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* COMPAT_EXECINFO_H_INCLUDED */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 579cebd..871cbaf 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,7 +1,6 @@
#
SUBDIRS = \
- libvarnishcompat \
libvarnish \
libvarnishapi \
libvcc \
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index f33fbe2..769e658 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -44,6 +44,10 @@ libvarnishapi_la_SOURCES = \
vxp_fixed_token.c \
libvarnishapi.map
+if ! HAVE_DAEMON
+libvarnishapi_la_SOURCES += daemon.c
+endif
+
libvarnishapi_la_CFLAGS = \
-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
@SAN_CFLAGS@
diff --git a/lib/libvarnishapi/daemon.c b/lib/libvarnishapi/daemon.c
new file mode 100644
index 0000000..e68b3a1
--- /dev/null
+++ b/lib/libvarnishapi/daemon.c
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * Derived from:
+ * $FreeBSD: src/lib/libc/gen/daemon.c,v 1.8 2007/01/09 00:27:53 imp Exp $
+ */
+
+//lint -e{766}
+#include "config.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "compat/daemon.h"
+
+int
+varnish_daemon(int nochdir, int noclose)
+{
+ struct sigaction osa, sa;
+ int fd;
+ pid_t newgrp;
+ int oerrno;
+ int osa_ok;
+
+ /* A SIGHUP may be thrown when the parent exits below. */
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = 0;
+ osa_ok = sigaction(SIGHUP, &sa, &osa);
+
+ switch (fork()) {
+ case -1:
+ return (-1);
+ case 0:
+ break;
+ default:
+ /*
+ * A fine point: _exit(0), not exit(0), to avoid triggering
+ * atexit(3) processing
+ */
+ _exit(0);
+ }
+
+ newgrp = setsid();
+ oerrno = errno;
+ if (osa_ok != -1)
+ sigaction(SIGHUP, &osa, NULL);
+
+ if (newgrp == -1) {
+ errno = oerrno;
+ return (-1);
+ }
+
+ if (!nochdir)
+ (void)chdir("/");
+
+ if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
+ (void)dup2(fd, STDIN_FILENO);
+ (void)dup2(fd, STDOUT_FILENO);
+ (void)dup2(fd, STDERR_FILENO);
+ if (fd > 2)
+ (void)close(fd);
+ }
+ return (0);
+}
diff --git a/lib/libvarnishcompat/Makefile.am b/lib/libvarnishcompat/Makefile.am
deleted file mode 100644
index f2c878b..0000000
--- a/lib/libvarnishcompat/Makefile.am
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-
-AM_CPPFLAGS = \
- -I$(top_srcdir)/include \
- -I$(top_builddir)/include
-
-AM_LDFLAGS = $(AM_LT_LDFLAGS)
-
-pkglib_LTLIBRARIES = libvarnishcompat.la
-
-libvarnishcompat_la_CFLAGS = \
- @SAN_CFLAGS@
-
-libvarnishcompat_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version \
- @SAN_LDFLAGS@
-
-libvarnishcompat_la_SOURCES = \
- daemon.c \
- execinfo.c
diff --git a/lib/libvarnishcompat/daemon.c b/lib/libvarnishcompat/daemon.c
deleted file mode 100644
index 3ab6b7d..0000000
--- a/lib/libvarnishcompat/daemon.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * Derived from:
- * $FreeBSD: src/lib/libc/gen/daemon.c,v 1.8 2007/01/09 00:27:53 imp Exp $
- */
-
-//lint -e{766}
-#include "config.h"
-
-#ifndef HAVE_DAEMON
-
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "compat/daemon.h"
-
-int
-varnish_daemon(int nochdir, int noclose)
-{
- struct sigaction osa, sa;
- int fd;
- pid_t newgrp;
- int oerrno;
- int osa_ok;
-
- /* A SIGHUP may be thrown when the parent exits below. */
- sigemptyset(&sa.sa_mask);
- sa.sa_handler = SIG_IGN;
- sa.sa_flags = 0;
- osa_ok = sigaction(SIGHUP, &sa, &osa);
-
- switch (fork()) {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- /*
- * A fine point: _exit(0), not exit(0), to avoid triggering
- * atexit(3) processing
- */
- _exit(0);
- }
-
- newgrp = setsid();
- oerrno = errno;
- if (osa_ok != -1)
- sigaction(SIGHUP, &osa, NULL);
-
- if (newgrp == -1) {
- errno = oerrno;
- return (-1);
- }
-
- if (!nochdir)
- (void)chdir("/");
-
- if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
- (void)dup2(fd, STDIN_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd > 2)
- (void)close(fd);
- }
- return (0);
-}
-
-#endif
diff --git a/lib/libvarnishcompat/execinfo.c b/lib/libvarnishcompat/execinfo.c
deleted file mode 100644
index 17321b7..0000000
--- a/lib/libvarnishcompat/execinfo.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2003 Maxim Sobolev <sobomax at FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-//lint -e{766}
-#include "config.h"
-
-#ifndef HAVE_BACKTRACE
-
-#include "compat/execinfo.h"
-
-#if defined (__GNUC__) && __GNUC__ >= 4 /* XXX Correct version to check for ? */
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <dlfcn.h>
-#include <math.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static void *getreturnaddr(int);
-static void *getframeaddr(int);
-
-int
-backtrace(void **buffer, int size)
-{
- int i;
-
- for (i = 1; getframeaddr(i + 1) != NULL && i != size + 1; i++) {
- buffer[i - 1] = getreturnaddr(i);
- if (buffer[i - 1] == NULL)
- break;
- }
- return (i - 1);
-}
-
-/*
- * XXX: This implementation should be changed to a much more conservative
- * XXX: memory strategy: Allocate 4k up front, realloc 4K more as needed.
- */
-
-char **
-backtrace_symbols(void *const *buffer, int size)
-{
- size_t clen, alen;
- int i;
- char **rval;
-
- clen = size * sizeof(char *);
- rval = malloc(clen);
- if (rval == NULL)
- return (NULL);
- for (i = 0; i < size; i++) {
-
-#ifdef HAVE_DLADDR
- {
- Dl_info info;
- int offset;
-
- if (dladdr(buffer[i], &info) != 0) {
- if (info.dli_sname == NULL)
- info.dli_sname = "?";
- if (info.dli_saddr == NULL)
- info.dli_saddr = buffer[i];
- offset = (const char*)buffer[i] -
- (const char*)info.dli_saddr;
- /* "0x01234567 <function+offset> at filename" */
- alen = 2 + /* "0x" */
- (sizeof(void *) * 2) + /* "01234567" */
- 2 + /* " <" */
- strlen(info.dli_sname) + /* "function" */
- 1 + /* "+" */
- 10 + /* "offset */
- 5 + /* "> at " */
- strlen(info.dli_fname) + /* "filename" */
- 1; /* "\0" */
- rval = realloc(rval, clen + alen);
- if (rval == NULL)
- return NULL;
- (void)snprintf((char *) rval + clen, alen,
- "%p <%s+%d> at %s", buffer[i], info.dli_sname,
- offset, info.dli_fname);
- rval[i] = (char *) clen;
- clen += alen;
- continue;
- }
- }
-#endif
- alen = 2 + /* "0x" */
- (sizeof(void *) * 2) + /* "01234567" */
- 1; /* "\0" */
- rval = realloc(rval, clen + alen);
- if (rval == NULL)
- return NULL;
- (void)snprintf((char *) rval + clen, alen, "%p", buffer[i]);
- rval[i] = (char *) clen;
- clen += alen;
- }
-
- for (i = 0; i < size; i++)
- rval[i] += (long) rval;
- return (rval);
-}
-
-/* Binary expansion */
-#define DO_P2_TIMES_1(x) DO_P2_TIMES_0(x); DO_P2_TIMES_0((x) + (1<<0))
-#define DO_P2_TIMES_2(x) DO_P2_TIMES_1(x); DO_P2_TIMES_1((x) + (1<<1))
-#define DO_P2_TIMES_3(x) DO_P2_TIMES_2(x); DO_P2_TIMES_2((x) + (1<<2))
-#define DO_P2_TIMES_4(x) DO_P2_TIMES_3(x); DO_P2_TIMES_3((x) + (1<<3))
-#define DO_P2_TIMES_5(x) DO_P2_TIMES_4(x); DO_P2_TIMES_4((x) + (1<<4))
-#define DO_P2_TIMES_6(x) DO_P2_TIMES_5(x); DO_P2_TIMES_5((x) + (1<<5))
-#define DO_P2_TIMES_7(x) DO_P2_TIMES_6(x); DO_P2_TIMES_6((x) + (1<<6))
-
-static void *
-getreturnaddr(int level)
-{
-
- switch(level) {
-#define DO_P2_TIMES_0(x) case (x): return __builtin_return_address((x) + 1)
- DO_P2_TIMES_7(0);
-#undef DO_P2_TIMES_0
- default: return NULL;
- }
-}
-
-static void *
-getframeaddr(int level)
-{
-
- switch(level) {
-#define DO_P2_TIMES_0(x) case (x): return __builtin_frame_address((x) + 1)
- DO_P2_TIMES_7(0);
-#undef DO_P2_TIMES_0
- default: return NULL;
- }
-}
-
-#else
-
-int
-backtrace(void **buffer, int size)
-{
- (void)buffer;
- (void)size;
- return (0);
-}
-
-char **
-backtrace_symbols(void *const *buffer, int size)
-{
- (void)buffer;
- (void)size;
- return (0);
-}
-
-#endif /* (__GNUC__) && __GNUC__ >= 4 */
-#endif /* HAVE_BACKTRACE */
More information about the varnish-commit
mailing list