Commit 77ebdc93 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Properly handle signals using KSignalHandler

We cannot interact with Qt directly from a signal handler we configure,
we need to make sure it doesn't mess with the app's state.


(cherry picked from commit fcdc99d8)
parent e78e1b18
Pipeline #234708 passed with stage
in 2 minutes and 10 seconds
......@@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#endif
#include <KSignalHandler>
#include <LayerShellQt/Shell>
static void signalHandler(int signum)
......@@ -184,11 +185,8 @@ int main(int argc, char *argv[])
// Crucial for blocking until it is ready, ensuring locking happens before sleep, e.g.
std::cout << "Locked at " << QDateTime::currentDateTime().toSecsSinceEpoch() << std::endl;
struct sigaction sa;
sa.sa_handler = signalHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGUSR1, &sa, nullptr);
KSignalHandler::self()->watchSignal(SIGTERM);
KSignalHandler::self()->watchSignal(SIGUSR1);
QObject::connect(KSignalHandler::self(), &KSignalHandler::signalReceived, &app, &signalHandler);
return app.exec();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment