diff --git a/kded/kded.cpp b/kded/kded.cpp index 0f915142..235bb53e 100644 --- a/kded/kded.cpp +++ b/kded/kded.cpp @@ -34,8 +34,8 @@ #include #include #include -#include +#include #include #include #include @@ -47,6 +47,8 @@ #include #endif +#include + #define KDED_EXENAME "kded4" #define MODULES_PATH "/modules/" @@ -660,6 +662,7 @@ int main(int argc, char *argv[]) KApplication app; app.setQuitOnLastWindowClosed(false); app.disableSessionManagement(); + app.quitOnSignal(); QDBusConnection session = QDBusConnection::sessionBus(); if (!session.isConnected()) { diff --git a/kdeui/kernel/kapplication.cpp b/kdeui/kernel/kapplication.cpp index 5b4acc45..92f19702 100644 --- a/kdeui/kernel/kapplication.cpp +++ b/kdeui/kernel/kapplication.cpp @@ -25,13 +25,15 @@ #include #include +#include +#include +#include #include #include -#include #include -#include -#include -#include +#include +#include +#include #include "kauthorized.h" #include "kaboutdata.h" @@ -54,29 +56,23 @@ #include "kurl.h" #include "kmessage.h" #include "kmessageboxmessagehandler.h" - -#if defined Q_WS_X11 -#include +#include "kwindowsystem.h" +#include "kde_file.h" #include -#endif +#include #include -#ifdef HAVE_SYS_STAT_H -#include -#endif #include - -#include "kwindowsystem.h" - #include #include // srand(), rand() #include -#if defined Q_WS_X11 -//#ifndef Q_WS_QWS //FIXME(embedded): NetWM should talk to QWS... -#include +#include +#ifdef HAVE_SYS_STAT_H +# include #endif #ifdef Q_WS_X11 +#include #include #include #include @@ -86,14 +82,6 @@ #include #endif - -#ifdef Q_OS_UNIX -#include -#endif - -#include -#include - KApplication* KApplication::KApp = 0L; bool KApplication::loadedByKdeinit = false; @@ -188,9 +176,9 @@ static void installSigpipeHandler() #ifdef Q_OS_UNIX struct sigaction act; act.sa_handler = SIG_IGN; - sigemptyset( &act.sa_mask ); + sigemptyset(&act.sa_mask); act.sa_flags = 0; - sigaction( SIGPIPE, &act, 0 ); + sigaction(SIGPIPE, &act, 0); #endif } @@ -843,7 +831,25 @@ void KApplication::updateRemoteUserTimestamp( const QString& service, int time ) #endif } +static void quit_handler(int sig) +{ + Q_UNUSED(sig); + KDE_signal(SIGTERM, SIG_DFL); + KDE_signal(SIGHUP, SIG_DFL); + KDE_signal(SIGINT, SIG_DFL); + + if (qApp) { + qApp->quit(); + } +} + +void KApplication::quitOnSignal() +{ + KDE_signal(SIGTERM, quit_handler); + KDE_signal(SIGHUP, quit_handler); + KDE_signal(SIGINT, quit_handler); +} QString KApplication::checkRecoverFile( const QString& pFilename, diff --git a/kdeui/kernel/kapplication.h b/kdeui/kernel/kapplication.h index cc3470a0..a271c8ff 100644 --- a/kdeui/kernel/kapplication.h +++ b/kdeui/kernel/kapplication.h @@ -262,6 +262,12 @@ public: */ void updateRemoteUserTimestamp( const QString& service, int time = 0 ); + /** + * Setups signal handler for SIGTERM, SIGHUP and SIGINT to call QApplication::quit() when such + * signal is received. + */ + static void quitOnSignal(); + #ifdef Q_WS_X11 /** @internal