Skip to content

Commit

Permalink
netlink: improved event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Sep 10, 2024
1 parent 3a8daae commit c3ff334
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/fastgame_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,20 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {

// nl->new_exit.connect([&](int pid) {});

auto check_lock_file = [&]() {
while (std::filesystem::is_regular_file(input_file)) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
// auto check_lock_file = [&]() {
// while (std::filesystem::is_regular_file(input_file)) {
// std::this_thread::sleep_for(std::chrono::seconds(1));
// }

util::info("The lock file has been removed. Exitting the lock thread.");
// util::info("The lock file has been removed. Exitting the lock thread.");

nl->listen = false;
};
// nl->listen = false;
// };

if (nl->listen) {
std::thread t(check_lock_file);
// std::thread t(check_lock_file);

t.detach();
// t.detach();

nl->handle_events(); // This is a blocking call. It has to be started at the end

Expand Down
6 changes: 6 additions & 0 deletions src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ void Netlink::handle_events() {
.msg_controllen = 0,
.msg_flags = 0};

auto input_file = std::filesystem::temp_directory_path() / std::filesystem::path{"fastgame.json"};

while (listen) {
if (!std::filesystem::is_regular_file(input_file)) {
return;
}

auto len = recvmsg(nl_socket, &msg_hdr, 0);

if (len == -1) {
Expand Down
9 changes: 2 additions & 7 deletions src/presets_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,9 @@ bool Backend::applySettings() {
save_preset("fastgame", std::filesystem::temp_directory_path());

try {
std::thread t([]() {
// std::system("pkexec fastgame_apply");
boost::process::child c(boost::process::search_path("pkexec"), "fastgame_apply");
boost::process::child c(boost::process::search_path("pkexec"), "fastgame_apply");

c.wait();
});

t.detach();
c.detach();

Q_EMIT settingsApplied();
} catch (std::exception& e) {
Expand Down

0 comments on commit c3ff334

Please sign in to comment.