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`.
This commit is contained in:
Vaxry 2024-04-28 22:25:24 +01:00 committed by GitHub
parent d20ee31210
commit a5a6480917
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 60 additions and 33 deletions

View File

@ -34,16 +34,16 @@ If your bug crashes Hyprland, append additionally:
## Obtaining the Hyprland log ## 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 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. 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 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) ## Obtaining the Hyprland Crash Report (v0.22.0beta and up)

View File

@ -8,6 +8,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/un.h> #include <sys/un.h>
#include <pwd.h>
#include <unistd.h> #include <unistd.h>
#include <ranges> #include <ranges>
#include <algorithm> #include <algorithm>
@ -41,21 +42,22 @@ struct SInstanceData {
std::vector<SInstanceData> instances() { std::vector<SInstanceData> instances() {
std::vector<SInstanceData> result; std::vector<SInstanceData> result;
for (const auto& el : std::filesystem::directory_iterator("/tmp/hypr")) { const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid);
if (el.is_directory() || !el.path().string().ends_with(".lock"))
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; continue;
// read lock // read lock
SInstanceData* data = &result.emplace_back(); SInstanceData* data = &result.emplace_back();
data->id = el.path().string(); 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 { 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))); 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; } } catch (std::exception& e) { continue; }
// read file // read file
std::ifstream ifs(el.path().string()); std::ifstream ifs(el.path().string() + "/hyprland.lock");
int i = 0; int i = 0;
for (std::string line; std::getline(ifs, line); ++i) { for (std::string line; std::getline(ifs, line); ++i) {
@ -99,10 +101,12 @@ void request(std::string arg, int minArgs = 0) {
return; return;
} }
sockaddr_un serverAddress = {0}; const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid);
serverAddress.sun_family = AF_UNIX;
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); 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}; sockaddr_un serverAddress = {0};
serverAddress.sun_family = AF_UNIX; 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); strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1);

View File

@ -16,8 +16,8 @@
#include "protocols/FractionalScale.hpp" #include "protocols/FractionalScale.hpp"
#include "protocols/PointerConstraints.hpp" #include "protocols/PointerConstraints.hpp"
#include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
int handleCritSignal(int signo, void* data) { int handleCritSignal(int signo, void* data) {
Debug::log(LOG, "Hyprland received signal {}", signo); Debug::log(LOG, "Hyprland received signal {}", signo);
@ -62,6 +62,16 @@ void handleUserSignal(int sig) {
CCompositor::CCompositor() { CCompositor::CCompositor() {
m_iHyprlandPID = getpid(); 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::random_device dev;
std::mt19937 engine(dev()); std::mt19937 engine(dev());
std::uniform_int_distribution<> distribution(0, INT32_MAX); std::uniform_int_distribution<> distribution(0, INT32_MAX);
@ -70,29 +80,31 @@ CCompositor::CCompositor() {
setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true); setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true);
if (!std::filesystem::exists("/tmp/hypr")) if (!std::filesystem::exists(m_szHyprTempDataRoot))
mkdir("/tmp/hypr", S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX); mkdir(m_szHyprTempDataRoot.c_str(), S_IRWXU);
else if (!std::filesystem::is_directory("/tmp/hypr")) { else if (!std::filesystem::is_directory(m_szHyprTempDataRoot)) {
std::cout << "Bailing out, /tmp/hypr is not a directory\n"; std::cout << "Bailing out, " << m_szHyprTempDataRoot << " is not a directory\n";
return; throw std::runtime_error("CCompositor() failed");
} }
const auto INSTANCEPATH = "/tmp/hypr/" + m_szInstanceSignature; m_szInstancePath = m_szHyprTempDataRoot + "/" + m_szInstanceSignature;
if (std::filesystem::exists(INSTANCEPATH)) { if (std::filesystem::exists(m_szInstancePath)) {
std::cout << "Bailing out, /tmp/hypr/$HIS exists??\n"; std::cout << "Bailing out, " << m_szInstancePath << " exists??\n";
return; throw std::runtime_error("CCompositor() failed");
} }
if (mkdir(INSTANCEPATH.c_str(), S_IRWXU) < 0) { if (mkdir(m_szInstancePath.c_str(), S_IRWXU) < 0) {
std::cout << "Bailing out, couldn't create /tmp/hypr/$HIS\n"; std::cout << "Bailing out, couldn't create " << m_szInstancePath << "\n";
return; throw std::runtime_error("CCompositor() failed");
} }
Debug::init(m_szInstanceSignature); Debug::init(m_szInstancePath);
Debug::log(LOG, "Instance Signature: {}", m_szInstanceSignature); Debug::log(LOG, "Instance Signature: {}", m_szInstanceSignature);
Debug::log(LOG, "Runtime directory: {}", m_szInstancePath);
Debug::log(LOG, "Hyprland PID: {}", m_iHyprlandPID); Debug::log(LOG, "Hyprland PID: {}", m_iHyprlandPID);
Debug::log(LOG, "===== SYSTEM INFO: ====="); Debug::log(LOG, "===== SYSTEM INFO: =====");
@ -519,7 +531,7 @@ void CCompositor::initManagers(eManagersInitStage stage) {
} }
void CCompositor::createLockFile() { 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); std::ofstream ofs(PATH, std::ios::trunc);
@ -529,7 +541,7 @@ void CCompositor::createLockFile() {
} }
void CCompositor::removeLockFile() { void CCompositor::removeLockFile() {
const auto PATH = "/tmp/hypr/" + m_szInstanceSignature + ".lock"; const auto PATH = m_szInstancePath + "/hyprland.lock";
if (std::filesystem::exists(PATH)) if (std::filesystem::exists(PATH))
std::filesystem::remove(PATH); std::filesystem::remove(PATH);

View File

@ -74,8 +74,11 @@ class CCompositor {
wlr_session_lock_manager_v1* m_sWLRSessionLockMgr; wlr_session_lock_manager_v1* m_sWLRSessionLockMgr;
// ------------------------------------------------- // // ------------------------------------------------- //
std::string m_szHyprTempDataRoot = "";
std::string m_szWLDisplaySocket = ""; std::string m_szWLDisplaySocket = "";
std::string m_szInstanceSignature = ""; std::string m_szInstanceSignature = "";
std::string m_szInstancePath = "";
std::string m_szCurrentSplash = "error"; std::string m_szCurrentSplash = "error";
std::vector<SP<CMonitor>> m_vMonitors; std::vector<SP<CMonitor>> m_vMonitors;

View File

@ -1746,7 +1746,7 @@ void CHyprCtl::startHyprCtlSocket() {
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX}; 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()); strcpy(SERVERADDRESS.sun_path, socketPath.c_str());

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
void Debug::init(const std::string& IS) { 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) { void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) {

View File

@ -97,8 +97,13 @@ int main(int argc, char** argv) {
// let's init the compositor. // let's init the compositor.
// it initializes basic Wayland stuff in the constructor. // it initializes basic Wayland stuff in the constructor.
g_pCompositor = std::make_unique<CCompositor>(); try {
g_pCompositor->explicitConfigPath = configPath; g_pCompositor = std::make_unique<CCompositor>();
g_pCompositor->explicitConfigPath = configPath;
} catch (std::exception& e) {
std::cout << "Hyprland threw in ctor: " << e.what() << "\nCannot continue.\n";
return 1;
}
g_pCompositor->initServer(); g_pCompositor->initServer();

View File

@ -39,7 +39,7 @@ void CEventManager::startThread() {
} }
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX}; 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); strncpy(SERVERADDRESS.sun_path, socketPath.c_str(), sizeof(SERVERADDRESS.sun_path) - 1);
bind(m_iSocketFD, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS)); bind(m_iSocketFD, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));

View File

@ -2,6 +2,7 @@
#include "../debug/Log.hpp" #include "../debug/Log.hpp"
#include "../helpers/VarList.hpp" #include "../helpers/VarList.hpp"
#include "../managers/TokenManager.hpp" #include "../managers/TokenManager.hpp"
#include "../Compositor.hpp"
#define register #define register
#include <udis86.h> #include <udis86.h>
@ -138,7 +139,7 @@ CFunctionHook::SAssembly CFunctionHook::fixInstructionProbeRIPCalls(const SInstr
currentAddress += len; 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)) { if (std::filesystem::exists(RANDOMDIR)) {
Debug::log(ERR, "[hooksystem] random out dir exists??"); Debug::log(ERR, "[hooksystem] random out dir exists??");