summaryrefslogtreecommitdiff
path: root/src/debug/HyprCtl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug/HyprCtl.cpp')
-rw-r--r--src/debug/HyprCtl.cpp51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index a7e714bd..70b886f2 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -28,6 +28,7 @@ using namespace Hyprutils::String;
#include "../devices/IKeyboard.hpp"
#include "../devices/ITouch.hpp"
#include "../devices/Tablet.hpp"
+#include "debug/RollingLogFollow.hpp"
#include "config/ConfigManager.hpp"
#include "helpers/MiscFunctions.hpp"
@@ -1732,6 +1733,46 @@ std::string CHyprCtl::makeDynamicCall(const std::string& input) {
return getReply(input);
}
+bool successWrite(int fd, const std::string& data, bool needLog = true) {
+ if (write(fd, data.c_str(), data.length()) > 0)
+ return true;
+
+ if (errno == EAGAIN)
+ return true;
+
+ if (needLog)
+ Debug::log(ERR, "Couldn't write to socket. Error: " + std::string(strerror(errno)));
+
+ return false;
+}
+
+void runWritingDebugLogThread(const int conn) {
+ using namespace std::chrono_literals;
+ Debug::log(LOG, "In followlog thread, got connection, start writing: {}", conn);
+ //will be finished, when reading side close connection
+ std::thread([conn]() {
+ while (Debug::RollingLogFollow::Get().IsRunning()) {
+ if (Debug::RollingLogFollow::Get().isEmpty(conn)) {
+ std::this_thread::sleep_for(1000ms);
+ continue;
+ }
+
+ auto line = Debug::RollingLogFollow::Get().GetLog(conn);
+ if (!successWrite(conn, line))
+ // We cannot write, when connection is closed. So thread will successfully exit by itself
+ break;
+
+ std::this_thread::sleep_for(100ms);
+ }
+ close(conn);
+ Debug::RollingLogFollow::Get().StopFor(conn);
+ }).detach();
+}
+
+bool isFollowUpRollingLogRequest(const std::string& request) {
+ return request.contains("rollinglog") && request.contains("f");
+}
+
int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP)
return 0;
@@ -1775,9 +1816,15 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
reply = "Err: " + std::string(e.what());
}
- write(ACCEPTEDCONNECTION, reply.c_str(), reply.length());
+ successWrite(ACCEPTEDCONNECTION, reply);
- close(ACCEPTEDCONNECTION);
+ if (isFollowUpRollingLogRequest(request)) {
+ Debug::log(LOG, "Followup rollinglog request received. Starting thread to write to socket.");
+ Debug::RollingLogFollow::Get().StartFor(ACCEPTEDCONNECTION);
+ runWritingDebugLogThread(ACCEPTEDCONNECTION);
+ Debug::log(LOG, Debug::RollingLogFollow::Get().DebugInfo());
+ } else
+ close(ACCEPTEDCONNECTION);
if (g_pConfigManager->m_bWantsMonitorReload)
g_pConfigManager->ensureMonitorStatus();