[pulseaudio-discuss] [PATCH] util: Fix pa_get_binary_name() on Debian/kFreeBSD

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Sun Aug 10 01:37:39 PDT 2014


On Wed, 2014-08-06 at 18:12 -0400, Felipe Sateler wrote:
> On Mon, Aug 4, 2014 at 10:52 AM, Peter Meerwald <pmeerw at pmeerw.net> wrote:
> >
> >> > Debian GNU/kFreeBSD uses a FreeBSD kernel and GLIBC,
> >> > it #defines __FreeBSD_kernel__, but not __FreeBSD__ nor __linux__
> >> > Debian GNU/kFreeBSD does have a /proc/self/exe
> >> >
> >> > FreeBSD #defines __FreeBSD__ and __FreeBSD_kernel__
> >> >
> >> > problem reporte here:
> >> > http://lists.freedesktop.org/archives/pulseaudio-discuss/2014-July/020998.html
> >> >
> >> > Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
> >> > ---
> >> >  src/pulse/util.c | 2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/src/pulse/util.c b/src/pulse/util.c
> >> > index 50f90b8..42b160a 100644
> >> > --- a/src/pulse/util.c
> >> > +++ b/src/pulse/util.c
> >> > @@ -193,7 +193,7 @@ char *pa_get_binary_name(char *s, size_t l) {
> >> >      }
> >> >  #endif
> >> >
> >> > -#ifdef __linux__
> >> > +#if defined(__linux__) || defined(__FreeBSD_kernel__)
> >>
> >> If FreeBSD does not have /proc/self/exe, but defines
> >> __FreeBSD_kernel__ then this check will pass, which I don't think is
> >> intended.
> >
> > on FreeBSD it will call pa_readlink("/proc/self/exe") which will return
> > NULL and then continue with the FreeBSD-specific code
> >
> >> Perhaps the check needs to be defined(__FreeBSD_kernel__) &&
> >> !defined(__FreeBSD__)?
> >
> > would work as well, I prefer simpler #defines;
> > defined(__FreeBSD_kernel__) && defined(__GLIBC__) should do as well

/proc/self/exe is not managed by glibc, so checking for __GLIBC__ would
be a bit misleading IMO - what we really would like to have is
__Debian_kFreeBSD__ or similar, since what we're interested in is that
is the kernel Debian's custom version of FreeBSD. I don't know if that
kind of macro exists. If not, I think defined(__linux__) ||
defined(__FreeBSD_kernel__) is the second best alternative.

> >
> > one extra readlink() doesn't hurt
> 
> I just found out about this possibility[1]:
> 
> #include <dlfcn.h>
> [...]
> Dl_info DLInfo;
> int err = dladdr(&main, &DLInfo);
> if (err != 0) {
>   // DLInfo.dli_fname has the executable name.
> }
> 
> This should work on all glibc systems. I can prepare a patch if this
> solution is acceptable too.
> 
> [1] https://www.gnu.org/software/hurd/hurd/translator/procfs/jkoenig/discussion.html#index7h1

I'd not be against that, just remember to apply pa_realpath() first,
because dli_fname may contain a symlink instead of the real path.

-- 
Tanu



More information about the pulseaudio-discuss mailing list