YAZ_DOC
dnl
dnl
-AC_CHECK_HEADERS([dirent.h fnmatch.h wchar.h locale.h langinfo.h pwd.h unistd.h sys/select.h sys/socket.h sys/stat.h sys/time.h sys/times.h sys/types.h sys/un.h sys/wait.h sys/prctl.h netdb.h arpa/inet.h netinet/tcp.h netinet/in_systm.h],[],[],[])
+AC_CHECK_HEADERS([dirent.h fnmatch.h wchar.h locale.h langinfo.h pwd.h unistd.h sys/select.h sys/socket.h sys/stat.h sys/time.h sys/times.h sys/types.h sys/un.h sys/wait.h sys/prctl.h netdb.h arpa/inet.h netinet/tcp.h netinet/in_systm.h execinfo.h],[],[],[])
AC_CHECK_HEADERS([net/if.h netinet/in.h netinet/if_ether.h],[],[],[
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
noinst_HEADERS = icu_I18N.h
-pkginclude_HEADERS= backend.h base64.h \
+pkginclude_HEADERS= backend.h backtrace.h base64.h \
ccl.h ccl_xml.h cookie.h cql.h rpn2cql.h rpn2solr.h \
solr.h comstack.h \
diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) Index Data.
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Index Data 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 AND 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.
+ */
+
+/**
+ * \file
+ * \brief backtrace handling
+ */
+#ifndef YAZ_BACKTRACE_H
+#define YAZ_BACKTRACE_H
+
+#include <stddef.h>
+#include <yaz/yconfig.h>
+
+YAZ_BEGIN_CDECL
+
+/** \brief enables backtrace when bad signal is received (never returns)
+*/
+
+YAZ_EXPORT void yaz_enable_panic_backtrace(void);
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
iconv_encode_marc8.c iconv_encode_iso_8859_1.c iconv_encode_wchar.c \
iconv_decode_marc8.c iconv_decode_iso5426.c iconv_decode_danmarc.c sc.c \
json.c xml_include.c file_glob.c dirent.c mutex-p.h mutex.c condvar.c \
- thread_id.c gettimeofday.c thread_create.c spipe.c url.c
+ thread_id.c gettimeofday.c thread_create.c spipe.c url.c backtrace.c
libyaz_la_LDFLAGS=-version-info $(YAZ_VERSION_INFO)
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) Index Data
+ * See the file LICENSE for details.
+ */
+
+/**
+ * \file
+ * \brief get information for abnormal termianted, crashes, etc
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdlib.h>
+#if HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+#include <yaz/log.h>
+#include <yaz/snprintf.h>
+#include <yaz/backtrace.h>
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_EXECINFO_H
+#include <execinfo.h>
+#endif
+
+#define BACKTRACE_SZ 1000
+
+void yaz_invoke_backtrace(char *buf, int buf_sz)
+{
+ FILE *file = yaz_log_file();
+ int fd = fileno(file);
+#if HAVE_EXECINFO_H
+ void *backtrace_info[BACKTRACE_SZ];
+ char **backtrace_str;
+ int sz = BACKTRACE_SZ;
+ int left = buf_sz - strlen(buf);
+
+ sz = backtrace(backtrace_info, sz);
+ backtrace_str = backtrace_symbols(backtrace_info, sz);
+
+ yaz_snprintf(buf + strlen(buf), left, "Backtrace for PID=%ld\n",
+ (long) getpid());
+ if (backtrace_str)
+ {
+ int i;
+ for (i = 1; i < sz; i++)
+ {
+ left = buf_sz - strlen(buf);
+ if (left < 80)
+ break;
+ yaz_snprintf(buf + strlen(buf), left, " %p %s\n",
+ backtrace_info[i], backtrace_str[i]);
+ }
+ }
+#endif
+ write(fd, buf, strlen(buf));
+}
+
+void yaz_panic_sig_handler(int sig)
+{
+ char buf[4096];
+
+ signal(SIGABRT, SIG_DFL);
+ strcpy(buf, "\nyaz_panic_sig_handlet received ");
+ switch (sig)
+ {
+ case SIGSEGV:
+ strcat(buf, "SIGSEGV\n");
+ break;
+ case SIGABRT:
+ strcat(buf, "SIGABRT\n");
+ break;
+ case SIGFPE:
+ strcat(buf, "SIGFPE\n");
+ break;
+ case SIGBUS:
+ strcat(buf, "SIGFPE\n");
+ break;
+ default:
+ yaz_snprintf(buf + strlen(buf), sizeof buf, "signo=%d\n", sig);
+ break;
+ }
+ yaz_invoke_backtrace(buf, sizeof buf);
+ abort();
+}
+
+void yaz_enable_panic_backtrace(void)
+{
+ signal(SIGABRT, yaz_panic_sig_handler);
+ signal(SIGSEGV, yaz_panic_sig_handler);
+ signal(SIGFPE, yaz_panic_sig_handler);
+ signal(SIGBUS, yaz_panic_sig_handler);
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
$(OBJDIR)\file_glob.obj \
$(OBJDIR)\thread_id.obj \
$(OBJDIR)\dirent.obj \
- $(OBJDIR)\url.obj
+ $(OBJDIR)\url.obj \
+ $(OBJDIR)\backtrace.obj
Z3950_OBJS= \
$(OBJDIR)\z-date.obj\
#include <yaz/diagbib1.h>
#include <yaz/otherinfo.h>
#include <yaz/facet.h>
+#include <yaz/backtrace.h>
#include "ztest.h"
int main(int argc, char **argv)
{
+ yaz_enable_panic_backtrace();
+
return statserv_main(argc, argv, bend_init, bend_close);
}
/*