From 305b89bfa8b757c95810d7c2085c15f138a0922e Mon Sep 17 00:00:00 2001 From: Pedro Ramos <131530838+pr9000@users.noreply.github.com> Date: Tue, 28 Jul 2026 11:46:28 +0100 Subject: [PATCH] fix(cli): add native FreeBSD self-executable path resolution cbm_detect_self_path had no branch for FreeBSD, falling through to the generic #else that reads /proc/self/exe. In this environment /proc is a native FreeBSD procfs mount left empty (only /compat/linux/proc is populated, for Linux-ABI processes under the compat layer), so the readlink always failed silently and the function fell back to the expected install path instead of the actual running binary's path. This broke install: with no valid self path, the activation transaction could never confirm what to publish and aborted early with "activation transaction I/O failed" before attempting any linkat/rename. Add sysctl(CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1) for FreeBSD, matching the pattern already used in the test suites, and include guarded by __FreeBSD__. Signed-off-by: Pedro Ramos <131530838+pr9000@users.noreply.github.com> --- src/cli/cli.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 #include // strtok_r #include // mode_t, S_IXUSR +#ifdef __FreeBSD__ +#include +#include +#endif #include #include #include // 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;