int tempDirToucherMain(int argc, char *argv[]) { initialize(argc, argv, 2); installSignalHandlers(); maybeDaemonize(); maybeWritePidfile(); while (1) { if (dirExists(dir)) { DEBUG("Touching directory"); touchDir(dir); if (!doSleep(sleepInterval)) { break; } } else { DEBUG("Directory no longer exists, exiting"); break; } } maybeDeletePidFile(); if (shouldCleanup) { DEBUG("Cleaning up directory"); performCleanup(dir); } return 0; }
int main(void) { const char str[] = "string 1"; int size = (4096*10); char *anon; installSignalHandlers(); anon = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if (anon == MAP_FAILED) { fprintf(stderr, "mmap fails\n"); exit(errno); } strcpy(anon, str); printf("anonymous page(%x): %s\n", anon, anon); if (mprotect(anon, 4096, PROT_NONE)) { perror("Couldn¡¯t mprotect"); exit(errno); } printf("anonymous page(%x): %s\n", anon, anon); strcpy(anon, str); munmap(anon, size); exit(0); }
KSshProcess::KSshProcess() : mVersion(UNKNOWN_VER), mConnected(false), mRunning(false), mConnectState(0) { mSshPath = KStandardDirs::findExe(QString::fromLatin1("ssh")); kdDebug(KSSHPROC) << "KSshProcess::KSshProcess(): ssh path [" << mSshPath << "]" << endl; installSignalHandlers(); }
int main(int argc, char *argv[]) { initialize(argc, argv); installSignalHandlers(); maybeDaemonize(); maybeWritePidfile(); while (1) { if (dirExists(dir)) { touchDir(dir); if (!doSleep(1800)) { break; } } else { break; } } maybeDeletePidFile(); if (shouldCleanup) { performCleanup(dir); } return 0; }
int main(int argc, char* argv[]) { installSignalHandlers(); printLibraryVersions(); /** Setup D-BUS information */ QCoreApplication::setOrganizationName("QlixIsOSS"); QCoreApplication::setOrganizationDomain("Qlix.berlios.de"); QCoreApplication::setApplicationName("Qlix"); /** Setup QSettings */ QSettings settings; QString ret = settings.value("DefaultDevice").toString(); /** Setup QApplication */ QApplication app(argc, argv); app.setStyle("Plastique"); /** Grab AutoFix options */ CommandLineOptions opts = ParseCommandLineOptions(argc, argv); _subSystem.SetAutoFixOptions(opts); if (opts.AutoFixPlaylists) cout << "Working" << endl; //app.setStyleSheet("QTreeView::branch:!adjoins-item{ border-color: none;}"); works //app.setStyleSheet("QTreeView::branch:!adjoins-item{ background: none}"); //app.setStyleSheet("QTreeView::branch:!adjoins-item:!has-children{ foreground: red}"); //app.setStyleSheet("QTreeView::branch:adjoins-item:has-children{ background: cyan}"); QlixMainWindow qmw(&_subSystem); qmw.show(); Q_INIT_RESOURCE(Qlix); app.exec(); return 0; }
void spawnManagedChild() { installSignalHandlers(); // Loops forever to make sure the parent process never leaves. while (true) { switch (childPid = fork()) { case -1: // error logFailure(failure::Category::kSystemError, "Can't spawn child process, sleeping"); std::this_thread::sleep_for(std::chrono::seconds(SpawnWait)); break; case 0: // child process. cleanup and continue with the startup logic. uninstallSignalHandlers(); return; default: // parent process. LOG(INFO) << "Spawned child process " << childPid; int rv; do { rv = wait(nullptr); } while (rv == -1 && errno != ECHILD && running); if (running) { // Child died accidentally. Cleanup and restart. LOG(INFO) << "Child process " << childPid << " exited"; waitpid(childPid, nullptr, 0); } else { // Child was killed. Shutdown parent. if (!waitpidTimeout(childPid, TermSignalTimeout)) { logFailure(failure::Category::kSystemError, "Child process did not exit in {} microseconds. Sending SIGKILL.", TermSignalTimeout); kill(childPid, SIGKILL); } exit(0); } break; } } }
KSshProcess::KSshProcess(QString pathToSsh) : mSshPath(pathToSsh), mVersion(UNKNOWN_VER), mConnected(false), mRunning(false), mConnectState(0) { installSignalHandlers(); }
jboolean rvmSetupSignals(Env* env) { if (!installSignalHandlers(env)) { return FALSE; } return TRUE; }
int main(int argc, char *argv[]) { #ifdef Q_OS_WIN _oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter); // CAPIHook apiHook("kernel32.dll", "SetUnhandledExceptionFilter", (PROC)RedirectedSetUnhandledExceptionFilter); #endif settingsParseArgs(argc, argv); for (int32 i = 0; i < argc; ++i) { if (string("-fixprevious") == argv[i]) { return psFixPrevious(); } else if (string("-cleanup") == argv[i]) { return psCleanup(); } } if (!logsInit()) { return 0; } installSignalHandlers(); Global::Initializer _init; Local::readSettings(); if (Local::oldSettingsVersion() < AppVersion) { psNewVersion(); } if (cFromAutoStart() && !cAutoStart()) { psAutoStart(false, true); Local::stop(); return 0; } DEBUG_LOG(("Application Info: Telegram started, test mode: %1, exe dir: %2").arg(logBool(cTestMode())).arg(cExeDir())); if (cDebug()) { LOG(("Application Info: Telegram started in debug mode")); for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(fromUtf8Safe(argv[i]))); } QStringList logs = psInitLogs(); for (int32 i = 0, l = logs.size(); i < l; ++i) { LOG(("Init Log: %1").arg(logs.at(i))); } } psClearInitLogs(); DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); psStart(); int result = 0; { QByteArray args[] = { "-style=0" }; // prepare fake args static const int a_cnt = sizeof(args) / sizeof(args[0]); int a_argc = a_cnt + 1; char *a_argv[a_cnt + 1] = { argv[0], args[0].data() }; Application app(a_argc, a_argv); if (!App::quiting()) { result = app.exec(); } } psFinish(); Local::stop(); DEBUG_LOG(("Application Info: Telegram done, result: %1").arg(result)); #ifndef TDESKTOP_DISABLE_AUTOUPDATE if (cRestartingUpdate()) { if (!cBetaVersion() && DevVersion) { LOG(("Writing 'devversion' file before launching the Updater!")); QFile f(cWorkingDir() + qsl("tdata/devversion")); if (!f.exists() && f.open(QIODevice::WriteOnly)) { f.write("1"); f.close(); } } DEBUG_LOG(("Application Info: executing updater to install update..")); psExecUpdater(); } else #endif if (cRestarting()) { DEBUG_LOG(("Application Info: executing Telegram, because of restart..")); psExecTelegram(); } logsClose(); return result; }
int main(int argc, const char** argv) { int retval = 0; boost::program_options::options_description general_options_description("Options", 140, 60); boost::program_options::variables_map vm; std::string colorArg, deviceArg; try { std::set<Nebula::HAL::Device*> devices; std::mutex devicesMutex; installSignalHandlers(); general_options_description.add_options() (Options::kDevice, boost::program_options::value<std::string>(), "specify device") (Options::kChannel, boost::program_options::value<RT::s4>()->default_value(0), "specify LED strip channel") (Options::kNumberOfLeds, boost::program_options::value<RT::s4>()->default_value(0), "set number of leds") ("nn", boost::program_options::value<RT::s4>()->default_value(100), "set running light increment") ("size,s", boost::program_options::value<RT::s4>()->default_value(100), "Ambilight sensing zones size") (Options::kFrequency, boost::program_options::value<float>()->default_value(24.0f), "set number of LEDs color updates per second") (Options::kColor, boost::program_options::value<std::string>()->default_value(std::string("255,255,255")), "set LEDs color") (Options::kBrightness, boost::program_options::value<float>()->default_value(0.5f), "set LEDs brightness") (Options::kRate, boost::program_options::value<float>()->default_value(1.0f), "set dynamic lighting effect rate") //(Options::kStrobe, "run in stroboscope mode") (Options::kDebug, boost::program_options::value<RT::u4>()->default_value(0), "stroboscope mode"); if (argc < 2) optionsError("mode was not specified\n"); auto mode = determineMode(argv[1]); if (mode == Mode::none) optionsError("invalid mode was specified\n"); boost::program_options::store(boost::program_options::command_line_parser(argc - 1, argv + 1).options(general_options_description).run(), vm, true); boost::program_options::notify(vm); switch (mode) { case Mode::help: print_usage(general_options_description); exit(0); case Mode::version: std::cout << VERSION_STRING(VERSION, __DATE__, __TIME__) << std::endl; exit(0); default: break; } auto onDeviceAddition = [&](Nebula::HAL::Device* device) -> void { std::lock_guard<std::mutex> lock(devicesMutex); devices.insert(device); }; auto onDeviceRemoval = [&](Nebula::HAL::Device* device) -> void { std::lock_guard<std::mutex> lock(devicesMutex); devices.erase(device); }; std::unique_ptr<Nebula::HAL::Context> nebula(Nebula::HAL::createContext(onDeviceAddition, onDeviceRemoval)); if (mode == Mode::list) { std::lock_guard<std::mutex> lock(devicesMutex); for (auto device : devices) printDeviceInfo(device); } else { auto firstDeviceIterator = devices.begin(); if (firstDeviceIterator != devices.end()) { auto device = *firstDeviceIterator; auto channel = vm["channel"].as<RT::s4>(); auto numberOfLeds = vm["nleds"].as<RT::s4>(); auto frequency = vm["freq"].as<float>(); auto brightness = vm["brightness"].as<float>(); bool animate = false; if (channel < 0) optionsError("channel should be >= 0\n"); if (numberOfLeds <= 0) optionsError("number of LEDs should be > 0\n"); if (frequency <= 0.0f) optionsError("frequency should be > 0\n"); if (brightness < 0.0f) optionsError("brightness should be >= 0\n"); std::unique_ptr<Nebula::Color::RGB<RT::u1>> colors(new Nebula::Color::RGB<RT::u1>[numberOfLeds]); std::mutex colorsMutex; Nebula::HAL::Device::IoctlParameters::SetNumberOfLeds setNumberOfLedsIoctlParameters(channel, numberOfLeds); Nebula::HAL::Device::IoctlParameters::Colors colorsIoctlParameters(channel, colors.get(), numberOfLeds); device->controlIn(Nebula::HAL::Device::Request::setNumberOfLeds, &setNumberOfLedsIoctlParameters, sizeof(setNumberOfLedsIoctlParameters)); switch (mode) { case Mode::continuous: { RT::u4 r, g, b; sscanf(vm["color"].as<std::string>().c_str(), "%u,%u,%u", &r, &g, &b); r *= brightness; g *= brightness; b *= brightness; for (auto i = 0; i < numberOfLeds; i++) colors.get()[convertLedNumber(i)].set(r, g, b); device->controlIn(Nebula::HAL::Device::Request::setColors, &colorsIoctlParameters, sizeof(colorsIoctlParameters)); } break; case Mode::rainbow: case Mode::ambilight: case Mode::run: animate = true; break; default: break; } if (animate) { std::unique_ptr<Nebula::Generator> generator(createGenerator(mode, vm)); std::unique_ptr<Nebula::Transformation> transformation(new Reorder(numberOfLeds, 3)); TimerCallbackParameters timerCallbackParameters(device, &colorsIoctlParameters, &colorsMutex); std::thread pluginThread([&]() -> void { std::unique_ptr<Nebula::Color::RGB<RT::u1>> localColors(new Nebula::Color::RGB<RT::u1>[numberOfLeds]); time_t t1, t2; RT::u8 count = 0; time(&t1); while (!doTerminate) { generator->generate(localColors.get()); transformation->transformInPlace(localColors.get()); guardedMemcpy(localColors.get(), colors.get(), numberOfLeds * sizeof(Nebula::Color::RGB<RT::u1>), &colorsMutex); count++; } time(&t2); if (count > 0) printf("updates per second = %f\n", float(count) / float(t2 - t1)); }); try { runLoop(&timerCallbackParameters, frequency); } catch(...) { pluginThread.join(); throw; } pluginThread.join(); } } else printf("No device found\n"); } } catch (RT::u4 ID) { printf("Error 0x%x\n", ID); } catch (OptionsError e) { printf("Invalid program invocation: %s", e.getMessage()); print_usage(general_options_description); retval = -1; } catch (...) { printf("Exception occured\n"); } return retval; }