From: devnexen@gmail.com Date: Tue, 17 Aug 2021 11:55:49 +0000 (+0100) Subject: MINOR: tools: add FreeBSD support to get_exec_path() X-Git-Tag: v2.5-dev5~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4e5232db89786bdd12cf8d23cedd17a8c65770c;p=thirdparty%2Fhaproxy.git MINOR: tools: add FreeBSD support to get_exec_path() FreeBSD stores the absolute path into the auxiliary vector as well. The auxiliary vector is found in __elf_aux_vector there. --- diff --git a/src/tools.c b/src/tools.c index 545fd9e8dc..1961689dd4 100644 --- a/src/tools.c +++ b/src/tools.c @@ -16,6 +16,12 @@ #include #endif +#if defined(__FreeBSD__) +#include +#include +extern void *__elf_aux_vector; +#endif + #if defined(__NetBSD__) #include #include @@ -4766,6 +4772,14 @@ const char *get_exec_path() if (execfn && execfn != ENOENT) ret = (const char *)execfn; +#elif defined(__FreeBSD__) + Elf_Auxinfo *auxv; + for (auxv = __elf_aux_vector; auxv->a_type != AT_NULL; ++auxv) { + if (auxv->a_type == AT_EXECPATH) { + ret = (const char *)auxv->a_un.a_ptr; + break; + } + } #elif defined(__NetBSD__) AuxInfo *auxv; for (auxv = _dlauxinfo(); auxv->a_type != AT_NULL; ++auxv) {