From: Damjan Jovanovic Subject: [PATCH 3/8] ntdll: use sysctl instead of /proc/curproc/file on FreeBSD Message-Id: Date: Sat, 23 Oct 2021 10:15:55 +0200 Signed-off-by: Damjan Jovanovic --- dlls/ntdll/unix/loader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 4e807744862..2be11dc3747 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -58,6 +58,10 @@ #ifdef HAVE_SYS_WAIT_H #include #endif +#include +#ifdef HAVE_SYS_SYSCTL_H +# include +#endif #ifdef __APPLE__ # include # define LoadResource MacLoadResource @@ -588,6 +592,11 @@ static void set_config_dir(void) static void init_paths( char *argv[] ) { Dl_info info; +#if defined (__FreeBSD__) || defined(__DragonFly__) + static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + char *path; + size_t path_size; +#endif argv0 = strdup( argv[0] ); @@ -600,7 +609,10 @@ static void init_paths( char *argv[] ) #if (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) bin_dir = realpath_dirname( "/proc/self/exe" ); #elif defined (__FreeBSD__) || defined(__DragonFly__) - bin_dir = realpath_dirname( "/proc/curproc/file" ); + path = malloc( path_size = PATH_MAX ); + if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) + bin_dir = realpath_dirname( path ); + free( path ); #else bin_dir = realpath_dirname( argv0 ); #endif