quickmod/FuseMounter/signalhandler.cpp
Daniel O'Neill 1393a796b2 Implement FUSE VFS as a very early implementation. It can, does, and will break your game.
Updated QML and C++ in various places to build and work with new Qt (6.4+)
Minor bugfixes, possibly caused by the Qt version bump, and mostly in JS logic.
Tried (again) to get mod sorting working by dragging them within the list.
Initial support for Profiles. (To switch between FO4 and FOLON, for example.)
Initial "Launch Game" stuff, but it's far from done. Don't use it (yet).
2025-08-20 07:57:00 -07:00

62 lines
1.6 KiB
C++

#include <QDebug>
#include "signalhandler.h"
#include <sys/socket.h>
#include <signal.h>
static int sighupFd[2] = {0, 0};
SignalHandler::SignalHandler(QObject *parent)
: QObject{parent}
{
sighupFd[0] = sighupFd[1] = 0;
if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sighupFd))
qFatal("Couldn't create HUP socketpair");
snHup = new QSocketNotifier(sighupFd[0], QSocketNotifier::Read, this);
connect(snHup, &QSocketNotifier::activated, this, &SignalHandler::handleSigHup);
snHup->setEnabled(true);
qDebug() << "QSocketNotifier valid?" << snHup->isValid();
}
int SignalHandler::setup_unix_signal_handlers()
{
struct sigaction hup;
hup.sa_handler = SignalHandler::hupSignalHandler;
sigemptyset(&hup.sa_mask);
hup.sa_flags = 0;
hup.sa_flags |= SA_RESTART;
if (sigaction(SIGHUP, &hup, 0))
return 1;
return 0;
}
void SignalHandler::hupSignalHandler(int)
{
char a = 1;
int len = ::write(sighupFd[1], &a, sizeof(a));
fprintf(stderr, "SignalHandler::hupSignalHandler: Informing Qt process of HUP request, wrote %d bytes.\n", len);
}
void SignalHandler::handleSigHup(QSocketDescriptor socket, QSocketNotifier::Type type)
{
Q_UNUSED(socket)
Q_UNUSED(type)
snHup->setEnabled(false);
fprintf(stderr, "SignalHandler::handleSigHup: Reading the byte.\n");
char tmp;
int len = ::read(sighupFd[0], &tmp, sizeof(tmp));
// do Qt stuff
fprintf(stderr, "SignalHandler::handleSigHup: HUP Received. Emitting 'hupSignalReceived', read %d bytes.\n", len);
emit hupSignalReceived();
snHup->setEnabled(true);
}