Skip to content

Commit

Permalink
Kill child process (#57)
Browse files Browse the repository at this point in the history
* Kill child process on detour error

* Update version
  • Loading branch information
mwasplund authored Aug 5, 2020
1 parent 4115e80 commit 1d83da1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Source/Client/CLI/Commands/VersionCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Soup::Client

// TODO var version = Assembly.GetExecutingAssembly().GetName().Version;
// Log::Message($"{version.Major}.{version.Minor}.{version.Build}");
Log::HighPriority("0.8.4");
Log::HighPriority("0.8.5");
}

private:
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/CLI/Recipe.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name = "Soup"
Version = "0.8.4"
Version = "0.8.5"
Type = "Executable"

# Ensure the core build extensions are runtime dependencies
Expand Down
21 changes: 14 additions & 7 deletions Source/Monitor/Detours/EventLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class EventLogger
static void Shutdown()
{
auto lock = std::lock_guard<std::mutex>(s_pipeMutex);
Monitor::DetourMessage message;
message.Type = Monitor::DetourMessageType::Info_Shutdown;
message.ContentSize = 0;
UnsafeWriteMessage(message);

if (s_pipeHandle != INVALID_HANDLE_VALUE)
{
Monitor::DetourMessage message;
message.Type = Monitor::DetourMessageType::Info_Shutdown;
message.ContentSize = 0;
UnsafeWriteMessage(message);
FlushFileBuffers(s_pipeHandle);
CloseHandle(s_pipeHandle);
s_pipeHandle = INVALID_HANDLE_VALUE;
Expand Down Expand Up @@ -122,11 +123,13 @@ class EventLogger

static void WriteError(std::string_view value)
{
printf("DETOURS-ERROR: %s\n", value.data());

Monitor::DetourMessage message;
message.Type = Monitor::DetourMessageType::Info_Error;
message.ContentSize = 0;
AppendValue(message, value.data());
UnsafeWriteMessage(message);
WriteMessage(message);
}

static void WriteMessage(const Monitor::DetourMessage& message)
Expand Down Expand Up @@ -194,11 +197,15 @@ class EventLogger
&countBytesWritten,
nullptr))
{
throw std::runtime_error("Failed write event logger");
printf("DETOURS-ERROR: Failed write event logger\n", (uint32_t)message.Type);
exit(-1234);
}

if (countBytesWritten != countBytesToWrite)
throw std::runtime_error("Did not write the expected number of bytes");
{
printf("Did not write the expected number of bytes\n", (uint32_t)message.Type);
exit(-1234);
}
}

private:
Expand Down
4 changes: 4 additions & 0 deletions Source/Monitor/Detours/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,12 @@ bool ProcessAttach(HMODULE hDll)
catch (const std::exception& ex)
{
EventLogger::WriteError(ex.what());
exit(-1234);
}
catch (...)
{
EventLogger::WriteError("Unknown error attaching detours");
exit(-1234);
}

ThreadAttach(hDll);
Expand All @@ -566,10 +568,12 @@ bool ProcessDetach(HMODULE hDll)
catch (const std::exception& ex)
{
EventLogger::WriteError(ex.what());
exit(-1234);
}
catch (...)
{
EventLogger::WriteError("Unknown error detaching detours");
exit(-1234);
}

EventLogger::Shutdown();
Expand Down

0 comments on commit 1d83da1

Please sign in to comment.