Patchwork [libbacktrace] Use getexecname() on Solaris

login
register
mail settings
Submitter Gerald Pfeifer
Date Oct. 5, 2012, 11:05 a.m.
Message ID <alpine.LNX.2.00.1210051259190.1878@tuna.site>
Download mbox | patch
Permalink /patch/189457/
State New
Headers show

Comments

Gerald Pfeifer - Oct. 5, 2012, 11:05 a.m.
On Fri, 5 Oct 2012, Rainer Orth wrote:
> 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.
>
> 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.

Oops, I also had prepared a patch for this which I was just going
to submit when seeing yours.

Your patch is better in that it checks for getexecname (which does
not exist in FreeBSD).  Mine seems better in that it removes the 
duplication between fileline.c and print.c and also addresses the
latter case.

Could you just merge mine into yours or am I missing something?

Gerald


2012-10-05  Gerald Pfeifer  <gerald@pfeifer.com>

	* internal.h (DEFAULT_PROCESS_FILENAME): Define.
	* fileline.c (fileline_initialize): Use it.
 	* print.c (error_callback): Ditto.
Rainer Orth - Oct. 5, 2012, 11:21 a.m.
Gerald Pfeifer <gerald@pfeifer.com> writes:

> Your patch is better in that it checks for getexecname (which does
> not exist in FreeBSD).  Mine seems better in that it removes the 
> duplication between fileline.c and print.c and also addresses the
> latter case.
>
> Could you just merge mine into yours or am I missing something?

I think this should work.  The only complication might be that users of
DEFAULT_PROCESS_FILENAME need to include <stdlib.h> on Solaris to get
the declaration of getexecname().  Given that this header is already
used unconditionally, its inclusion should probably be moved to either
internal.h (which doesn't yet include anything) or backtrace.h.  Ian,
what do you prefer here?

Do the FreeBSD headers already provide a define for /proc/curproc/file?
In that case we might check for that and use it directly instead of
#ifdef __FreeBSD__.  At least on our CentOS 6.2 systems, I haven't found
anything similar for /proc/self/exe, and I still have no idea if it's
Linux-only.

	Rainer
Gerald Pfeifer - Oct. 5, 2012, 12:38 p.m.
On Fri, 5 Oct 2012, Rainer Orth wrote:
> Do the FreeBSD headers already provide a define for /proc/curproc/file?

None that I could find.

Gerald
Ian Taylor - Oct. 5, 2012, 1:49 p.m.
On Fri, Oct 5, 2012 at 4:21 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>
> I think this should work.  The only complication might be that users of
> DEFAULT_PROCESS_FILENAME need to include <stdlib.h> on Solaris to get
> the declaration of getexecname().  Given that this header is already
> used unconditionally, its inclusion should probably be moved to either
> internal.h (which doesn't yet include anything) or backtrace.h.  Ian,
> what do you prefer here?

Definitely not backtrace.h.  I think I would prefer that print.c
simply #include <stdlib.h> directly.

Ian

Patch

Index: internal.h
===================================================================
--- internal.h	(revision 192106)
+++ internal.h	(working copy)
@@ -56,6 +56,12 @@ 
 # endif
 #endif
 
+#ifdef __FreeBSD__
+# define DEFAULT_PROCESS_FILENAME "/proc/curproc/file"
+#else
+# define DEFAULT_PROCESS_FILENAME "/proc/self/exe"
+#endif
+
 #ifndef HAVE_SYNC_FUNCTIONS
 
 /* Define out the sync functions.  These should never be called if
Index: fileline.c
===================================================================
--- fileline.c	(revision 192106)
+++ fileline.c	(working copy)
@@ -82,7 +82,8 @@ 
   if (state->filename != NULL)
     descriptor = backtrace_open (state->filename, error_callback, data);
   else
-    descriptor = backtrace_open ("/proc/self/exe", error_callback, data);
+    descriptor = backtrace_open (DEFAULT_PROCESS_FILENAME, error_callback,
+				 data);
   if (descriptor < 0)
     failed = 1;
 
Index: print.c
===================================================================
--- print.c	(revision 192106)
+++ print.c	(working copy)
@@ -73,7 +73,7 @@ 
 
   name = pdata->state->filename;
   if (name == NULL)
-    name = "/proc/self/exe";
+    name = DEFAULT_PROCESS_FILENAME;
   fprintf (stderr, "%s: libbacktrace: %s", name, msg);
   if (errnum > 0)
     fprintf (stderr, ": %s", strerror (errnum));