From a5a648091760ac002120fab18247e5292b6482de Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:25:24 +0100 Subject: core: Move /tmp/hypr to $XDG_RUNTIME_DIR/hypr (#5788) Moves the directory containing sockets and logs. Also restructures lockfiles a bit. For consumers, check if `$XDG_RUNTIME_DIR/hypr` exists. If so, use it. If not, use the old `/tmp/hypr`. --- src/Compositor.cpp | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d252dda2..d178215c 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -16,8 +16,8 @@ #include "protocols/FractionalScale.hpp" #include "protocols/PointerConstraints.hpp" -#include #include +#include int handleCritSignal(int signo, void* data) { Debug::log(LOG, "Hyprland received signal {}", signo); @@ -62,6 +62,16 @@ void handleUserSignal(int sig) { CCompositor::CCompositor() { m_iHyprlandPID = getpid(); + m_szHyprTempDataRoot = std::string{getenv("XDG_RUNTIME_DIR")} + "/hypr"; + + if (m_szHyprTempDataRoot.starts_with("/hypr")) { + std::cout << "Bailing out, XDG_RUNTIME_DIR is invalid\n"; + throw std::runtime_error("CCompositor() failed"); + } + + if (!m_szHyprTempDataRoot.starts_with("/run/user")) + std::cout << "[!!WARNING!!] XDG_RUNTIME_DIR looks non-standard. Proceeding anyways...\n"; + 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); -- cgit v1.2.3