From f01b028d58d4195c9f84a08528ae7f9c226746e3 Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Sat, 23 Oct 2021 10:18:43 +0200 Subject: [PATCH] wrc: Use sysctl instead of /proc/curproc/file on FreeBSD. Signed-off-by: Damjan Jovanovic Signed-off-by: Alexandre Julliard --- tools/wrc/wrc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c index 8cdb91195cf..b44ae6fd0e5 100644 --- a/tools/wrc/wrc.c +++ b/tools/wrc/wrc.c @@ -27,6 +27,11 @@ #include #include #include +#include +#include +#ifdef HAVE_SYS_SYSCTL_H +# include +#endif #include "../tools.h" #include "wrc.h" @@ -336,7 +341,12 @@ static void init_argv0_dir( const char *argv0 ) #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) dir = realpath( "/proc/self/exe", NULL ); #elif defined (__FreeBSD__) || defined(__DragonFly__) - dir = realpath( "/proc/curproc/file", NULL ); + static int pathname[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t path_size = PATH_MAX; + char *path = malloc( path_size ); + if (path && !sysctl( pathname, sizeof(pathname)/sizeof(pathname[0]), path, &path_size, NULL, 0 )) + dir = realpath( path, NULL ); + free( path ); #else dir = realpath( argv0, NULL ); #endif