mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 16:25:59 +01:00
IPC and log changes, introduce signature
This commit is contained in:
parent
19b17b590c
commit
6f3b004199
8 changed files with 46 additions and 16 deletions
|
@ -45,12 +45,25 @@ void request(std::string arg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the instance signature
|
||||||
|
auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
|
||||||
|
if (!instanceSig) {
|
||||||
|
std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string instanceSigStr = std::string(instanceSig);
|
||||||
|
|
||||||
sockaddr_un serverAddress = {0};
|
sockaddr_un serverAddress = {0};
|
||||||
serverAddress.sun_family = AF_UNIX;
|
serverAddress.sun_family = AF_UNIX;
|
||||||
strcpy(serverAddress.sun_path, "/tmp/hypr/.socket.sock");
|
|
||||||
|
std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock";
|
||||||
|
|
||||||
|
strcpy(serverAddress.sun_path, socketPath.c_str());
|
||||||
|
|
||||||
if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
|
if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
|
||||||
std::cout << "Couldn't connect to /tmp/hypr/.socket.sock. (3) Is Hyprland running?";
|
std::cout << "Couldn't connect to " << socketPath << ". (3)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#include "Compositor.hpp"
|
#include "Compositor.hpp"
|
||||||
|
|
||||||
CCompositor::CCompositor() {
|
CCompositor::CCompositor() {
|
||||||
unlink("/tmp/hypr/hyprland.log");
|
m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL));
|
||||||
unlink("/tmp/hypr/hyprlandd.log");
|
|
||||||
unlink("/tmp/hypr/.hyprlandrq");
|
|
||||||
|
|
||||||
system("mkdir -p /tmp/hypr");
|
Debug::log(LOG, "Instance Signature: %s", m_szInstanceSignature.c_str());
|
||||||
|
|
||||||
|
setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true);
|
||||||
|
|
||||||
|
const auto INSTANCEPATH = "/tmp/hypr/" + m_szInstanceSignature;
|
||||||
|
mkdir(INSTANCEPATH.c_str(), S_IRWXU | S_IRWXG);
|
||||||
|
|
||||||
m_sWLDisplay = wl_display_create();
|
m_sWLDisplay = wl_display_create();
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
const char* m_szWLDisplaySocket;
|
const char* m_szWLDisplaySocket;
|
||||||
|
std::string m_szInstanceSignature = "";
|
||||||
|
|
||||||
std::list<SMonitor> m_lMonitors;
|
std::list<SMonitor> m_lMonitors;
|
||||||
std::list<CWindow> m_lWindows;
|
std::list<CWindow> m_lWindows;
|
||||||
|
|
|
@ -266,11 +266,11 @@ void HyprCtl::startHyprCtlSocket() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink("/tmp/hypr/.socket.sock");
|
|
||||||
|
|
||||||
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
||||||
|
|
||||||
strcpy(SERVERADDRESS.sun_path, "/tmp/hypr/.socket.sock");
|
std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket.sock";
|
||||||
|
|
||||||
|
strcpy(SERVERADDRESS.sun_path, socketPath.c_str());
|
||||||
|
|
||||||
bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ void HyprCtl::startHyprCtlSocket() {
|
||||||
|
|
||||||
char readBuffer[1024] = {0};
|
char readBuffer[1024] = {0};
|
||||||
|
|
||||||
Debug::log(LOG, "Hypr socket started.");
|
Debug::log(LOG, "Hypr socket started at %s", socketPath.c_str());
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
const auto ACCEPTEDCONNECTION = accept(SOCKET, (sockaddr*)&clientAddress, &clientSize);
|
const auto ACCEPTEDCONNECTION = accept(SOCKET, (sockaddr*)&clientAddress, &clientSize);
|
||||||
|
|
|
@ -4,12 +4,18 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
void Debug::init() {
|
||||||
|
if (ISDEBUG)
|
||||||
|
logFile = "/tmp/hypr/hyprlandd-" + std::to_string(time(NULL)) + ".log";
|
||||||
|
else
|
||||||
|
logFile = "/tmp/hypr/hyprland-" + std::to_string(time(NULL)) + ".log";
|
||||||
|
}
|
||||||
|
|
||||||
void Debug::log(LogLevel level, const char* fmt, ...) {
|
void Debug::log(LogLevel level, const char* fmt, ...) {
|
||||||
|
|
||||||
// log to a file
|
// log to a file
|
||||||
const std::string DEBUGPATH = ISDEBUG ? "/tmp/hypr/hyprlandd.log" : "/tmp/hypr/hyprland.log";
|
|
||||||
std::ofstream ofs;
|
std::ofstream ofs;
|
||||||
ofs.open(DEBUGPATH, std::ios::out | std::ios::app);
|
ofs.open(logFile, std::ios::out | std::ios::app);
|
||||||
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case LOG:
|
case LOG:
|
||||||
|
|
|
@ -12,5 +12,8 @@ enum LogLevel {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Debug {
|
namespace Debug {
|
||||||
|
void init();
|
||||||
void log(LogLevel level, const char* fmt, ...);
|
void log(LogLevel level, const char* fmt, ...);
|
||||||
|
|
||||||
|
inline std::string logFile;
|
||||||
};
|
};
|
|
@ -19,6 +19,10 @@ int main(int argc, char** argv) {
|
||||||
ignoreSudo = true;
|
ignoreSudo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
system("mkdir -p /tmp/hypr");
|
||||||
|
|
||||||
|
Debug::init();
|
||||||
|
|
||||||
if (!ignoreSudo) {
|
if (!ignoreSudo) {
|
||||||
if (Init::isSudo()) {
|
if (Init::isSudo()) {
|
||||||
Debug::log(CRIT, "Hyprland shall not be run as the root user. If you really want to, use the --i-am-really-stupid flag.");
|
Debug::log(CRIT, "Hyprland shall not be run as the root user. If you really want to, use the --i-am-really-stupid flag.");
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "EventManager.hpp"
|
#include "EventManager.hpp"
|
||||||
|
#include "../Compositor.hpp"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -26,10 +27,9 @@ void CEventManager::startThread() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink("/tmp/hypr/.socket2.sock");
|
|
||||||
|
|
||||||
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
||||||
strcpy(SERVERADDRESS.sun_path, "/tmp/hypr/.socket2.sock");
|
std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket2.sock";
|
||||||
|
strcpy(SERVERADDRESS.sun_path, socketPath.c_str());
|
||||||
|
|
||||||
bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ void CEventManager::startThread() {
|
||||||
sockaddr_in clientAddress;
|
sockaddr_in clientAddress;
|
||||||
socklen_t clientSize = sizeof(clientAddress);
|
socklen_t clientSize = sizeof(clientAddress);
|
||||||
|
|
||||||
Debug::log(LOG, "Hypr socket 2 started.");
|
Debug::log(LOG, "Hypr socket 2 started at %s", socketPath.c_str());
|
||||||
|
|
||||||
// set the socket nonblock
|
// set the socket nonblock
|
||||||
int flags = fcntl(SOCKET, F_GETFL, 0);
|
int flags = fcntl(SOCKET, F_GETFL, 0);
|
||||||
|
|
Loading…
Reference in a new issue