Permalink
Browse files

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

  • Loading branch information...
lluchs committed Feb 17, 2018
1 parent cd1f540 commit a09187454684e6a510d0cbefe6a79f74f539bca5
Showing with 18 additions and 4 deletions.
  1. +11 −0 CMakeLists.txt
  2. +3 −0 config.h.cmake
  3. +2 −2 src/config/C4Config.cpp
  4. +2 −2 src/platform/PlatformAbstraction.cpp
@@ -299,6 +299,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)
@@ -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}"
@@ -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(".");
@@ -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);
}

0 comments on commit a091874

Please sign in to comment.