Hi,

here a little patch proposal.

Thanks in advance.
From 30a530f3b352e907a3dd9daebfda2bb94dccbdbc Mon Sep 17 00:00:00 2001
From: David Carlier <devne...@gmail.com>
Date: Tue, 17 Aug 2021 08:44:25 +0100
Subject: [PATCH] BUILD: tools: get the absolute path of the current binary on
 NetBSD.

NetBSD stores the absolute path into the auxiliary vector as well.
---
 src/tools.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/tools.c b/src/tools.c
index bd6bf4edc..545fd9e8d 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 @@ const char *get_exec_path()
 
 	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;
 }
-- 
2.32.0

Reply via email to