Patchwork [libbacktrace] Use getexecname() on Solaris

login
register
mail settings
Submitter Rainer Orth
Date Oct. 5, 2012, 10:21 a.m.
Message ID <ydd391tdxt8.fsf@manam.CeBiTec.Uni-Bielefeld.DE>
Download mbox | patch
Permalink /patch/189455/
State New
Headers show

Comments

Rainer Orth - Oct. 5, 2012, 10:21 a.m.
With the strnlen-related Go failures now gone on Solaris, another issue
crept up: several tests were failing like this:

throw: /proc/self/exe

goroutine 4 [running]:
panic during panic
FAIL: log

This is due to the hardcoded use of /proc/self/exe in libbacktrace,
which doesn't exist on Solaris, and probably is also missing on other
non-Linux OSes.  Solaris (since 2.6, it seems) provides getexecname()
instead, which this patch uses.

I haven't touched the other hardcoded use in print.c since it isn't
obvious to me how best to handle it.

Tested by rebuilding libbacktrace and libgo and rerunning the libgo
tests on i386-pc-solaris2.11.  All the /proc/self/exe-related failures
are now gone as expected.

Ok for mainline?

	Rainer


2012-10-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* configure.ac: Check for getexecname.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* fileline.c (fileline_initialize) [HAVE_GETEXECNAME]: Use
	getexecname if available.
Ian Taylor - Oct. 5, 2012, 1:45 p.m.
On Fri, Oct 5, 2012 at 3:21 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
> With the strnlen-related Go failures now gone on Solaris, another issue
> crept up: several tests were failing like this:
>
> throw: /proc/self/exe
>
> goroutine 4 [running]:
> panic during panic
> FAIL: log
>
> This is due to the hardcoded use of /proc/self/exe in libbacktrace,
> which doesn't exist on Solaris, and probably is also missing on other
> non-Linux OSes.  Solaris (since 2.6, it seems) provides getexecname()
> instead, which this patch uses.

That reminds me that libgo shouldn't be relying on /proc/self/exe
anyhow.  I meant to fix that but forgot.  This patch fixes it.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Something like your patch is still a good idea, of course.

Ian

Patch

# HG changeset patch
# Parent 73da06114bd60792e31b30c4fd95ee5fe340167b
Use getexecname() on Solaris

diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -242,6 +242,19 @@  fi
 
 AC_CHECK_DECLS(strnlen)
 
+# Check for getexecname function.
+if test -n "${with_target_subdir}"; then
+   case "${host}" in
+   *-*-solaris2*) have_getexecname=yes ;;
+   *) have_getexecname=no ;;
+   esac
+else
+  AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexename=no])
+fi
+if test "$have_getexecname" = "yes"; then
+  AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
+fi
+
 AC_CACHE_CHECK([whether tests can run],
   [libbacktrace_cv_sys_native],
   [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -49,6 +49,7 @@  fileline_initialize (struct backtrace_st
 {
   int failed;
   fileline fileline_fn;
+  const char *execname;
   int descriptor;
 
   failed = state->fileline_initialization_failed;
@@ -82,7 +83,14 @@  fileline_initialize (struct backtrace_st
   if (state->filename != NULL)
     descriptor = backtrace_open (state->filename, error_callback, data);
   else
-    descriptor = backtrace_open ("/proc/self/exe", error_callback, data);
+    {
+#ifdef HAVE_GETEXECNAME
+      execname = getexecname ();
+#else
+      execname = "/proc/self/exe";
+#endif
+      descriptor = backtrace_open (execname, error_callback, data);
+    }
   if (descriptor < 0)
     failed = 1;