Skip to content

Commit

Permalink
Add a flag for when the process is terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangz committed Apr 9, 2015
1 parent 1e4bae0 commit fd9a63e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
15 changes: 14 additions & 1 deletion src/common/System.cpp
Expand Up @@ -314,6 +314,17 @@ intptr_t DynamicLib::InternalLoadSym(Str::StringRef sym, std::string& errorStrin
} }
#endif // __native_client__ #endif // __native_client__


bool processTerminating = false;

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

bool IsProcessTerminating() {
return processTerminating;
}

} // namespace Sys } // namespace Sys


// Global operator new/delete override to not throw an exception when out of // Global operator new/delete override to not throw an exception when out of
Expand All @@ -327,5 +338,7 @@ void* operator new(size_t n)
} }
void operator delete(void* p) NOEXCEPT void operator delete(void* p) NOEXCEPT
{ {
free(p); if (!Sys::processTerminating) {
free(p);
}
} }
4 changes: 4 additions & 0 deletions src/common/System.h
Expand Up @@ -165,6 +165,10 @@ class DynamicLib {
}; };
#endif // __native_client__ #endif // __native_client__


void OSExit(int exitCode);

bool IsProcessTerminating();

} // namespace Sys } // namespace Sys


#endif // COMMON_SYSTEM_H_ #endif // COMMON_SYSTEM_H_
10 changes: 5 additions & 5 deletions src/engine/framework/System.cpp
Expand Up @@ -307,7 +307,7 @@ void Quit(Str::StringRef message)
{ {
Shutdown(false, message); Shutdown(false, message);


exit(0); OSExit(0);
} }


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


Shutdown(true, message); Shutdown(true, message);


exit(1); OSExit(1);
} }


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


// Create the singleton socket and a thread to watch it // Create the singleton socket and a thread to watch it
Expand Down
2 changes: 1 addition & 1 deletion src/engine/qcommon/common.cpp
Expand Up @@ -1564,7 +1564,7 @@ A way to force a bus error for development reasons
static void NORETURN Com_Crash_f( void ) static void NORETURN Com_Crash_f( void )
{ {
* ( volatile int * ) 0 = 0x12345678; * ( volatile int * ) 0 = 0x12345678;
exit( 1 ); // silence warning Sys::OSExit(1); // silence warning
} }


void Com_SetRecommended( void ) void Com_SetRecommended( void )
Expand Down
4 changes: 2 additions & 2 deletions src/gamelogic/shared/VMMain.cpp
Expand Up @@ -122,13 +122,13 @@ int main(int argc, char** argv)
// The socket handle is sent as the first argument // The socket handle is sent as the first argument
if (argc != 2) { 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"); 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; char* end;
Sys::OSHandle rootSocket = (Sys::OSHandle)strtol(argv[1], &end, 10); Sys::OSHandle rootSocket = (Sys::OSHandle)strtol(argv[1], &end, 10);
if (argv[1] == end || *end != '\0') { if (argv[1] == end || *end != '\0') {
fprintf(stderr, "Parameter is not a valid handle number\n"); 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 // Set up crash handling for this process. This will allow crashes to be
Expand Down

0 comments on commit fd9a63e

Please sign in to comment.