void UnixSignals::handleSignal(int number) { qDebug() << "Got signal:" << number; switch (number) { #ifdef SIGBREAK case SIGBREAK: qDebug() << "Got SIGBREAK! emit event!"; emit sigBREAK(); break; #endif #ifdef SIGHUP case SIGHUP: qDebug() << "Got SIGHUP! emit event!"; emit sigHUP(); break; #endif #ifdef SIGINT case SIGINT: qDebug() << "Got SIGINT! emit event!"; emit sigINT(); break; #endif #ifdef SIGTERM case SIGTERM: qDebug() << "Got SIGTERM! emit event!"; emit sigTERM(); break; #endif #ifdef SIGUSR1 case SIGUSR1: qDebug() << "Got SIGUSR1! emit event!"; emit sigUSR1(); break; #endif #ifdef SIGUSR2 case SIGUSR2: qDebug() << "Got SIGUSR2! emit event!"; emit sigUSR2(); break; #endif default: qDebug() << "Got something? Dunno what to do..."; } }
int ACE_TMAIN(int, ACE_TCHAR ** argv) { int result = 0; #if !defined (ACE_LACKS_FORK) ACE_Sig_Action sigUSR2((ACE_SignalHandler) shutdown_func, SIGUSR2); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) SIGUSR2 shutdown handler installed\n"))); ACE_UNUSED_ARG(sigUSR2); pid_t pid = -1; pid = ACE_OS::fork(); ACE_Log_Msg::instance ()->sync (argv[0]); // Make %P|%t work right if (pid == 0) // child { ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) child waiting\n"))); ACE_OS::sleep(5); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) signaling parent\n"))); result = ACE_OS::kill(ACE_OS::getppid(), SIGUSR2); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) signaled parent\n"))); // ACE_OS::sleep (100000); return 0; } else if (pid > 0) // parent { ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) parent using ACE_Service_Config, pid=%d\n"), pid)); ACE_Service_Config serviceConfig; ACE_TCHAR signum[64]; ACE_OS::sprintf(signum, ACE_TEXT("%d"), SIGUSR1); ACE_ARGV args; args.add(argv[0]); args.add(ACE_TEXT("-s")); args.add(signum); result = serviceConfig.open ( args.argc(), args.argv(), ACE_DEFAULT_LOGGER_KEY, 1, // ignore_static_svcs = 1, 1, // ignore_default_svc_conf_file = 0, 0 // ignore_debug_flag = 0 ); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.open failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.open done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.process_file ...\n"))); #if (ACE_USES_CLASSIC_SVC_CONF == 1) result = serviceConfig.process_file(ACE_TEXT("Bug_3251.conf")); #else result = serviceConfig.process_file(ACE_TEXT("Bug_3251.conf.xml")); #endif if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.process_file failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.process_file done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("run_event_loop ...\n"))); while(!bShutdown) { ACE_OS::last_error(0); result = ACE_Reactor::run_event_loop(); // reenter loop on EINTR if(0 != result && EINTR == ACE_OS::last_error()) { if(bShutdown) break; } else if(0 != result) { ACE_DEBUG (( LM_INFO, ACE_TEXT ("(%P|%t) run_event_loop failed (%s, %d)\n"), ACE_OS::strerror(ACE_OS::last_error()), ACE_OS::last_error() )); } } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) run_event_loop done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs ...\n"))); result = serviceConfig.fini_svcs(); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.fini_svcs failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.fini_svcs done\n"))); ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.close ...\n"))); result = serviceConfig.close(); if(0 != result) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: serviceConfig.close failed\n"))); return result; } ACE_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) serviceConfig.close done\n"))); return result; } /* end of if */ else // fork failed { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) Error: fork failed\n"))); return 1; } /* end of else */ #else ACE_UNUSED_ARG (argv); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Fork not available\n"))); #endif return result; }
void MainWindow::init(AnyOption *opts) { cmdopts = opts; if (cmdopts->getValue("config") || cmdopts->getValue('c')) { qDebug(">> Config option in command prompt..."); QString cfgPath = cmdopts->getValue('c'); if (cfgPath.isEmpty()) { cfgPath = cmdopts->getValue("config"); } loadSettings(cfgPath); } else { loadSettings(QString("")); } if (mainSettings->value("signals/enable").toBool()) { connect(handler, SIGNAL(sigUSR1()), SLOT(unixSignalUsr1())); connect(handler, SIGNAL(sigUSR2()), SLOT(unixSignalUsr2())); } handler->start(); setMinimumWidth(320); setMinimumHeight(200); quint16 minimalWidth = mainSettings->value("view/minimal-width").toUInt(); quint16 minimalHeight = mainSettings->value("view/minimal-height").toUInt(); if (minimalWidth) { setMinimumWidth(minimalWidth); } if (minimalHeight) { setMinimumHeight(minimalHeight); } hiddenCurdor = new QCursor(Qt::BlankCursor); qDebug() << "Application icon: " << mainSettings->value("application/icon").toString(); setWindowIcon(QIcon( mainSettings->value("application/icon").toString() )); if (cmdopts->getValue("uri") || cmdopts->getValue('u')) { qDebug(">> Uri option in command prompt..."); QString uri = cmdopts->getValue('u'); if (uri.isEmpty()) { uri = cmdopts->getValue("uri"); } mainSettings->setValue("browser/homepage", uri); } QCoreApplication::setOrganizationName( mainSettings->value("application/organization").toString() ); QCoreApplication::setOrganizationDomain( mainSettings->value("application/organization-domain").toString() ); QCoreApplication::setApplicationName( mainSettings->value("application/name").toString() ); QCoreApplication::setApplicationVersion( mainSettings->value("application/version").toString() ); // --- Network --- // if (mainSettings->value("proxy/enable").toBool()) { bool system = mainSettings->value("proxy/system").toBool(); if (system) { QNetworkProxyFactory::setUseSystemConfiguration(system); } else { QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpProxy); proxy.setHostName( mainSettings->value("proxy/host").toString() ); proxy.setPort(mainSettings->value("proxy/port").toUInt()); if (mainSettings->value("proxy/auth").toBool()) { proxy.setUser(mainSettings->value("proxy/username").toString()); proxy.setPassword(mainSettings->value("proxy/password").toString()); } QNetworkProxy::setApplicationProxy(proxy); } } // --- Web View --- // view = new WebView(this); if (mainSettings->value("view/show_load_progress").toBool()) { // --- Progress Bar --- // loadProgress = new QProgressBar(view); loadProgress->setContentsMargins(2, 2, 2, 2); loadProgress->setMinimumWidth(100); loadProgress->setMinimumHeight(16); loadProgress->setFixedHeight(16); loadProgress->setAutoFillBackground(true); QPalette palette = this->palette(); palette.setColor(QPalette::Window, QColor(255,255,255,63)); loadProgress->setPalette(palette); // Do not work... Need Layout... loadProgress->setAlignment(Qt::AlignTop); loadProgress->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); loadProgress->hide(); } setCentralWidget(view); view->setSettings(mainSettings); view->setPage(new QWebPage(view)); // --- Disk cache --- // if (mainSettings->value("cache/enable").toBool()) { diskCache = new QNetworkDiskCache(this); QString location = mainSettings->value("cache/location").toString(); if (!location.length()) { #ifdef QT5 location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); #else location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); #endif } diskCache->setCacheDirectory(location); diskCache->setMaximumCacheSize(mainSettings->value("cache/size").toUInt()); if (mainSettings->value("cache/clear-on-start").toBool()) { diskCache->clear(); } else if (cmdopts->getFlag('C') || cmdopts->getFlag("clear-cache")) { diskCache->clear(); } CachingNetworkManager *nm = new CachingNetworkManager(); nm->setCache(diskCache); view->page()->setNetworkAccessManager(nm); } if (mainSettings->value("browser/cookiejar").toBool()) { view->page()->networkAccessManager()->setCookieJar(new PersistentCookieJar()); } view->settings()->setAttribute(QWebSettings::JavascriptEnabled, mainSettings->value("browser/javascript").toBool() ); view->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, mainSettings->value("browser/javascript_can_open_windows").toBool() ); view->settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, mainSettings->value("browser/javascript_can_close_windows").toBool() ); view->settings()->setAttribute(QWebSettings::WebGLEnabled, mainSettings->value("browser/webgl").toBool() ); view->settings()->setAttribute(QWebSettings::JavaEnabled, mainSettings->value("browser/java").toBool() ); view->settings()->setAttribute(QWebSettings::PluginsEnabled, mainSettings->value("browser/plugins").toBool() ); if (mainSettings->value("inspector/enable").toBool()) { view->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); inspector = new QWebInspector(); inspector->setVisible(mainSettings->value("inspector/visible").toBool()); inspector->setMinimumSize(800, 600); inspector->setWindowTitle(mainSettings->value("application/name").toString() + " - WebInspector"); inspector->setWindowIcon(this->windowIcon()); inspector->setPage(view->page()); } connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); connect(view, SIGNAL(loadStarted()), SLOT(startLoading())); connect(view, SIGNAL(urlChanged(const QUrl &)), SLOT(urlChanged(const QUrl &))); connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); connect(view, SIGNAL(iconChanged()), SLOT(pageIconLoaded())); QDesktopWidget *desktop = QApplication::desktop(); connect(desktop, SIGNAL(resized(int)), SLOT(desktopResized(int))); // Window show, start events loop show(); view->page()->view()->setFocusPolicy(Qt::StrongFocus); view->setFocusPolicy(Qt::StrongFocus); if (mainSettings->value("view/hide_mouse_cursor").toBool()) { QApplication::setOverrideCursor(Qt::BlankCursor); view->setCursor(*hiddenCurdor); } int delay_resize = 0; if (mainSettings->value("view/startup_resize_delayed").toBool()) { delay_resize = mainSettings->value("view/startup_resize_delay").toInt(); } delayedResize->singleShot(delay_resize, this, SLOT(delayedWindowResize())); int delay_load = 0; if (mainSettings->value("browser/startup_load_delayed").toBool()) { delay_load = mainSettings->value("browser/startup_load_delay").toInt(); } delayedLoad->singleShot(delay_load, this, SLOT(delayedPageLoad())); }
void UnixSignals::start() { #ifdef SIGBREAK // Available on Windows if (receivers(SIGNAL(sigBREAK())) > 0) { if (signal(SIGBREAK, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on BREAK"); } } else { qDebug("No listeners for signal BREAK"); } #else qWarning("No signal BREAK defined"); #endif #ifdef SIGTERM if (receivers(SIGNAL(sigTERM())) > 0) { if (signal(SIGTERM, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on TERM"); } } else { qDebug("No listeners for signal TERM"); } #else qWarning("No signal TERM defined"); #endif #ifdef SIGINT if (receivers(SIGNAL(sigINT())) > 0) { if (signal(SIGINT, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on INT"); } } else { qDebug("No listeners for signal INT"); } #else qWarning("No signal INT defined"); #endif #ifdef SIGHUP // Unavailable on Windows if (receivers(SIGNAL(sigHUP())) > 0) { if (signal(SIGHUP, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on HUP"); } } else { qDebug("No listeners for signal HUP"); } #else qWarning("No signal HUP defined"); #endif #ifdef SIGUSR1 // Unavailable on Windows if (receivers(SIGNAL(sigUSR1())) > 0) { if (signal(SIGUSR1, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on USR1"); } } else { qDebug("No listeners for signal USR1"); } #else qWarning("No signal USR1 defined"); #endif #ifdef SIGUSR2 // Unavailable on Windows if (receivers(SIGNAL(sigUSR2())) > 0) { if (signal(SIGUSR2, UnixSignals::signalHandler) == SIG_ERR) { qFatal("Unable to set signal handler on USR2"); } } else { qDebug("No listeners for signal USR1"); } #else qWarning("No signal USR2 defined"); #endif }