Skip to content

Commit

Permalink
Launch editor via argv[0] on Unix systems without /proc/self/exe (#1999)
Browse files Browse the repository at this point in the history
  • Loading branch information
lluchs committed Feb 18, 2018
1 parent a091874 commit e10d4b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/game/C4Application.cpp
Expand Up @@ -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(" ");
Expand Down
1 change: 1 addition & 0 deletions src/game/C4Application.h
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/platform/PlatformAbstraction.cpp
Expand Up @@ -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:
Expand Down

0 comments on commit e10d4b3

Please sign in to comment.