From ab2743dd23ba093f389a89bf8daf55d777f4ff4d Mon Sep 17 00:00:00 2001 From: Ka Ho Ng Date: Tue, 7 Apr 2020 00:45:57 +0800 Subject: [PATCH] libobs/util: FreeBSD/Dragonfly exec path support Add support for FreeBSD and Dragonfly in os_get_executable_path_ptr(). This is required to obtain the path of the running executable image correctly. Fixes https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=245299 Fixes https://github.com/obsproject/obs-studio/issues/2622 --- libobs/util/platform-nix.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index d91ddd66f..1dd81077e 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -275,7 +275,20 @@ char *os_get_program_data_path_ptr(const char *name) char *os_get_executable_path_ptr(const char *name) { char exe[PATH_MAX]; +#if defined(__FreeBSD__) || defined(__DragonFly__) + int sysctlname[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t pathlen = PATH_MAX; + ssize_t count; + if (sysctl(sysctlname, nitems(sysctlname), exe, &pathlen, NULL, 0) == + -1) { + blog(LOG_ERROR, "sysctl(KERN_PROC_PATHNAME) failed, errno %d", + errno); + return NULL; + } + count = pathlen; +#else ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX); +#endif const char *path_out = NULL; struct dstr path;