Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid /proc on BSDs as it may not be mounted #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H

/* Define to 1 if you have the <sys/sysctl.h> header file. */
#undef HAVE_SYS_SYSCTL_H

/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H

Expand Down
14 changes: 14 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions fileline.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,42 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <stdlib.h>
#include <unistd.h>

#if defined(HAVE_SYS_SYSCTL_H)
#include <sys/sysctl.h>
#include <limits.h>
#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
Expand Down