Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability changes #3

Merged
merged 6 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#include <chrono>
#include <dirent.h>
#include <dlfcn.h>
#include <filesystem>
#include <linux/fcntl.h>
#include <mutex>
#include <sys/socket.h>
#include <systemd/sd-journal.h>
#include <thread>
#include <unistd.h>
#include <sys/prctl.h>
#include <condition_variable>

#define forever for(;;)

namespace {
static int(*func_open)(const char*, int, mode_t) = nullptr;
static std::mutex logMutex;
std::condition_variable stateThreadCondition;
std::mutex stateThreadConditionMutex;
static std::thread stateThread;
static std::atomic<bool> stateThreadRunning = false;
static bool exitThread = false;
Expand Down Expand Up @@ -112,7 +114,11 @@ namespace {
_WARN("Unknown power state call: %s", data.c_str());
}
}
stateThreadRunning = false;
{
[[maybe_unused]] std::lock_guard<std::mutex> lock(stateThreadConditionMutex);
stateThreadRunning = false;
stateThreadCondition.notify_one();
}
}

int __open(const char* pathname, int flags){
Expand Down Expand Up @@ -218,10 +224,15 @@ extern "C" {
rtld_fini,
stack_end
);
if(stateThreadRunning){
_DEBUG("Waiting for thread to exit");
exitThread = true;
stateThread.join();
exitThread = true;
Eeems marked this conversation as resolved.
Show resolved Hide resolved
_DEBUG("Waiting for thread to exit");
{
std::unique_lock<std::mutex> lock(stateThreadConditionMutex);
if(!stateThreadCondition.wait_for(lock, std::chrono::seconds(5), []{
return !stateThreadRunning;
})){
_WARN("Timeout waiting for state thread to exit");
Eeems marked this conversation as resolved.
Show resolved Hide resolved
}
}
return res;
}
Expand Down
Loading