diff --git a/CMakeLists.txt b/CMakeLists.txt index bf41ffd..0f3a5a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,6 @@ qt_add_executable(hyprpolkitagent src/core/PolkitListener.cpp src/QMLIntegration.cpp src/QMLIntegration.hpp - src/SigDaemon.hpp - src/SigDaemon.cpp ) qt_add_qml_module(hyprpolkitagent @@ -42,8 +40,6 @@ qt_add_qml_module(hyprpolkitagent SOURCES src/QMLIntegration.cpp src/QMLIntegration.hpp - src/SigDaemon.hpp - src/SigDaemon.cpp ) target_link_libraries(hyprpolkitagent diff --git a/src/SigDaemon.cpp b/src/SigDaemon.cpp deleted file mode 100644 index 198f59d..0000000 --- a/src/SigDaemon.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "SigDaemon.hpp" -#include "core/Agent.hpp" - -#include - -#include -#include - -static int sighupFd[2]; -static int sigtermFd[2]; -static int sigintFd[2]; - -// -void CSigDaemon::onSignal(int signo) { - char a = 1; - if (signo == SIGHUP) - ::write(sighupFd[0], &a, sizeof(a)); - else if (signo == SIGINT) - ::write(sigintFd[0], &a, sizeof(a)); - else if (signo == SIGTERM) - ::write(sigtermFd[0], &a, sizeof(a)); -} - -CSigDaemon::CSigDaemon(QObject* parent) : QObject(parent) { - if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sighupFd)) - qFatal("Couldn't create HUP socketpair"); - if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd)) - qFatal("Couldn't create TERM socketpair"); - if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigintFd)) - qFatal("Couldn't create INT socketpair"); - snHup = new QSocketNotifier(sighupFd[1], QSocketNotifier::Read, this); - connect(snHup, SIGNAL(activated(QSocketDescriptor)), this, SLOT(handleSigHup())); - snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this); - connect(snTerm, SIGNAL(activated(QSocketDescriptor)), this, SLOT(handleSigTerm())); - snInt = new QSocketNotifier(sigintFd[1], QSocketNotifier::Read, this); - connect(snInt, SIGNAL(activated(QSocketDescriptor)), this, SLOT(handleSigInt())); - - struct sigaction sa; - - sa.sa_handler = onSignal; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_flags |= SA_RESTART; - - if (sigaction(SIGHUP, &sa, 0)) - std::print(stderr, "sigaction for hup failed\n"); - - if (sigaction(SIGTERM, &sa, 0)) - std::print(stderr, "sigaction for term failed\n"); - - if (sigaction(SIGINT, &sa, 0)) - std::print(stderr, "sigaction for int failed\n"); -} - -void CSigDaemon::handleSigHup() { - std::print("> signal received: SIGHUP\n"); - snHup->setEnabled(false); - char tmp; - ::read(sighupFd[1], &tmp, sizeof(tmp)); - g_pAgent->resetAuthState(); - snHup->setEnabled(true); -} - -void CSigDaemon::handleSigInt() { - std::print("> signal received: SIGINT\n"); - snInt->setEnabled(false); - char tmp; - ::read(sigintFd[1], &tmp, sizeof(tmp)); - g_pAgent->resetAuthState(); - snInt->setEnabled(true); - exit(0); -} - -void CSigDaemon::handleSigTerm() { - std::print("> signal received: SIGTERM\n"); - snTerm->setEnabled(false); - char tmp; - ::read(sigtermFd[1], &tmp, sizeof(tmp)); - g_pAgent->resetAuthState(); - snTerm->setEnabled(true); -} diff --git a/src/SigDaemon.hpp b/src/SigDaemon.hpp deleted file mode 100644 index 19c14a5..0000000 --- a/src/SigDaemon.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -class CSigDaemon : public QObject { - Q_OBJECT; - - public: - CSigDaemon(QObject* parent = nullptr); - - static void onSignal(int signo); - - public slots: - void handleSigHup(); - void handleSigTerm(); - void handleSigInt(); - - private: - QSocketNotifier* snHup = nullptr; - QSocketNotifier* snTerm = nullptr; - QSocketNotifier* snInt = nullptr; -}; diff --git a/src/core/Agent.cpp b/src/core/Agent.cpp index 531c0f5..c9a7825 100644 --- a/src/core/Agent.cpp +++ b/src/core/Agent.cpp @@ -5,7 +5,6 @@ #include "Agent.hpp" #include "../QMLIntegration.hpp" -#include "../SigDaemon.hpp" CAgent::CAgent() { ; @@ -24,8 +23,6 @@ bool CAgent::start() { char* argv = (char*)"hyprpolkitagent"; QApplication app(argc, &argv); - sigDaemon = makeShared(); - app.setApplicationName("Hyprland Polkit Agent"); QGuiApplication::setQuitOnLastWindowClosed(false); diff --git a/src/core/Agent.hpp b/src/core/Agent.hpp index 29aa782..4d9d74d 100644 --- a/src/core/Agent.hpp +++ b/src/core/Agent.hpp @@ -15,7 +15,6 @@ using namespace Hyprutils::Memory; #define WP CWeakPointer class CQMLIntegration; -class CSigDaemon; class CAgent { public: @@ -40,7 +39,6 @@ class CAgent { } lastAuthResult; CPolkitListener listener; - SP sigDaemon; SP sessionSubject; bool resultReady();