static void OS_InstallSignalHandlers(int force) { struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = OS_SigpipeHandler; installSignalHandler(SIGPIPE, &sa, force); sa.sa_handler = OS_Sigusr1Handler; installSignalHandler(SIGUSR1, &sa, force); }
bool VoxMain::initialize(int argc, char** argv) { if(!readUserInput(argc, argv)) return false; installSignalHandler(); if(!setToDaemon()) return false; if(!setupLog()) return false; if(!INIT_WIRING) { ERROR("INIT_WIRING failed!"); return false; } if(!VoxControl::getInstance().start()) { ERROR("(MAIN) failed to start controller thread"); return false; } if(!VoxSensor::getInstance().start()) { ERROR("(MAIN) failed to start sensor thread"); return false; } if(!VoxPlayer::getInstance().start()) { ERROR("(MAIN) failed to start player thread"); return false; } if(!VoxVision::getInstance().start()) { ERROR("(MAIN) failed to start vision thread"); return false; } if(!VoxVoice::getInstance().start()) { ERROR("(MAIN) failed to start voice thread"); return false; } if(!createPidFile()) { ERROR("(MAIN) pid file '%s' create failed", m_pidfile.c_str()); return false; } return true; }
// signalhandler and internal clock is only needed to install once // for unit testing purposes the initializeLogging might be called // several times... for all other practical use, it shouldn't! void initializeLogging(g2LogWorker *bgworker) { std::call_once(g_initialize_flag, []() { installSignalHandler(); }); std::lock_guard<std::mutex> lock(g_logging_init_mutex); CHECK(!internal::isLoggingInitialized()); CHECK(bgworker != nullptr); g_logger_instance = bgworker; }
void initializeLogging(LogWorker *bgworker) { std::call_once(g_initialize_flag, []() { installSignalHandler(); }); std::lock_guard<std::mutex> lock(g_logging_init_mutex); CHECK(!internal::isLoggingInitialized()); CHECK(bgworker != nullptr); // Save the first uninitialized message, if any std::call_once(g_save_first_unintialized_flag, [&bgworker] { if (g_first_unintialized_msg) { bgworker->save(LogMessagePtr{std::move(g_first_unintialized_msg)}); } }); g_logger_instance = bgworker; }
static void setEnabled(bool isEnabled) { if(isEnabled != g_isEnabled) { g_isEnabled = isEnabled; if(isEnabled) { ksid_generate(g_eventID); if(!installSignalHandler()) { return; } } else { uninstallSignalHandler(); } } }
Error PerfEvents::start(const char* event, long interval) { _event_type = PerfEventType::forName(event); if (_event_type == NULL) { return Error("Unsupported event type"); } if (interval < 0) { return Error("interval must be positive"); } _interval = interval ? interval : _event_type->default_interval; installSignalHandler(); jvmtiEnv* jvmti = VM::jvmti(); jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL); jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL); createForAllThreads(); return Error::OK; }
void Tresenv::sim_step() { // implement graceful exit when Ctrl-C is hit during simulation. We want // to finish the current event, then normally exit via callFinish() etc // so that simulation results are not lost. installSignalHandler(); startClock(); sigint_received = false; disable_tracing = true; cSimpleModule *mod; try { mod = simulation.selectNextModule(); if (!mod) throw cTerminationException("scheduler interrupted while waiting"); // execute event simulation.doOneEvent(mod); printEventBanner(mod); checkTimeLimits(); if (sigint_received) throw cTerminationException("SIGINT or SIGTERM received, exiting"); } catch (std::exception& e) { disable_tracing = false; stoppedWithException(e); displayException(e); } disable_tracing = false; stopClock(); deinstallSignalHandler(); }
int main(int argc,char *argv[]) { daemon_init(); if(chdir(XJOJHOME) < 0) { BLOG("can't change dir to XJOJHOME", SYSCALL_ERROR); return 1; } if(write_pid("judge.pid") < 0) { return 1; } Config *config = Config::getInstant(); Log::getInstance(config->getLogRoot() + config->getLogFileName()); if(config->isIniError()) { BLOG(config->getErrorMesg(), ERROR); return 1; } if(!config->initConfig(argc, argv)) { BLOG(config->getErrorMesg(), ERROR); return 1; } removeDir(Config::getInstant()->getTmpUserPath().c_str(), false); int totThread = Config::getInstant()->getThreadNumber(); if(totThread <= 0) { BLOG("Thread number is less or equal than 0", ERROR); return 1; } int fd; if((fd = open("/dev/null", O_RDWR, 0600)) == -1 || dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) return 1; // Write data to a closed socket will cause SIGPIPE signal installSignalHandler(SIGPIPE, SIG_IGN, 0); std::string host = Config::getInstant()->getServer().first; int port = Config::getInstant()->getServer().second; std::vector<JudgeThread *> threads(totThread); for(int i = 0; i < totThread; i++) { threads[i] = new JudgeThread(i + 1); threads[i]->setServerAddress(host); threads[i]->setPort(port); } for(int i = 0; i < totThread; i++) { threads[i]->start(); } for(int i = 0; i < totThread; i++) { threads[i]->join(); } return 0; }
// installs the signal handling for whatever signal set that is currently active // If you want to setup your own signal handling then // You should instead call overrideSetupSignals() void installCrashHandler() { installSignalHandler(); }