close
Skip to content

Commit 305b89b

Browse files
committed
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 <sys/sysctl.h> guarded by __FreeBSD__. Signed-off-by: Pedro Ramos <131530838+pr9000@users.noreply.github.com>
1 parent d6be58e commit 305b89b

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ static int cbm_powershell_quote_word(const char *value, char *out, size_t out_si
107107
#include <stdlib.h>
108108
#include <string.h> // strtok_r
109109
#include <sys/stat.h> // mode_t, S_IXUSR
110+
#ifdef __FreeBSD__
111+
#include <sys/types.h>
112+
#include <sys/sysctl.h>
113+
#endif
110114
#include <time.h>
111115
#include <wchar.h>
112116
#include <zlib.h> // MAX_WBITS
@@ -8913,6 +8917,13 @@ static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) {
89138917
if (!exact) {
89148918
buf[0] = '\0';
89158919
}
8920+
#elif defined(__FreeBSD__)
8921+
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
8922+
size_t cb = buf_sz;
8923+
exact = sysctl(mib, 4, buf, &cb, NULL, 0) == 0 && cb > 0;
8924+
if (!exact) {
8925+
buf[0] = '\0';
8926+
}
89168927
#else
89178928
ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE);
89188929
exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE;

0 commit comments

Comments
 (0)