Autodetect "/proc/self/exe"-equivalent on FreeBSD (#1999)

master
Lukas Werling 2018-02-17 12:41:16 +01:00
parent 334c57f296
commit 9855f9355e
4 changed files with 18 additions and 4 deletions

View File

@ -300,6 +300,17 @@ if(UNIX AND NOT APPLE)
if(Backward_FOUND)
set(HAVE_BACKWARD 1)
endif()
if(NOT DEFINED PROC_SELF_EXE)
macro(FIND_PROC_SELF_EXE path)
if(EXISTS ${path})
set(PROC_SELF_EXE ${path} CACHE FILEPATH "Path to /proc/self/exe (Linux) or equivalent")
endif()
endmacro()
FIND_PROC_SELF_EXE(/proc/self/exe) # Linux
FIND_PROC_SELF_EXE(/proc/curproc/file) # FreeBSD
FIND_PROC_SELF_EXE(/proc/curproc/exe) # NetBSD
endif()
endif()
if (WIN32)

View File

@ -118,3 +118,6 @@
/* Include OpenAL extensions (alext.h) for sound modifiers */
#cmakedefine HAVE_ALEXT 1
/* Path to /proc/self/exe (Linux) or equivalent */
#cmakedefine PROC_SELF_EXE "${PROC_SELF_EXE}"

View File

@ -443,9 +443,9 @@ void C4ConfigGeneral::DeterminePaths()
GetTempPathW(CFG_MaxString,apath);
TempPath = StdStrBuf(apath);
if (TempPath[0]) TempPath.AppendBackslash();
#elif defined(__linux__)
#elif defined(PROC_SELF_EXE)
ExePath.SetLength(1024);
ssize_t l = readlink("/proc/self/exe", ExePath.getMData(), 1024);
ssize_t l = readlink(PROC_SELF_EXE, ExePath.getMData(), 1024);
if (l < -1)
{
ExePath.Ref(".");

View File

@ -98,7 +98,7 @@ bool RestartApplication(std::vector<const char *> parameters)
intptr_t iError = (intptr_t)::ShellExecute(nullptr, nullptr, buf, params.GetWideChar(), Config.General.ExePath.GetWideChar(), SW_SHOW);
if (iError > 32) success = true;
}
#else
#elif defined(PROC_SELF_EXE)
pid_t pid;
switch (pid = fork())
{
@ -108,7 +108,7 @@ bool RestartApplication(std::vector<const char *> parameters)
std::vector<const char*> params = {"openclonk"};
params.insert(params.end(), parameters.begin(), parameters.end());
params.push_back(nullptr);
execv("/proc/self/exe", const_cast<char *const *>(params.data()));
execv(PROC_SELF_EXE, const_cast<char *const *>(params.data()));
perror("editor launch failed");
exit(1);
}