Message ID | alpine.LNX.2.00.1210051259190.1878@tuna.site |
---|---|
State | New |
Headers | show |
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
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
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
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));