Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions src/common/SignalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
namespace DDM {
int sigintFd[2];
int sigtermFd[2];
int sigcustomFd[2];

SignalHandler::SignalHandler(QObject *parent) : QObject(parent) {
initialize();
Expand All @@ -45,27 +44,19 @@ namespace DDM {

snterm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
connect(snterm, &QSocketNotifier::activated, this, &SignalHandler::handleSigterm);

sncustom = new QSocketNotifier(sigcustomFd[1], QSocketNotifier::Read, this);
connect(sncustom, &QSocketNotifier::activated, this, &SignalHandler::handleSigCustom);
}

SignalHandler::~SignalHandler() {
struct sigaction sa_default;
sa_default.sa_handler = SIG_DFL;
sigaction(SIGINT, &sa_default, NULL);
sigaction(SIGTERM, &sa_default, NULL);
for (int signal : customSignals)
sigaction(signal, &sa_default, NULL);
snint->setEnabled(false);
snterm->setEnabled(false);
sncustom->setEnabled(false);
::close(sigintFd[0]);
::close(sigintFd[1]);
::close(sigtermFd[0]);
::close(sigtermFd[1]);
::close(sigcustomFd[0]);
::close(sigcustomFd[1]);
}

void SignalHandler::initialize() {
Expand Down Expand Up @@ -95,31 +86,6 @@ namespace DDM {
return;
}

if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sigcustomFd))
qCritical() << "Failed to create socket pair for custom signals handling.";
}

void SignalHandler::addCustomSignal(int signal)
{
struct sigaction sigcustom = { };
sigcustom.sa_handler = SignalHandler::customSignalHandler;
sigemptyset(&sigcustom.sa_mask);
sigcustom.sa_flags = SA_RESTART;

if (sigaction(signal, &sigcustom, 0) < 0) {
qCritical() << "Failed to set up " << strsignal(signal) << " handler.";
return;
}

sigset_t set;
sigemptyset(&set);
sigaddset(&set, signal);
if (sigprocmask(SIG_UNBLOCK, &set, nullptr) < 0) {
qCritical() << "Failed to unblock " << strsignal(signal) << " handler.";
return;
}

customSignals.append(signal);
}

void SignalHandler::intSignalHandler(int) {
Expand All @@ -138,13 +104,6 @@ namespace DDM {
}
}

void SignalHandler::customSignalHandler(int signal) {
if (::write(sigcustomFd[0], &signal, sizeof(signal)) == -1) {
qCritical() << "Error writing to the " << strsignal(signal) << " handler";
return;
}
}

void SignalHandler::handleSigint() {
// disable notifier
snint->setEnabled(false);
Expand Down Expand Up @@ -189,27 +148,4 @@ namespace DDM {
snterm->setEnabled(true);
}

void SignalHandler::handleSigCustom() {
// disable notifier
sncustom->setEnabled(false);

// read from socket
int signal;
if (::read(sigcustomFd[1], &signal, sizeof(signal)) == -1) {
// something went wrong!
qCritical() << "Error reading from the socket";
return;
}

// log event
qWarning() << "Signal received: " << strsignal(signal);

// emit signal
emit customSignalReceived(signal);

// enable notifier
sncustom->setEnabled(true);
}


}
9 changes: 0 additions & 9 deletions src/common/SignalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#ifndef DDM_SIGNALHANDLER_H
#define DDM_SIGNALHANDLER_H

#include <QObject>

Check warning on line 23 in src/common/SignalHandler.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QList>

class QSocketNotifier;

Expand All @@ -33,30 +32,22 @@
SignalHandler(QObject *parent = 0);
~SignalHandler();

void addCustomSignal(int signal);

signals:
void sighupReceived();
void sigintReceived();
void sigtermReceived();
void customSignalReceived(int signal);

private slots:

Check warning on line 40 in src/common/SignalHandler.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void handleSigint();
void handleSigterm();
void handleSigCustom();

private:
static void initialize();
static void intSignalHandler(int unused);
static void termSignalHandler(int unused);
static void customSignalHandler(int unused);

QSocketNotifier *snint { nullptr };
QSocketNotifier *snterm { nullptr };
QSocketNotifier *sncustom { nullptr };

QList<int> customSignals{};
};
}
#endif // DDM_SIGNALHANDLER_H
15 changes: 11 additions & 4 deletions src/daemon/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#include "UserSession.h"

#include "DaemonApp.h"
#include "DdeSeatdControl.h"
#include "Login1Manager.h"

Check warning on line 10 in src/daemon/Auth.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Login1Manager.h" not found.
#include "Login1Session.h"

Check warning on line 11 in src/daemon/Auth.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Login1Session.h" not found.
#include "SignalHandler.h"

Check warning on line 12 in src/daemon/Auth.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SignalHandler.h" not found.
#include "VirtualTerminal.h"
#include "TtyUtils.h"
#include "TreelandConnector.h"

#include <pwd.h>

Check warning on line 16 in src/daemon/Auth.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <pwd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <security/pam_appl.h>

Check warning on line 17 in src/daemon/Auth.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <security/pam_appl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <signal.h>
#include <unistd.h>
#include <utmp.h>
Expand Down Expand Up @@ -229,8 +231,13 @@
return -1;
}

// Here is most safe place to jump VT
VirtualTerminal::jumpToVt(tty, false, false);
// Here is most safe place to request the VT switch before opening the session.
if (!daemonApp->seatdControl()->requestSwitchVt(tty)) {
qWarning() << "[Auth] Failed to switch to VT" << tty << ":" << strerror(errno);
close(pipefd[0]);
close(pipefd[1]);
return -1;
}

sessionLeaderPid = fork();
switch (sessionLeaderPid) {
Expand Down Expand Up @@ -379,7 +386,7 @@
CHECK_RET_OPEN

// Set PAM_TTY
QString vtPath = VirtualTerminal::path(tty);
QString vtPath = TtyUtils::path(tty);
d->ret = pam_set_item(d->handle, PAM_TTY, qPrintable(vtPath));
CHECK_RET_OPEN

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ configure_file(config.h.in config.h IMMEDIATE @ONLY)
set(DAEMON_SOURCES
Auth.cpp
DaemonApp.cpp
DdeSeatdControl.cpp
Display.cpp
DisplayManager.cpp
PowerManager.cpp
SeatManager.cpp
SocketServer.cpp
TreelandConnector.cpp
UserSession.cpp
VirtualTerminal.cpp
XorgDisplayServer.cpp
TreelandDisplayServer.cpp
${TREELAND_DDM_SOURCE}
Expand Down
8 changes: 7 additions & 1 deletion src/daemon/DaemonApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

#include "DaemonApp.h"

#include "Configuration.h"

Check warning on line 23 in src/daemon/DaemonApp.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Configuration.h" not found.
#include "Constants.h"

Check warning on line 24 in src/daemon/DaemonApp.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Constants.h" not found.
#include "DdeSeatdControl.h"
#include "DisplayManager.h"
#include "PowerManager.h"
#include "SeatManager.h"
Expand Down Expand Up @@ -85,7 +86,12 @@
connect(m_signalHandler, &SignalHandler::sigintReceived, this, &DaemonApp::quit);
connect(m_signalHandler, &SignalHandler::sigtermReceived, this, &DaemonApp::quit);

m_treelandConnector = new TreelandConnector();
m_seatdControl = new DdeSeatdControl(this);
m_treelandConnector = new TreelandConnector(this);
connect(m_seatdControl, &DdeSeatdControl::vtChanged,
m_seatManager, &SeatManager::handleVtChanged);
if (!m_seatdControl->connectEventSocket())
qWarning() << "Failed to connect dde-seatd event socket during startup";
// log message
qDebug() << "Starting...";

Expand Down
3 changes: 3 additions & 0 deletions src/daemon/DaemonApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace DDM {
class PowerManager;
class SeatManager;
class SignalHandler;
class DdeSeatdControl;
class TreelandConnector;

class DaemonApp : public QCoreApplication {
Expand All @@ -46,6 +47,7 @@ namespace DDM {
inline PowerManager *powerManager() const { return m_powerManager; };
inline SeatManager *seatManager() const { return m_seatManager; };
inline SignalHandler *signalHandler() const { return m_signalHandler; };
inline DdeSeatdControl *seatdControl() const { return m_seatdControl; };
inline TreelandConnector *treelandConnector() const { return m_treelandConnector; };

void backToNormal();
Expand All @@ -62,6 +64,7 @@ namespace DDM {
PowerManager *m_powerManager { nullptr };
SeatManager *m_seatManager { nullptr };
SignalHandler *m_signalHandler { nullptr };
DdeSeatdControl *m_seatdControl { nullptr };
TreelandConnector *m_treelandConnector { nullptr };
};
}
Expand Down
Loading
Loading