Fix hang on exit when using platform.restart

This commit is contained in:
Tamás Bálint Misius 2021-02-08 10:55:17 +01:00
parent c1d7fc47f6
commit 3056b86780
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 20 additions and 1 deletions

View File

@ -135,6 +135,9 @@ if copt_msvc
args_msvc_opt = [ '/Oy-', '/fp:fast' ]
project_c_args += args_msvc_opt
project_cpp_args += args_msvc_opt
project_link_args += [
'/NODEFAULTLIB:LIBCMT',
]
endif
else
if copt_platform == 'mac'

View File

@ -19,6 +19,7 @@
#endif
#include "Misc.h"
#include "client/Client.h"
namespace Platform
{
@ -80,11 +81,26 @@ void DoRestart()
if (exename.length())
{
#ifdef WIN
ShellExecute(NULL, "open", exename.c_str(), NULL, NULL, SW_SHOWNORMAL);
int ret = (int)ShellExecute(NULL, NULL, exename.c_str(), NULL, NULL, SW_SHOWNORMAL);
if (ret <= 32)
{
fprintf(stderr, "cannot restart: ShellExecute(...) failed: code %i\n", ret);
}
else
{
Client::Ref().Shutdown(); // very ugly hack; will fix soon(tm)
exit(0);
}
#elif defined(LIN) || defined(MACOSX)
execl(exename.c_str(), "powder", NULL);
int ret = errno;
fprintf(stderr, "cannot restart: execl(...) failed: code %i\n", ret);
#endif
}
else
{
fprintf(stderr, "cannot restart: no executable name???\n");
}
exit(-1);
}