From 0132efb73dea9fe1f792f71fe985f8b911e32fa4 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Wed, 12 Jul 2017 22:48:00 +0000 Subject: [PATCH] * backtrace.c (getexecname): New function. (fileline_initialize): Prefer local `getexecname' on BSDs. * configure.ac: Detect sys/sysctl.h on BSDs. * configure: Regenerate. * config.h.in: Regenerate. --- config.h.in | 3 +++ configure | 14 ++++++++++++++ configure.ac | 3 +++ fileline.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/config.h.in b/config.h.in index 76baa09..a50269d 100644 --- a/config.h.in +++ b/config.h.in @@ -76,6 +76,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SYSCTL_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H diff --git a/configure b/configure index 642df12..ac070d1 100755 --- a/configure +++ b/configure @@ -11731,6 +11731,20 @@ fi done +# Check if BSDs can try KERN_PROC_PATHNAME +for ac_header in sys/sysctl.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "sys/sysctl.h" "ac_cv_header_sys_sysctl_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_sysctl_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_SYS_SYSCTL_H 1 +_ACEOF + +fi + +done + + # Check for getexecname function. if test -n "${with_target_subdir}"; then case "${host}" in diff --git a/configure.ac b/configure.ac index 2aad65a..80926bf 100644 --- a/configure.ac +++ b/configure.ac @@ -373,6 +373,9 @@ fi AC_CHECK_DECLS(strnlen) AC_CHECK_FUNCS(lstat readlink) +# Check if BSDs can try KERN_PROC_PATHNAME +AC_CHECK_HEADERS(sys/sysctl.h) + # Check for getexecname function. if test -n "${with_target_subdir}"; then case "${host}" in diff --git a/fileline.c b/fileline.c index e567306..c50c1b6 100644 --- a/fileline.c +++ b/fileline.c @@ -39,9 +39,42 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include +#if defined(HAVE_SYS_SYSCTL_H) +#include +#include +#endif + #include "backtrace.h" #include "internal.h" +#if !defined(HAVE_GETEXECNAME) && defined(KERN_PROC_PATHNAME) +/* Return pathname of executable or 0 on failure. */ +#define HAVE_GETEXECNAME +static char execname[PATH_MAX + 1]; +static const char * +getexecname (void) +{ + size_t path_len = sizeof(execname); + int mib[] = { + CTL_KERN, +#if defined(__NetBSD__) + KERN_PROC_ARGS, + -1, + KERN_PROC_PATHNAME, +#else + KERN_PROC, + KERN_PROC_PATHNAME, + -1, +#endif + }; + + if (sysctl (mib, sizeof mib / sizeof mib[0], execname, &path_len, NULL, 0) < 0) + return NULL; + + return execname; +} +#endif /* !HAVE_GETEXECNAME && KERN_PROC_PATHNAME */ + #ifndef HAVE_GETEXECNAME #define getexecname() NULL #endif