Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(cli): add native FreeBSD self-executable path resolution

Pedro Ramos305b89bfa8b7
diff --git a/src/cli/cli.c b/src/cli/cli.c
index 8010e2258..ed58059c2 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -107,6 +107,10 @@ static int cbm_powershell_quote_word(const char *value, char *out, size_t out_si
#include <stdlib.h>
#include <string.h> // strtok_r
#include <sys/stat.h> // mode_t, S_IXUSR
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
#include <time.h>
#include <wchar.h>
#include <zlib.h> // MAX_WBITS
@@ -8913,6 +8917,13 @@ static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) {
if (!exact) {
buf[0] = '\0';
}
+#elif defined(__FreeBSD__)
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ size_t cb = buf_sz;
+ exact = sysctl(mib, 4, buf, &cb, NULL, 0) == 0 && cb > 0;
+ if (!exact) {
+ buf[0] = '\0';
+ }
#else
ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE);
exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE;