Skip to content
Permalink
Browse files

Add a flag for when the process is terminating

  • Loading branch information...
Kangz committed Apr 2, 2015
1 parent 1e4bae0 commit fd9a63ebfbca0b4a41ced285f031fc3ef85e6968
@@ -314,6 +314,17 @@ intptr_t DynamicLib::InternalLoadSym(Str::StringRef sym, std::string& errorStrin
}
#endif // __native_client__

bool processTerminating = false;

void OSExit(int exitCode) {
processTerminating = true;
exit(exitCode);
}

bool IsProcessTerminating() {
return processTerminating;
}

} // namespace Sys

// Global operator new/delete override to not throw an exception when out of
@@ -327,5 +338,7 @@ void* operator new(size_t n)
}
void operator delete(void* p) NOEXCEPT
{
free(p);
if (!Sys::processTerminating) {
free(p);
}
}
@@ -165,6 +165,10 @@ class DynamicLib {
};
#endif // __native_client__

void OSExit(int exitCode);

bool IsProcessTerminating();

} // namespace Sys

#endif // COMMON_SYSTEM_H_
@@ -307,7 +307,7 @@ void Quit(Str::StringRef message)
{
Shutdown(false, message);

exit(0);
OSExit(0);
}

void Error(Str::StringRef message)
@@ -325,7 +325,7 @@ void Error(Str::StringRef message)

Shutdown(true, message);

exit(1);
OSExit(1);
}

// Translate non-fatal signals into a quit command
@@ -463,10 +463,10 @@ static void ParseCmdline(int argc, char** argv, cmdlineArgs_t& cmdlineArgs)
" -set <variable> <value> set the value of a cvar\n"
" +<command> <args> execute an ingame command after startup\n"
);
exit(0);
OSExit(0);
} else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-version")) {
printf(PRODUCT_NAME " " PRODUCT_VERSION "\n");
exit(0);
OSExit(0);
} else if (!strcmp(argv[i], "-set")) {
if (i >= argc - 2) {
Log::Warn("Missing argument for -set");
@@ -604,7 +604,7 @@ static void Init(int argc, char** argv)
close(singletonSocket);
#endif
CON_Shutdown();
exit(0);
OSExit(0);
}

// Create the singleton socket and a thread to watch it
@@ -1564,7 +1564,7 @@ A way to force a bus error for development reasons
static void NORETURN Com_Crash_f( void )
{
* ( volatile int * ) 0 = 0x12345678;
exit( 1 ); // silence warning
Sys::OSExit(1); // silence warning
}

void Com_SetRecommended( void )
@@ -122,13 +122,13 @@ int main(int argc, char** argv)
// The socket handle is sent as the first argument
if (argc != 2) {
fprintf(stderr, "This program is not meant to be invoked directly, it must be invoked by the engine's VM loader.\n");
exit(1);
OSExit(1);
}
char* end;
Sys::OSHandle rootSocket = (Sys::OSHandle)strtol(argv[1], &end, 10);
if (argv[1] == end || *end != '\0') {
fprintf(stderr, "Parameter is not a valid handle number\n");
exit(1);
OSExit(1);
}

// Set up crash handling for this process. This will allow crashes to be

0 comments on commit fd9a63e

Please sign in to comment.
You can’t perform that action at this time.