Signal and backtrace improvements
This commit is contained in:
parent
18b72f9617
commit
b5c536b134
|
@ -72,11 +72,14 @@ set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
|
||||||
check_include_file("linux/videodev.h" HAVE_LINUX_VIDEODEV_H)
|
check_include_file("linux/videodev.h" HAVE_LINUX_VIDEODEV_H)
|
||||||
check_include_file("linux/videodev2.h" HAVE_LINUX_VIDEODEV2_H)
|
check_include_file("linux/videodev2.h" HAVE_LINUX_VIDEODEV2_H)
|
||||||
check_include_file("execinfo.h" HAVE_EXECINFO_H)
|
check_include_file("execinfo.h" HAVE_EXECINFO_H)
|
||||||
|
check_include_file("siginfo.h" HAVE_SIGINFO_H)
|
||||||
|
check_include_file("ucontext.h" HAVE_UCONTEXT_H)
|
||||||
check_include_file("sys/sendfile.h" HAVE_SYS_SENDFILE_H)
|
check_include_file("sys/sendfile.h" HAVE_SYS_SENDFILE_H)
|
||||||
check_include_file("sys/syscall.h" HAVE_SYS_SYSCALL_H)
|
check_include_file("sys/syscall.h" HAVE_SYS_SYSCALL_H)
|
||||||
check_function_exists("syscall" HAVE_SYSCALL)
|
check_function_exists("syscall" HAVE_SYSCALL)
|
||||||
check_function_exists("sendfile" HAVE_SENDFILE)
|
check_function_exists("sendfile" HAVE_SENDFILE)
|
||||||
check_function_exists("backtrace" HAVE_DECL_BACKTRACE)
|
check_function_exists("backtrace" HAVE_DECL_BACKTRACE)
|
||||||
|
check_function_exists("backtrace_symbols" HAVE_DECL_BACKTRACE_SYMBOLS)
|
||||||
check_function_exists("posix_memalign" HAVE_POSIX_MEMALIGN)
|
check_function_exists("posix_memalign" HAVE_POSIX_MEMALIGN)
|
||||||
check_function_exists("strsignal" HAVE_STRSIGNAL)
|
check_function_exists("strsignal" HAVE_STRSIGNAL)
|
||||||
check_prototype_definition("round" "double round (double x)" "0.0" "math.h" HAVE_DECL_ROUND)
|
check_prototype_definition("round" "double round (double x)" "0.0" "math.h" HAVE_DECL_ROUND)
|
||||||
|
|
|
@ -237,6 +237,7 @@ AC_TYPE_SIGNAL
|
||||||
AC_CHECK_TYPES(siginfo_t,,,[#include <signal.h>])
|
AC_CHECK_TYPES(siginfo_t,,,[#include <signal.h>])
|
||||||
AC_CHECK_TYPES(struct sigcontext,,,[#include <signal.h>])
|
AC_CHECK_TYPES(struct sigcontext,,,[#include <signal.h>])
|
||||||
AC_CHECK_MEMBERS([struct sigcontext.eip],,,[#include <signal.h>])
|
AC_CHECK_MEMBERS([struct sigcontext.eip],,,[#include <signal.h>])
|
||||||
|
AC_CHECK_MEMBERS([struct sigcontext.rip],,,[#include <signal.h>])
|
||||||
AC_CHECK_TYPES(ucontext_t,,,[#include <signal.h>])
|
AC_CHECK_TYPES(ucontext_t,,,[#include <signal.h>])
|
||||||
|
|
||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
|
@ -302,6 +303,8 @@ AC_HEADER_STDC
|
||||||
AC_CHECK_HEADERS([fcntl.h limits.h memory.h stddef.h stdlib.h string.h strings.h sys/param.h sys/time.h syslog.h unistd.h values.h])
|
AC_CHECK_HEADERS([fcntl.h limits.h memory.h stddef.h stdlib.h string.h strings.h sys/param.h sys/time.h syslog.h unistd.h values.h])
|
||||||
AC_CHECK_HEADERS([netdb.h netinet/in.h arpa/inet.h sys/ioctl.h sys/socket.h sys/un.h glob.h sys/sendfile.h])
|
AC_CHECK_HEADERS([netdb.h netinet/in.h arpa/inet.h sys/ioctl.h sys/socket.h sys/un.h glob.h sys/sendfile.h])
|
||||||
AC_CHECK_HEADERS(execinfo.h,,,)
|
AC_CHECK_HEADERS(execinfo.h,,,)
|
||||||
|
AC_CHECK_HEADERS(siginfo.h,,,)
|
||||||
|
AC_CHECK_HEADERS(ucontext.h,,,)
|
||||||
AC_CHECK_HEADERS(sys/syscall.h,,,)
|
AC_CHECK_HEADERS(sys/syscall.h,,,)
|
||||||
AC_CHECK_HEADERS(pthread.h,,,)
|
AC_CHECK_HEADERS(pthread.h,,,)
|
||||||
AC_CHECK_HEADERS(linux/videodev.h,AC_SUBST(ZM_HAS_V4L1,1),AC_SUBST(ZM_HAS_V4L1,0),)
|
AC_CHECK_HEADERS(linux/videodev.h,AC_SUBST(ZM_HAS_V4L1,1),AC_SUBST(ZM_HAS_V4L1,0),)
|
||||||
|
@ -345,6 +348,7 @@ AC_CHECK_DECLS(gnutls_fingerprint,,AC_MSG_ERROR([zm requires gnutls/gnutls.h - u
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
AC_CHECK_DECLS(backtrace,,,[#include <execinfo.h>])
|
AC_CHECK_DECLS(backtrace,,,[#include <execinfo.h>])
|
||||||
|
AC_CHECK_DECLS(backtrace_symbols,,,[#include <execinfo.h>])
|
||||||
|
|
||||||
AC_SUBST(LDFLAGS)
|
AC_SUBST(LDFLAGS)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TRACE_SIZE 16
|
||||||
|
|
||||||
bool zm_reload = false;
|
bool zm_reload = false;
|
||||||
|
bool zm_terminate = false;
|
||||||
|
|
||||||
|
|
||||||
RETSIGTYPE zm_hup_handler( int signal )
|
RETSIGTYPE zm_hup_handler( int signal )
|
||||||
{
|
{
|
||||||
|
@ -36,7 +40,6 @@ RETSIGTYPE zm_hup_handler( int signal )
|
||||||
zm_reload = true;
|
zm_reload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zm_terminate = false;
|
|
||||||
|
|
||||||
RETSIGTYPE zm_term_handler( int signal )
|
RETSIGTYPE zm_term_handler( int signal )
|
||||||
{
|
{
|
||||||
|
@ -48,12 +51,10 @@ RETSIGTYPE zm_term_handler( int signal )
|
||||||
zm_terminate = true;
|
zm_terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TRACE_SIZE 16
|
|
||||||
|
|
||||||
#if HAVE_STRUCT_SIGCONTEXT
|
#if HAVE_STRUCT_SIGCONTEXT
|
||||||
RETSIGTYPE zm_die_handler( int signal, struct sigcontext context )
|
RETSIGTYPE zm_die_handler( int signal, struct sigcontext context )
|
||||||
#elif ( HAVE_SIGINFO_T && HAVE_UCONTEXT_T )
|
#elif ( HAVE_SIGINFO_T && HAVE_UCONTEXT_T )
|
||||||
#include <ucontext.h>
|
|
||||||
RETSIGTYPE zm_die_handler( int signal, siginfo_t *info, void *context )
|
RETSIGTYPE zm_die_handler( int signal, siginfo_t *info, void *context )
|
||||||
#else
|
#else
|
||||||
RETSIGTYPE zm_die_handler( int signal )
|
RETSIGTYPE zm_die_handler( int signal )
|
||||||
|
@ -81,29 +82,37 @@ RETSIGTYPE zm_die_handler( int signal )
|
||||||
void *trace[TRACE_SIZE];
|
void *trace[TRACE_SIZE];
|
||||||
int trace_size = 0;
|
int trace_size = 0;
|
||||||
|
|
||||||
#if HAVE_STRUCT_SIGCONTEXT_EIP
|
|
||||||
Error( "Signal address is %p, from %p", (void *)context.cr2, (void *)context.eip );
|
|
||||||
|
|
||||||
trace_size = backtrace( trace, TRACE_SIZE );
|
trace_size = backtrace( trace, TRACE_SIZE );
|
||||||
|
#if HAVE_STRUCT_SIGCONTEXT
|
||||||
|
#if HAVE_STRUCT_SIGCONTEXT_RIP
|
||||||
|
Error( "Signal address is %p, from %p", (void *)context.cr2, (void *)context.rip );
|
||||||
|
// overwrite sigaction with caller's address
|
||||||
|
trace[1] = (void *)context.rip;
|
||||||
|
#elif HAVE_STRUCT_SIGCONTEXT_EIP
|
||||||
|
Error( "Signal address is %p, from %p", (void *)context.cr2, (void *)context.eip );
|
||||||
// overwrite sigaction with caller's address
|
// overwrite sigaction with caller's address
|
||||||
trace[1] = (void *)context.eip;
|
trace[1] = (void *)context.eip;
|
||||||
#elif HAVE_STRUCT_SIGCONTEXT
|
#else
|
||||||
Error( "Signal address is %p, no eip", (void *)context.cr2 );
|
Error( "Signal address is %p, no instruction pointer", (void *)context.cr2 );
|
||||||
|
#endif // HAVE_STRUCT_SIGCONTEXT_*
|
||||||
|
|
||||||
trace_size = backtrace( trace, TRACE_SIZE );
|
|
||||||
#else // HAVE_STRUCT_SIGCONTEXT
|
#else // HAVE_STRUCT_SIGCONTEXT
|
||||||
if ( info && context )
|
if ( info && context )
|
||||||
{
|
{
|
||||||
ucontext_t *uc = (ucontext_t *)context;
|
ucontext_t *uc = (ucontext_t *)context;
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
Error( "Signal address is %p, from %p", info->si_addr, uc->uc_mcontext.gregs[REG_RIP] );
|
||||||
|
// overwrite sigaction with caller's address
|
||||||
|
trace[1] = (void *) uc->uc_mcontext.gregs[REG_RIP];
|
||||||
|
#else
|
||||||
Error( "Signal address is %p, from %p", info->si_addr, uc->uc_mcontext.gregs[REG_EIP] );
|
Error( "Signal address is %p, from %p", info->si_addr, uc->uc_mcontext.gregs[REG_EIP] );
|
||||||
|
|
||||||
trace_size = backtrace( trace, TRACE_SIZE );
|
|
||||||
// overwrite sigaction with caller's address
|
// overwrite sigaction with caller's address
|
||||||
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
|
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
|
||||||
|
#endif // defined(__x86_64__)
|
||||||
}
|
}
|
||||||
#endif // HAVE_STRUCT_SIGCONTEXT
|
#endif // HAVE_STRUCT_SIGCONTEXT
|
||||||
#if HAVE_DECL_BACKTRACE
|
|
||||||
|
#if ( HAVE_DECL_BACKTRACE && HAVE_DECL_BACKTRACE_SYMBOLS )
|
||||||
char cmd[1024] = "addr2line -e ";
|
char cmd[1024] = "addr2line -e ";
|
||||||
char *cmd_ptr = cmd+strlen(cmd);
|
char *cmd_ptr = cmd+strlen(cmd);
|
||||||
// Try and extract the binary path from the last backtrace frame
|
// Try and extract the binary path from the last backtrace frame
|
||||||
|
@ -125,13 +134,15 @@ RETSIGTYPE zm_die_handler( int signal )
|
||||||
}
|
}
|
||||||
Info( "Backtrace complete, please execute the following command for more information" );
|
Info( "Backtrace complete, please execute the following command for more information" );
|
||||||
Info( cmd );
|
Info( cmd );
|
||||||
#endif // HAVE_DECL_BACKTRACE
|
#endif // ( HAVE_DECL_BACKTRACE && HAVE_DECL_BACKTRACE_SYMBOLS )
|
||||||
#endif // ( HAVE_SIGINFO_T && HAVE_UCONTEXT_T ) || HAVE_STRUCT_SIGCONTEXT
|
|
||||||
|
#endif // (( HAVE_SIGINFO_T && HAVE_UCONTEXT_T ) || HAVE_STRUCT_SIGCONTEXT )
|
||||||
#endif // ZM_NO_CRASHTRACE
|
#endif // ZM_NO_CRASHTRACE
|
||||||
|
|
||||||
exit( signal );
|
exit( signal );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void zmSetHupHandler( SigHandler *handler )
|
void zmSetHupHandler( SigHandler *handler )
|
||||||
{
|
{
|
||||||
sigset_t block_set;
|
sigset_t block_set;
|
||||||
|
|
|
@ -21,7 +21,17 @@
|
||||||
#define ZM_SIGNAL_H
|
#define ZM_SIGNAL_H
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#if HAVE_EXECINFO_H
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_SIGINFO_H
|
||||||
|
#include <siginfo.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_UCONTEXT_H
|
||||||
|
#include <ucontext.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
|
|
||||||
|
@ -35,7 +45,6 @@ RETSIGTYPE zmc_term_handler( int signal );
|
||||||
#if HAVE_STRUCT_SIGCONTEXT
|
#if HAVE_STRUCT_SIGCONTEXT
|
||||||
RETSIGTYPE zmc_die_handler( int signal, struct sigcontext context );
|
RETSIGTYPE zmc_die_handler( int signal, struct sigcontext context );
|
||||||
#elif ( HAVE_SIGINFO_T && HAVE_UCONTEXT_T )
|
#elif ( HAVE_SIGINFO_T && HAVE_UCONTEXT_T )
|
||||||
#include <ucontext.h>
|
|
||||||
RETSIGTYPE zmc_die_handler( int signal, siginfo_t *info, void *context );
|
RETSIGTYPE zmc_die_handler( int signal, siginfo_t *info, void *context );
|
||||||
#else
|
#else
|
||||||
RETSIGTYPE zmc_die_handler( int signal );
|
RETSIGTYPE zmc_die_handler( int signal );
|
||||||
|
|
|
@ -7,11 +7,14 @@
|
||||||
#cmakedefine HAVE_LINUX_VIDEODEV_H 1
|
#cmakedefine HAVE_LINUX_VIDEODEV_H 1
|
||||||
#cmakedefine HAVE_LINUX_VIDEODEV2_H 1
|
#cmakedefine HAVE_LINUX_VIDEODEV2_H 1
|
||||||
#cmakedefine HAVE_EXECINFO_H 1
|
#cmakedefine HAVE_EXECINFO_H 1
|
||||||
|
#cmakedefine HAVE_SIGINFO_H 1
|
||||||
|
#cmakedefine HAVE_UCONTEXT_H 1
|
||||||
#cmakedefine HAVE_SYS_SENDFILE_H 1
|
#cmakedefine HAVE_SYS_SENDFILE_H 1
|
||||||
#cmakedefine HAVE_SYS_SYSCALL_H 1
|
#cmakedefine HAVE_SYS_SYSCALL_H 1
|
||||||
#cmakedefine HAVE_SYSCALL 1
|
#cmakedefine HAVE_SYSCALL 1
|
||||||
#cmakedefine HAVE_SENDFILE 1
|
#cmakedefine HAVE_SENDFILE 1
|
||||||
#cmakedefine HAVE_DECL_BACKTRACE 1
|
#cmakedefine HAVE_DECL_BACKTRACE 1
|
||||||
|
#cmakedefine HAVE_DECL_BACKTRACE_SYMBOLS 1
|
||||||
#cmakedefine HAVE_POSIX_MEMALIGN 1
|
#cmakedefine HAVE_POSIX_MEMALIGN 1
|
||||||
#cmakedefine HAVE_STRSIGNAL 1
|
#cmakedefine HAVE_STRSIGNAL 1
|
||||||
#cmakedefine HAVE_DECL_ROUND 1
|
#cmakedefine HAVE_DECL_ROUND 1
|
||||||
|
|
Loading…
Reference in New Issue