bool CrashHandlerPOSIX::registerCrashHandlers() { arx_assert(m_pPreviousCrashHandlers == 0); m_pPreviousCrashHandlers = new PlatformCrashHandlers; // Catch 'bad' signals so we can print some debug output. #ifdef SIGILL registerSignalHandler(SIGILL, m_pPreviousCrashHandlers->illHandler); #endif #ifdef SIGABRT registerSignalHandler(SIGABRT, m_pPreviousCrashHandlers->abrtHandler); #endif #ifdef SIGBUS registerSignalHandler(SIGBUS, m_pPreviousCrashHandlers->busHandler); #endif #ifdef SIGFPE registerSignalHandler(SIGFPE, m_pPreviousCrashHandlers->fpeHandler); #endif #ifdef SIGSEGV registerSignalHandler(SIGSEGV, m_pPreviousCrashHandlers->segvHandler); #endif // We must also register the main thread crash handlers. return registerThreadCrashHandlers(); }
/* * This is the first type of heuristic we can use to guess the boundaries. * Here we are provoking a SIGSEGV by overflowing the stack. Then we get * the faulty adress directly. */ void detectStackBoundaries(jthread_t jtid, int mainThreadStackSize) { static volatile char * volatile guessPointer; void *old_sigsegv, *old_sigbus; setupSigAltStack(); #if defined(SIGSEGV) old_sigsegv = registerSyncSignalHandler(SIGSEGV, stackOverflowDetector); #endif #if defined(SIGBUS) old_sigbus = registerSyncSignalHandler(SIGBUS, stackOverflowDetector); #endif if (JTHREAD_SETJMP(outOfLoop) == 0) { uintp pageSize = getpagesize(); guessPointer = (char *)((uintp)(&jtid) & ~(pageSize-1)); while (1) { #if defined(STACK_GROWS_UP) guessPointer -= pageSize; #else guessPointer += pageSize; #endif kaffeNoopFunc(*guessPointer); } } /* Here we have detected one the boundary of the stack. * If stack grows up then it is the upper boundary. In the other * case we have the lower boundary. As we know the stack size we * may guess the other boundary. */ #if defined(STACK_GROWS_UP) jtid->stackBase = guessPointer; jtid->stackEnd = (char *)jtid->stackBase + mainThreadStackSize; jtid->restorePoint = jtid->stackEnd; #else jtid->stackEnd = guessPointer; jtid->stackBase = (char *)jtid->stackEnd - mainThreadStackSize; jtid->restorePoint = jtid->stackBase; #endif #if defined(SIGSEGV) registerSignalHandler(SIGSEGV, old_sigsegv, false); #endif #if defined(SIGBUS) registerSignalHandler(SIGBUS, old_sigbus, false); #endif }
/* * Register a signal handler for a synchronous signal. */ void * registerSyncSignalHandler(int sig, void* handler) { #if !defined(NDEBUG) /* Only used in assert. */ int validSig = 0 #if defined(SIGFPE) || (sig == SIGFPE) #endif /* defined(SIGFPE) */ #if defined(SIGSEGV) || (sig == SIGSEGV) #endif /* defined(SIGSEGV) */ #if defined(SIGBUS) || (sig == SIGBUS) #endif /* defined(SIGBUS) */ ; #endif /* !defined(NDEBUG) */ assert(handler != NULL); assert(validSig); /* Register a synchronous signal handler */ return registerSignalHandler(sig, handler, false); }
/* * Register a handler for an asynchronous signal. */ void * registerAsyncSignalHandler(int sig, void* handler) { #if !defined(NDEBUG) /* Only used in assert. */ int validSig = (sig == SIGALRM) #if defined(SIGVTALRM) || (sig == SIGVTALRM) #endif /* defined(SIGVTALRM) */ || (sig == SIGIO) || (sig == SIGUSR1) || (sig == SIGUSR2) || (sig == SIGCHLD); #endif /* !defined(NDEBUG) */ /* Make sure its really an asynchronous signal being registered. */ assert(handler != NULL); assert(validSig); /* Can't have the #ifdef in a macro arg. */ /* * Register an asynchronous signal handler that will block all * other asynchronous signals while the handler is running. */ return registerSignalHandler(sig, handler, true); }
int main(int argc, char *argv[]) { bool ret = true; s3ext_loglevel = EXT_ERROR; s3ext_logtype = STDERR_LOG; if (argc == 1) { printUsage(stderr); exit(EXIT_FAILURE); } /* Prepare to receive interrupts */ registerSignalHandler(); map<char, string> optionPairs = parseCommandLineArgs(argc, argv); validateCommandLineArgs(optionPairs); if (!optionPairs.empty()) { const char *arg = optionPairs.begin()->second.c_str(); switch (optionPairs.begin()->first) { case 'c': ret = checkConfig(arg); break; case 'd': ret = downloadS3(arg); break; case 'u': case 'f': ret = uploadS3(optionPairs['u'].c_str(), optionPairs['f'].c_str()); break; case 'h': printUsage(stdout); break; case 't': printTemplate(); break; default: printUsage(stderr); exit(EXIT_FAILURE); } } // Abort should not print the failed info if (ret || S3QueryIsAbortInProgress()) { exit(EXIT_SUCCESS); } else { fprintf(stderr, "Failed. Please check the arguments and configuration file.\n\n"); printUsage(stderr); exit(EXIT_FAILURE); } }
void InternodeSyncer::run() { try { registerSignalHandler(); syncLoop(); log.log(Log_DEBUG, "Component stopped."); } catch(std::exception& e) { PThread::getCurrentThreadApp()->handleComponentException(e); } saveTargetMappings(); }
/** * This is a singleton component, which is started through its control frontend on-demand at * runtime and terminates when it's done. * We have to ensure (in cooperation with the control frontend) that we don't get multiple instances * of this thread running at the same time. */ void FileResyncerGatherSlave::run() { setIsRunning(true); try { registerSignalHandler(); walkAllMetadata(); log.log(Log_DEBUG, "Component stopped."); } catch(std::exception& e) { PThread::getCurrentThreadApp()->handleComponentException(e); } setIsRunning(false); }
void Worker::run() { try { registerSignalHandler(); initBuffers(); if(workType == QueueWorkType_DIRECT) workLoopDirectWork(); else workLoopAnyWork(); log.log(4, "Component stopped."); } catch(std::exception& e) { PThread::getCurrentThreadApp()->handleComponentException(e); } }
void DataRequestorStats::run() { try { log.log(Log_DEBUG, "Component started."); if (!setStatusToRunning() ) return; registerSignalHandler(); requestLoop(); log.log(Log_DEBUG, "Component stopped."); setStatusToStopped(); } catch (std::exception& e) { Program::getApp()->handleComponentException(e); } }
void App::initDataObjects(int argc, char** argv) throw(InvalidConfigException) { // this->cfg = new Config(argc, argv); this->netFilter = new NetFilter(cfg->getConnNetFilterFile() ); this->tcpOnlyFilter = new NetFilter(cfg->getConnTcpOnlyFilterFile() ); this->logger = new Logger(cfg); // mute the standard logger if it has not been explicitly enabled if(!this->cfg->getLogEnabled() ) this->logger->setLogLevel(0); this->log = new LogContext("App"); this->allowedInterfaces = new StringList(); std::string interfacesFilename = this->cfg->getConnInterfacesFile(); if(interfacesFilename.length() ) this->cfg->loadStringListFile(interfacesFilename.c_str(), *this->allowedInterfaces); RDMASocket::rdmaForkInitOnce(); this->targetMapper = new TargetMapper(); this->mirrorBuddyGroupMapper = new MirrorBuddyGroupMapper(this->targetMapper); this->targetStateStore = new TargetStateStore(); this->mgmtNodes = new NodeStoreServers(NODETYPE_Mgmt, false); this->metaNodes = new NodeStoreServers(NODETYPE_Meta, false); this->storageNodes = new NodeStoreServers(NODETYPE_Storage, false); this->clientNodes = new NodeStoreClients(false); this->workQueue = new MultiWorkQueue(); this->ackStore = new AcknowledgmentStore(); initLocalNodeInfo(); registerSignalHandler(); this->netMessageFactory = new NetMessageFactory(); }
void ServerUtil::setupSignalHandlers(const SignalHandler& handler) { registerSignalHandler(handler); setupSignalHandlers(); }
/* * Ignore the given signal. */ void KaffeJThread_ignoreSignal(int sig) { registerSignalHandler(sig, SIG_IGN, false); }
/* * Clear the given signal (i.e., restore the default behavior of the signal) */ void clearSignal(int sig) { registerSignalHandler(sig, SIG_DFL, false); }
/* * Register a handler for a terminal (i.e., process-killing) signal. * These handlers must exit(). */ void registerTerminalSignal(int sig, void* handler) { assert((sig == SIGINT) || (sig == SIGTERM)); registerSignalHandler(sig, handler, true); }
/** * Main function * */ int main(int argc, char* argv[]) { int i, j, cmdargv_len; int rc = 0; int pipeExists = 0; char *formattedInput = NULL; char *userInput = NULL; char **cmdargv = NULL ; char *cdCmd = NULL; char *pipeCmd = NULL; if((userInput = malloc(sizeof(char)*MAX_CMD_LEN)) == NULL) ERROR("Failed malloc\n"); cmdargv_len = sizeof(char*) * MAX_CMD_ARGS; if((cmdargv = (char**) malloc(cmdargv_len)) == NULL) { ERROR("Failed malloc\n"); } else { memset(cmdargv, '\0', sizeof(char*) * MAX_CMD_ARGS); } registerSignalHandler(); while(1) { printf("_dash > "); got_sigint = false; if (fgets(userInput, MAX_CMD_LEN, stdin) == NULL) { if (got_sigint) { printf("\n"); continue; } else { // Ctrl+D return 0; } } // TODO: Sanitize user input! We're currently hoping the user is a // benelovent, sweet human being. HA! if( (formattedInput = malloc(sizeof(userInput))) == NULL ) ERROR("Failed malloc\n"); removeNewLine(userInput, formattedInput); // See if user wants out. if((strcmp("quit", formattedInput) == 0) || (strcmp("exit", formattedInput) == 0) || (strcmp("q", formattedInput) == 0)) { printf("Quitting!\n"); goto cleanup; } // Check to see if user wants to change working directories if( (cdCmd = strstr(formattedInput, "cd ")) != NULL ) { if(changeDir(cdCmd) != 0) ERROR("cd failed."); free(cdCmd); // No need to fork/exec, can just move on. continue; } // Check to see if user wants to pipe commands if( (pipeCmd = strstr(formattedInput, "|")) != NULL ) { pipeExists = 1; // Don't need to free pipeCmd bc freeing formattedInput will take // care of that for us. //free(pipeCmd); } parseUserInput(formattedInput, cmdargv); for(j=0; cmdargv[j] != NULL; j++) printf("%d: cmdargv[%d]: %s\n", __LINE__, j, cmdargv[j]); rc = execute_fork(cmdargv, pipeExists); ASSERT( rc != 0 ); pipeExists = 0; } /* Cleanup! */ cleanup: free(formattedInput); free(userInput); if (cmdargv) { for (i = 0; i < MAX_CMD_ARGS; i++) { free(cmdargv[i]); /* free(NULL) is ok with glibc */ } } free(cmdargv); printf("All finished.\n"); return 0; }
void SignalHandler::install(const std::vector<int>& signals) { for (const int& signal: signals) { registerSignalHandler(signal); } }