From 35cb7f4c3b77850bf4198a34ac9f06dacfba475a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 28 Apr 2024 22:01:55 +0100 Subject: [PATCH] Move /tmp/hypr to XDG_RUNTIME_DIR --- docs/ISSUE_GUIDELINES.md | 6 ++--- hyprctl/main.cpp | 22 +++++++++++------- src/Compositor.cpp | 44 ++++++++++++++++++++++------------- src/Compositor.hpp | 3 +++ src/debug/HyprCtl.cpp | 2 +- src/debug/Log.cpp | 2 +- src/main.cpp | 9 +++++-- src/managers/EventManager.cpp | 2 +- src/plugins/HookSystem.cpp | 3 ++- 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/docs/ISSUE_GUIDELINES.md b/docs/ISSUE_GUIDELINES.md index c031fe85..2f6cbbf8 100644 --- a/docs/ISSUE_GUIDELINES.md +++ b/docs/ISSUE_GUIDELINES.md @@ -34,16 +34,16 @@ If your bug crashes Hyprland, append additionally: ## Obtaining the Hyprland log If you are in a TTY, and the hyprland session that crashed was the last one you launched, the log will be printed with ``` -cat /tmp/hypr/$(ls -t /tmp/hypr/ | head -n 1)/hyprland.log +cat $XDG_RUNTIME_DIR/hypr/$(ls -t $XDG_RUNTIME_DIR/hypr | head -n 1)/hyprland.log ``` feel free to send it to a file, save, copy, etc. if you are in a Hyprland session, and you want the log of the last session, use ``` -cat /tmp/hypr/$(ls -t /tmp/hypr/ | head -n 2 | tail -n 1)/hyprland.log +cat $XDG_RUNTIME_DIR/hypr/$(ls -t $XDG_RUNTIME_DIR/hypr | head -n 2 | tail -n 1)/hyprland.log ``` -basically, directories in /tmp/hypr are your sessions. +basically, directories in $XDG_RUNTIME_DIR/hypr are your sessions. ## Obtaining the Hyprland Crash Report (v0.22.0beta and up) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 9b2c2fd2..a06a3899 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -41,21 +42,22 @@ struct SInstanceData { std::vector instances() { std::vector result; - for (const auto& el : std::filesystem::directory_iterator("/tmp/hypr")) { - if (el.is_directory() || !el.path().string().ends_with(".lock")) + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + + for (const auto& el : std::filesystem::directory_iterator("/run/user/" + USERID + "/hypr")) { + if (!el.is_directory() || !std::filesystem::exists(el.path().string() + "/hyprland.lock")) continue; // read lock SInstanceData* data = &result.emplace_back(); data->id = el.path().string(); - data->id = data->id.substr(data->id.find_last_of('/') + 1, data->id.find(".lock") - data->id.find_last_of('/') - 1); try { data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1, data->id.find_last_of('_') - (data->id.find_first_of('_') + 1))); } catch (std::exception& e) { continue; } // read file - std::ifstream ifs(el.path().string()); + std::ifstream ifs(el.path().string() + "/hyprland.lock"); int i = 0; for (std::string line; std::getline(ifs, line); ++i) { @@ -99,10 +101,12 @@ void request(std::string arg, int minArgs = 0) { return; } - sockaddr_un serverAddress = {0}; - serverAddress.sun_family = AF_UNIX; + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); - std::string socketPath = "/tmp/hypr/" + instanceSignature + "/.socket.sock"; + sockaddr_un serverAddress = {0}; + serverAddress.sun_family = AF_UNIX; + + std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.socket.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); @@ -160,7 +164,9 @@ void requestHyprpaper(std::string arg) { sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; - std::string socketPath = "/tmp/hypr/" + instanceSignature + "/.hyprpaper.sock"; + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + + std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.hyprpaper.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d252dda2..0f3ad981 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -16,8 +16,9 @@ #include "protocols/FractionalScale.hpp" #include "protocols/PointerConstraints.hpp" -#include #include +#include +#include int handleCritSignal(int signo, void* data) { Debug::log(LOG, "Hyprland received signal {}", signo); @@ -62,6 +63,15 @@ void handleUserSignal(int sig) { CCompositor::CCompositor() { m_iHyprlandPID = getpid(); + const auto PWUID = getpwuid(getuid()); + if (!PWUID) { + std::cout << "Bailing out, getpwuid(getuid()) failed. Are you running as a proper user?\n"; + throw std::runtime_error("CCompositor() failed"); + } + + const std::string USERID = std::to_string(PWUID->pw_uid); + m_szHyprTempDataRoot = "/run/user/" + USERID + "/hypr"; + std::random_device dev; std::mt19937 engine(dev()); std::uniform_int_distribution<> distribution(0, INT32_MAX); @@ -70,29 +80,31 @@ CCompositor::CCompositor() { setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true); - if (!std::filesystem::exists("/tmp/hypr")) - mkdir("/tmp/hypr", S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX); - else if (!std::filesystem::is_directory("/tmp/hypr")) { - std::cout << "Bailing out, /tmp/hypr is not a directory\n"; - return; + if (!std::filesystem::exists(m_szHyprTempDataRoot)) + mkdir(m_szHyprTempDataRoot.c_str(), S_IRWXU); + else if (!std::filesystem::is_directory(m_szHyprTempDataRoot)) { + std::cout << "Bailing out, " << m_szHyprTempDataRoot << " is not a directory\n"; + throw std::runtime_error("CCompositor() failed"); } - const auto INSTANCEPATH = "/tmp/hypr/" + m_szInstanceSignature; + m_szInstancePath = m_szHyprTempDataRoot + "/" + m_szInstanceSignature; - if (std::filesystem::exists(INSTANCEPATH)) { - std::cout << "Bailing out, /tmp/hypr/$HIS exists??\n"; - return; + if (std::filesystem::exists(m_szInstancePath)) { + std::cout << "Bailing out, " << m_szInstancePath << " exists??\n"; + throw std::runtime_error("CCompositor() failed"); } - if (mkdir(INSTANCEPATH.c_str(), S_IRWXU) < 0) { - std::cout << "Bailing out, couldn't create /tmp/hypr/$HIS\n"; - return; + if (mkdir(m_szInstancePath.c_str(), S_IRWXU) < 0) { + std::cout << "Bailing out, couldn't create " << m_szInstancePath << "\n"; + throw std::runtime_error("CCompositor() failed"); } - Debug::init(m_szInstanceSignature); + Debug::init(m_szInstancePath); Debug::log(LOG, "Instance Signature: {}", m_szInstanceSignature); + Debug::log(LOG, "Runtime directory: {}", m_szInstancePath); + Debug::log(LOG, "Hyprland PID: {}", m_iHyprlandPID); Debug::log(LOG, "===== SYSTEM INFO: ====="); @@ -519,7 +531,7 @@ void CCompositor::initManagers(eManagersInitStage stage) { } void CCompositor::createLockFile() { - const auto PATH = "/tmp/hypr/" + m_szInstanceSignature + ".lock"; + const auto PATH = m_szInstancePath + "/hyprland.lock"; std::ofstream ofs(PATH, std::ios::trunc); @@ -529,7 +541,7 @@ void CCompositor::createLockFile() { } void CCompositor::removeLockFile() { - const auto PATH = "/tmp/hypr/" + m_szInstanceSignature + ".lock"; + const auto PATH = m_szInstancePath + "/hyprland.lock"; if (std::filesystem::exists(PATH)) std::filesystem::remove(PATH); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index c118538e..47ffc7cf 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -74,8 +74,11 @@ class CCompositor { wlr_session_lock_manager_v1* m_sWLRSessionLockMgr; // ------------------------------------------------- // + std::string m_szHyprTempDataRoot = ""; + std::string m_szWLDisplaySocket = ""; std::string m_szInstanceSignature = ""; + std::string m_szInstancePath = ""; std::string m_szCurrentSplash = "error"; std::vector> m_vMonitors; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 7f09eb18..ce2f5c45 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1746,7 +1746,7 @@ void CHyprCtl::startHyprCtlSocket() { sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX}; - std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket.sock"; + std::string socketPath = g_pCompositor->m_szInstancePath + "/.socket.sock"; strcpy(SERVERADDRESS.sun_path, socketPath.c_str()); diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index 32d235e1..9fdf47f8 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -6,7 +6,7 @@ #include void Debug::init(const std::string& IS) { - logFile = "/tmp/hypr/" + IS + (ISDEBUG ? "/hyprlandd.log" : "/hyprland.log"); + logFile = IS + (ISDEBUG ? "/hyprlandd.log" : "/hyprland.log"); } void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) { diff --git a/src/main.cpp b/src/main.cpp index e1f43ad0..7e6fee02 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,8 +97,13 @@ int main(int argc, char** argv) { // let's init the compositor. // it initializes basic Wayland stuff in the constructor. - g_pCompositor = std::make_unique(); - g_pCompositor->explicitConfigPath = configPath; + try { + g_pCompositor = std::make_unique(); + g_pCompositor->explicitConfigPath = configPath; + } catch (std::exception& e) { + std::cout << "Hyprland threw in ctor: " << e.what() << "\nCannot continue.\n"; + return 1; + } g_pCompositor->initServer(); diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp index 57824430..8605768c 100644 --- a/src/managers/EventManager.cpp +++ b/src/managers/EventManager.cpp @@ -39,7 +39,7 @@ void CEventManager::startThread() { } sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX}; - std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket2.sock"; + std::string socketPath = g_pCompositor->m_szInstancePath + "/.socket2.sock"; strncpy(SERVERADDRESS.sun_path, socketPath.c_str(), sizeof(SERVERADDRESS.sun_path) - 1); bind(m_iSocketFD, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS)); diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp index 2b1f1193..2fee1bc5 100644 --- a/src/plugins/HookSystem.cpp +++ b/src/plugins/HookSystem.cpp @@ -2,6 +2,7 @@ #include "../debug/Log.hpp" #include "../helpers/VarList.hpp" #include "../managers/TokenManager.hpp" +#include "../Compositor.hpp" #define register #include @@ -138,7 +139,7 @@ CFunctionHook::SAssembly CFunctionHook::fixInstructionProbeRIPCalls(const SInstr currentAddress += len; } - const auto RANDOMDIR = "/tmp/hypr/" + g_pTokenManager->getRandomUUID(); + const auto RANDOMDIR = g_pCompositor->m_szInstancePath + "/" + g_pTokenManager->getRandomUUID(); if (std::filesystem::exists(RANDOMDIR)) { Debug::log(ERR, "[hooksystem] random out dir exists??");