]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add FreeBSD support to get_exec_path()
authordevnexen@gmail.com <devnexen@gmail.com>
Tue, 17 Aug 2021 11:55:49 +0000 (12:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Aug 2021 15:33:32 +0000 (17:33 +0200)
FreeBSD stores the absolute path into the auxiliary vector as well.
The auxiliary vector is found in __elf_aux_vector there.

src/tools.c

index 545fd9e8dca241e5d7c24fb4f4585d970447f75f..1961689dd46f1d982f5031323948828304bec56b 100644 (file)
 #include <link.h>
 #endif
 
+#if defined(__FreeBSD__)
+#include <elf.h>
+#include <dlfcn.h>
+extern void *__elf_aux_vector;
+#endif
+
 #if defined(__NetBSD__)
 #include <sys/exec_elf.h>
 #include <dlfcn.h>
@@ -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) {