Permalink
Browse files

Launch editor via argv[0] on Unix systems without /proc/self/exe (#1999)

  • Loading branch information...
lluchs committed Feb 17, 2018
1 parent a091874 commit e10d4b3bf513ef57871fb9485c6be5b7c3faf5b5
Showing with 9 additions and 4 deletions.
  1. +1 −1 src/game/C4Application.cpp
  2. +1 −0 src/game/C4Application.h
  3. +7 −3 src/platform/PlatformAbstraction.cpp
@@ -192,7 +192,7 @@ void C4Application::ClearCommandLine()

void C4Application::ParseCommandLine(int argc, char * argv[])
{

argv0 = argv[0];
StdStrBuf CmdLine("Command line:");
for(int i = 0; i < argc; ++i) {
CmdLine.Append(" ");
@@ -72,6 +72,7 @@ class C4Application: public C4AbstractApp
const char *GetRevision() const { return Revision.c_str(); }

// set by ParseCommandLine
const char *argv0;
int isEditor{false};
// set by ParseCommandLine, for manually applying downloaded update packs
std::string IncomingUpdate;
@@ -98,18 +98,22 @@ 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;
}
#elif defined(PROC_SELF_EXE)
#else
pid_t pid;
switch (pid = fork())
{
case -1: break; // error message shown below
case 0:
{
std::vector<const char*> params = {"openclonk"};
std::vector<const char*> params = {Application.argv0};
params.insert(params.end(), parameters.begin(), parameters.end());
params.push_back(nullptr);
#ifdef PROC_SELF_EXE
execv(PROC_SELF_EXE, const_cast<char *const *>(params.data()));
perror("editor launch failed");
perror("editor launch via " PROC_SELF_EXE " failed");
#endif
execvp(Application.argv0, const_cast<char *const *>(params.data()));
perror("editor launch via argv[0] failed");
exit(1);
}
default:

0 comments on commit e10d4b3

Please sign in to comment.