Skip to content

Commit 5e5dcd8

Browse files
authored
Merge pull request #1423 from PR9000/fix/freebsd-cli-self-path
fix(cli): add native FreeBSD self-executable path resolution
2 parents 786c586 + 305b89b commit 5e5dcd8

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
@@ -106,6 +106,10 @@ static int cbm_powershell_quote_word(const char *value, char *out, size_t out_si
106106
#include <stdlib.h>
107107
#include <string.h> // strtok_r
108108
#include <sys/stat.h> // mode_t, S_IXUSR
109+
#ifdef __FreeBSD__
110+
#include <sys/types.h>
111+
#include <sys/sysctl.h>
112+
#endif
109113
#include <time.h>
110114
#include <wchar.h>
111115
#include <zlib.h> // MAX_WBITS
@@ -9206,6 +9210,13 @@ static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) {
92069210
if (!exact) {
92079211
buf[0] = '\0';
92089212
}
9213+
#elif defined(__FreeBSD__)
9214+
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
9215+
size_t cb = buf_sz;
9216+
exact = sysctl(mib, 4, buf, &cb, NULL, 0) == 0 && cb > 0;
9217+
if (!exact) {
9218+
buf[0] = '\0';
9219+
}
92099220
#else
92109221
ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE);
92119222
exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE;

0 commit comments

Comments
 (0)