From 546e82965ddcf523e5369e1b2f4fee5c8ae353e3 Mon Sep 17 00:00:00 2001 From: Bob Andrews Date: Sat, 30 Apr 2022 15:01:58 +0200 Subject: [PATCH] Try reading from /proc/self first on linux, this is needed to make the edgy "make avail" work --- src/common/searchpath.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/searchpath.c b/src/common/searchpath.c index f1ee0b6e2..ebf14106f 100644 --- a/src/common/searchpath.c +++ b/src/common/searchpath.c @@ -296,10 +296,23 @@ void AddSubSearchPathFromBin (SearchPaths* P, const char* SubDir) } *Ptr = '\0'; +#elif defined(__linux__) + + /* reading from proc will return the real location, excluding symlinked + pathes - which is needed for certain edgy cases */ + if (readlink("/proc/self/exe", Dir, sizeof(Dir) - 1) < 0) { + GetProgPath(Dir, ArgVec[0]); + } else { + /* Remove binary name */ + Ptr = strrchr (Dir, PATHSEP[0]); + if (Ptr == 0) { + return; + } + *Ptr = '\0'; + } + #else - GetProgPath(Dir, ArgVec[0]); - #endif /* Check for 'bin' directory */