BUILD: tools: get the absolute path of the current binary on NetBSD.

NetBSD stores the absolute path into the auxiliary vector as well.
This commit is contained in:
David Carlier 2021-08-17 08:44:25 +01:00 committed by Willy Tarreau
parent af2720f69f
commit bd2ccedcc5
1 changed files with 13 additions and 0 deletions

View File

@ -16,6 +16,11 @@
#include <link.h> #include <link.h>
#endif #endif
#if defined(__NetBSD__)
#include <sys/exec_elf.h>
#include <dlfcn.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
@ -4761,6 +4766,14 @@ const char *get_exec_path()
if (execfn && execfn != ENOENT) if (execfn && execfn != ENOENT)
ret = (const char *)execfn; ret = (const char *)execfn;
#elif defined(__NetBSD__)
AuxInfo *auxv;
for (auxv = _dlauxinfo(); auxv->a_type != AT_NULL; ++auxv) {
if (auxv->a_type == AT_SUN_EXECNAME) {
ret = (const char *)auxv->a_v;
break;
}
}
#endif #endif
return ret; return ret;
} }