static void sig_handler(int sig_num) { // No recursion KDE_signal( SIGHUP, SIG_IGN); KDE_signal( SIGTERM, SIG_IGN); fprintf(stderr, "klauncher: Exiting on signal %d\n", sig_num); char tmp = 'x'; write( sigpipe[ 1 ], &tmp, 1 ); }
int PtyProcess::setupTTY() { // Reset signal handlers for (int sig = 1; sig < NSIG; sig++) KDE_signal(sig, SIG_DFL); KDE_signal(SIGHUP, SIG_IGN); d->m_pPTY->setCTty(); // Connect stdin, stdout and stderr int slave = d->m_pPTY->slaveFd(); dup2(slave, 0); dup2(slave, 1); dup2(slave, 2); // Close all file handles // XXX this caused problems in KProcess - not sure why anymore. -- ??? // Because it will close the start notification pipe. -- ossi struct rlimit rlp; getrlimit(RLIMIT_NOFILE, &rlp); for (int i = 3; i < (int)rlp.rlim_cur; i++) close(i); // Disable OPOST processing. Otherwise, '\n' are (on Linux at least) // translated to '\r\n'. struct ::termios tio; if (tcgetattr(0, &tio) < 0) { kError(kdesuDebugArea()) << k_lineinfo << "tcgetattr():" << perror; return -1; } tio.c_oflag &= ~OPOST; if (tcsetattr(0, TCSANOW, &tio) < 0) { kError(kdesuDebugArea()) << k_lineinfo << "tcsetattr():" << perror; return -1; } return 0; }
extern "C" KDE_EXPORT int kdemain(int argc, char **argv) { // Disable Session Management the right way (C) // // ksmserver has global shortcuts. disableSessionManagement() does not prevent Qt from // registering the app with the session manager. We remove the address to make sure we do not // get a hang on kglobalaccel restart (kglobalaccel tries to register with ksmserver, // ksmserver tries to register with kglobalaccel). unsetenv( "SESSION_MANAGER" ); #ifdef Q_OS_MAC CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { // get the application's Info Dictionary. For app bundles this would live in the bundle's Info.plist, // for regular executables it is obtained in another way. CFMutableDictionaryRef infoDict = (CFMutableDictionaryRef) CFBundleGetInfoDictionary(mainBundle); if (infoDict) { // Add or set the "LSUIElement" key with/to value "1". This can simply be a CFString. CFDictionarySetValue(infoDict, CFSTR("LSUIElement"), CFSTR("1")); // That's it. We're now considered as an "agent" by the window server, and thus will have // neither menubar nor presence in the Dock or App Switcher. } } #endif KAboutData aboutdata( "kglobalaccel", 0, ki18n("KDE Global Shortcuts Service"), "0.2", ki18n("KDE Global Shortcuts Service"), KAboutData::License_LGPL, ki18n("(C) 2007-2009 Andreas Hartmetz, Michael Jansen")); aboutdata.addAuthor(ki18n("Andreas Hartmetz"),ki18n("Maintainer"),"*****@*****.**"); aboutdata.addAuthor(ki18n("Michael Jansen"),ki18n("Maintainer"),"*****@*****.**"); aboutdata.setProgramIconName("kglobalaccel"); KCmdLineArgs::init( argc, argv, &aboutdata ); KUniqueApplication::addCmdLineOptions(); // check if kglobalaccel is disabled if (!isEnabled()) { kDebug() << "kglobalaccel is disabled!"; return 0; } if (!KUniqueApplication::start()) { kDebug() << "kglobalaccel is already running!"; return (0); } // As in the KUniqueApplication example only create a instance AFTER // calling KUniqueApplication::start() KUniqueApplication app; // This app is started automatically, no need for session management app.disableSessionManagement(); app.setQuitOnLastWindowClosed( false ); // Stop gracefully //There is no SIGINT and SIGTERM under wince #ifndef _WIN32_WCE KDE_signal(SIGINT, sighandler); KDE_signal(SIGTERM, sighandler); #endif KDE_signal(SIGHUP, sighandler); // Restart on a crash KCrash::setFlags(KCrash::AutoRestart); KGlobalAccelD globalaccel; if (!globalaccel.init()) { return -1; } return app.exec(); }
extern "C" KDE_EXPORT int kdemain( int argc, char**argv ) { #ifndef Q_WS_WIN // Started via kdeinit. int launcherFd; if (argc != 2 || memcmp(argv[1], "--fd=", 5) || !(launcherFd = atoi(argv[1] + 5))) { fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be started manually.\n" "klauncher: It is started automatically by kdeinit4.\n").toLocal8Bit().data()); return 1; } #endif #if defined(Q_OS_DARWIN) || defined (Q_OS_MAC) mac_initialize_dbus(); #endif KComponentData componentData("klauncher", "kdelibs4"); KGlobal::locale(); // WABA: Make sure not to enable session management. putenv(strdup("SESSION_MANAGER=")); // We need a QCoreApplication to get a DBus event loop QCoreApplication app(argc, argv); app.setApplicationName( componentData.componentName() ); int maxTry = 3; while(true) { QString service(QLatin1String("org.kde.klauncher")); // same as ktoolinvocation.cpp if (!QDBusConnection::sessionBus().isConnected()) { kWarning() << "No DBUS session-bus found. Check if you have started the DBUS server."; return 1; } QDBusReply<QDBusConnectionInterface::RegisterServiceReply> reply = QDBusConnection::sessionBus().interface()->registerService(service); if (!reply.isValid()) { kWarning() << "DBUS communication problem!"; return 1; } if (reply == QDBusConnectionInterface::ServiceRegistered) break; if (--maxTry == 0) { kWarning() << "Another instance of klauncher is already running!"; return 1; } // Wait a bit... kWarning() << "Waiting for already running klauncher to exit."; sleep(1); // Try again... } #ifndef USE_KPROCESS_FOR_KIOSLAVES KLauncher *launcher = new KLauncher(launcherFd); #else KLauncher *launcher = new KLauncher(); #endif QDBusConnection::sessionBus().registerObject(QString::fromLatin1("/"), launcher); #ifndef USE_KPROCESS_FOR_KIOSLAVES if (pipe(sigpipe) != 0) { perror("klauncher: pipe failed."); return 1; } QSocketNotifier* signotif = new QSocketNotifier( sigpipe[ 0 ], QSocketNotifier::Read, launcher ); QObject::connect( signotif, SIGNAL(activated(int)), launcher, SLOT(destruct())); KCrash::setEmergencySaveFunction(sig_handler); KDE_signal( SIGHUP, sig_handler); KDE_signal( SIGPIPE, SIG_IGN); KDE_signal( SIGTERM, sig_handler); #endif return app.exec(); }
void kmsetSignalHandler(void (*handler)(int)) { KDE_signal(SIGTERM, handler); KDE_signal(SIGHUP, handler); KCrash::setEmergencySaveFunction(kmcrashHandler); }