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

NetBSD stores the absolute path into the auxiliary vector as well.

(cherry picked from commit bd2ccedcc51d622598644179788d7dca37e8f6d3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/tools.c b/src/tools.c
index 8010126..7eaa743 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -16,6 +16,11 @@
 #include <link.h>
 #endif
 
+#if defined(__NetBSD__)
+#include <sys/exec_elf.h>
+#include <dlfcn.h>
+#endif
+
 #include <ctype.h>
 #include <errno.h>
 #include <netdb.h>
@@ -4761,6 +4766,14 @@
 
 	if (execfn && execfn != ENOENT)
 		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
 	return ret;
 }