/** * Startup method for the module */ void PCAPExporterPipe::performStart() { time(&last_check); if(last_check == (time_t) -1) THROWEXCEPTION("time() failed"); registerSignalHandlers(); msg(MSG_INFO, "Started PCAPExporterPipe with the following parameters:"); if (fifoReaderCmd != ""){ msg(MSG_INFO, " - fifoReaderCmd = %s", fifoReaderCmd.c_str()); msg(MSG_INFO, " - fifoReaderPid = %d", fifoReaderPid); } else { THROWEXCEPTION("No fifoReaderCmd specified!"); } if (logFileName != ""){ msg(MSG_INFO, " - logfileBaseName = %s", logFileName.c_str()); msg(MSG_INFO, " - appenddate = %s", appenddate ? "true" : "false"); } else msg(MSG_ERROR, "No Logfile specified - dumping to stdout!"); msg(MSG_INFO, " - sigKillTimeout = %d" , sigKillTimeout); msg(MSG_INFO, " - restartInterval = %u ms" , restartInterval); startProcess(); }
int main(int argc, char **argv) { unsigned timeout = 1, connected = 0; parseArguments(argc, argv); daemonize(); registerSignalHandlers(); termInit(); atexit(disconnectFromMPD); initCodesets(); do { if (!connected) { timeout = timeout <= 30 ? timeout * 2 : 60; connected = connectToMPD(timeout > 10 ? 10 : timeout); } if (connected) { timeout = 1; connected = getSong(); } display(timeout); } while (!done()); return 0; }
void NcursesEditorView::start() { initscr(); raw(); noecho(); keypad(stdscr, 1); registerSignalHandlers(this); }
Ptr<Coroutine> main() { // Returns the "main" coroutine (i.e., the main coroutine) static Ptr<Coroutine> main; if (!main) { main.reset(new Coroutine); registerSignalHandlers(); } return main; }
Server::Server(Handler& handler, unsigned short port) : pool(handler) , port(port) { registerSignalHandlers(); if (::pipe(pipe) == -1) { throw ServerException("Failed to create server's pipe."); } socket = Socket::createINET("0.0.0.0", std::to_string(port)); this->port = socket.getPort(); }
/** * Receives a packet and tries to write the packet into the ringbuffer */ void PCAPExporterMem::receive(Packet* packet) { DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() called"); if (onRestart) { DPRINTF("Dropping incoming packet, as attached process is not ready"); DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended"); packet->removeReference(); return; } if (fifoReaderPid == 0) { msg(MSG_VDEBUG, "fifoReaderPid = 0...this might happen during reconfiguration"); DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended"); packet->removeReference(); return; } if (restartInterval) { if (nextRestart.tv_sec==0) { DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): updating nextRestart"); nextRestart = packet->timestamp; nextRestart.tv_sec += restartInterval; } else if (compareTime(nextRestart, packet->timestamp)<0) { DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): restarting process"); // we need to unregister our signal handlers, as we get race conditions with the signal handler for restarting the process unregisterSignalHandlers(); stopProcess(); startProcess(); registerSignalHandlers(); DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): updating nextRestart"); nextRestart.tv_sec += ((packet->timestamp.tv_sec-nextRestart.tv_sec)/restartInterval+1)*restartInterval; } } if (writeIntoMemory(packet)) { statPktsForwarded++; statBytesForwarded += packet->data_length; DPRINTFL(MSG_VDEBUG, "Wrote packet at pos %u", *nextWrite); } else { batchUpdate(); statPktsDropped++; statBytesDropped += packet->data_length; DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): dropped packet"); } packet->removeReference(); DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended"); }
int main(const int argc, const char* argv[]) { setbuf(stdout, NULL); setbuf(stderr, NULL); checkUser(); if (chdir(etmWorkingDir) == -1) { perror("chdir"); exit(EXIT_FAILURE); } umask(006); cleanPreviousRun(); registerSignalHandlers(); setupSocketServer(); fdLock = open(LOCK_PATH, O_CREAT | O_RDWR, 0666); if (fdLock == -1) { perror("Open lock file"); exit(EXIT_SUCCESS); } int rc = flock(fdLock, LOCK_EX | LOCK_NB); if (rc == 0) { // success puts("xwared: unlocked."); fdETMLock = open(ETM_LOCK_PATH, O_CREAT | O_RDWR, 0666); if (fdETMLock == -1) { perror("Open ETM lock file"); exit(EXIT_SUCCESS); } // Check if ETM should run at start GKeyFile* configFile = g_key_file_new(); if (g_key_file_load_from_file(configFile, CONFIG_PATH, G_KEY_FILE_NONE, NULL) == 0) { fprintf(stderr, "xwared: cannot load settings.ini, use default value\n"); } GError* gErr = NULL; gboolean etmStart = g_key_file_get_boolean(configFile, "xwared", "startetm", &gErr); if (gErr == NULL) { if (etmStart == FALSE) { toRunETM = 0; } } else { fprintf(stderr, "xwared: %s, use default value\n", gErr->message); g_error_free(gErr); } g_key_file_free(configFile); while(1) { runETM(); } } else { if (errno == EWOULDBLOCK) { puts("xwared: locked."); exit(EXIT_FAILURE); } perror("flock"); } unload(); exit(EXIT_SUCCESS); }
// initialize state variable and copy command line arguments void initializeState(char **argv, struct scalpelState *state) { char** argvcopy = argv; int sss; int i; // Allocate memory for the state state->imagefile = (char*) malloc(MAX_STRING_LENGTH * sizeof(char)); state->inputFileList = (char*) malloc(MAX_STRING_LENGTH * sizeof(char)); state->conffile = (char*) malloc(MAX_STRING_LENGTH * sizeof(char)); state->outputdirectory = (char*) malloc(MAX_STRING_LENGTH * sizeof(char)); state->invocation = (char*) malloc(MAX_STRING_LENGTH * sizeof(char)); // GGRIII: memory allocation made more sane, because we're storing // more information in Scalpel than foremost had to, for each file // type. sss = (MAX_FILE_TYPES+1)*sizeof(struct SearchSpecLine); state->SearchSpec = (struct SearchSpecLine*) malloc(sss); state->specLines = 0; // GGRIII: initialize header/footer offset data, carved file count, // et al. The header/footer database is re-initialized in "dig.c" // after each image file is processed (numfilestocarve and // organizeDirNum are not). Storage for the header/footer offsets // will be reallocated as needed. for (i=0; i < MAX_FILE_TYPES; i++) { state->SearchSpec[i].offsets.headers=0; state->SearchSpec[i].offsets.footers=0; state->SearchSpec[i].offsets.numheaders=0; state->SearchSpec[i].offsets.numfooters=0; state->SearchSpec[i].offsets.headerstorage=0; state->SearchSpec[i].offsets.footerstorage=0; state->SearchSpec[i].numfilestocarve=0; state->SearchSpec[i].organizeDirNum=0; } state->fileswritten = 0; state->skip = 0; state->organizeMaxFilesPerSub=MAX_FILES_PER_SUBDIRECTORY; state->modeVerbose = FALSE; state->modeNoSuffix = FALSE; state->useInputFileList = FALSE; state->carveWithMissingFooters=FALSE; state->noSearchOverlap=FALSE; state->generateHeaderFooterDatabase=FALSE; state->updateCoverageBlockmap=FALSE; state->useCoverageBlockmap=FALSE; state->blockAlignedOnly=FALSE; state->organizeSubdirectories=TRUE; state->previewMode=FALSE; state->ignoreEmbedded=FALSE; state->auditFile = NULL; // default values for output directory, config file, wildcard character, // coverage blockmap directory strncpy(state->outputdirectory,SCALPEL_DEFAULT_OUTPUT_DIR, strlen(SCALPEL_DEFAULT_OUTPUT_DIR)); strncpy(state->conffile,SCALPEL_DEFAULT_CONFIG_FILE, MAX_STRING_LENGTH); state->coveragedirectory = state->outputdirectory; wildcard = SCALPEL_DEFAULT_WILDCARD; signal_caught = 0; state->invocation[0]=0; // copy the invocation string into the state do { strncat(state->invocation, *argvcopy, MAX_STRING_LENGTH-strlen(state->invocation)); strncat(state->invocation, " ", MAX_STRING_LENGTH-strlen(state->invocation)); ++argvcopy; } while (*argvcopy); registerSignalHandlers(); }
/** * Writes a packet into the pipe */ void PCAPExporterPipe::receive(Packet* packet) { DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() called"); if (onRestart){ DPRINTF("Dropping incoming packet, as attached process is not ready"); DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended"); packet->removeReference(); return; } if (fifoReaderPid == 0){ msg(MSG_VDEBUG, "fifoReaderPid = 0...this might happen during reconfiguration"); DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended"); packet->removeReference(); return; } if (restartInterval) { if (nextRestart.tv_sec==0) { DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): updating nextRestart"); nextRestart = packet->timestamp; struct timeval tv = { restartInterval/1000, (restartInterval % 1000)*1000 }; timeval_add(&nextRestart, &tv); } else if (compareTime(nextRestart, packet->timestamp)<0) { DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): restarting process"); // we need to unregister our signal handlers, as we get race conditions with the signal handler for restarting the process unregisterSignalHandlers(); stopProcess(); startProcess(); registerSignalHandlers(); DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): updating nextRestart"); timeval tvdiff; timeval_subtract(&tvdiff, &packet->timestamp, &nextRestart); uint32_t msdiff = tvdiff.tv_sec*1000+tvdiff.tv_usec/1000; uint32_t mswait = (msdiff/restartInterval+1)*restartInterval; tvdiff.tv_sec = mswait/1000; tvdiff.tv_usec = (mswait%1000)*1000; timeval_add(&nextRestart, &tvdiff); } } // write packet static struct pcap_pkthdr packetHeader; packetHeader.ts = packet->timestamp; packetHeader.caplen = packet->data_length; packetHeader.len = packet->pcapPacketLength; struct iovec wvec[2]; wvec[0].iov_base = &packetHeader; wvec[0].iov_len = sizeof(packetHeader); wvec[1].iov_base = packet->data; wvec[1].iov_len = packetHeader.caplen; if (writev(pcapFile, wvec, 2)!=(ssize_t)(sizeof(packetHeader)+packetHeader.caplen)) { if (errno==EAGAIN) { // pipe is full, drop packet statBytesDropped += packet->data_length; statPktsDropped++; } else THROWEXCEPTION("PCAPExporterPipe: failed to write, error %u (%s)", errno, strerror(errno)); } else { statBytesForwarded += packet->data_length; statPktsForwarded++; } packet->removeReference(); DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended"); }
static void sme_schedule_init(LinuxUserSpaceContext* context, int argc, char **argv) { CsrBool wifion = FALSE; CsrBool flightmode = FALSE; int i; #ifdef IPC_IP CsrUint32 ipc_portNumber = PORT_NUMBER_Q; #ifdef CSR_AMP_ENABLE CsrUint32 ipc_hciPortNumber = HCI_PORT_NUMBER_Q; CsrUint32 ipc_aclPortNumber = ACL_PORT_NUMBER_Q; #endif #endif #ifdef IPC_CHARDEVICE const char* connectStr = CHAR_DEVICE_Q; #endif sme_trace_entry((TR_FSM, "sme_schedule_init()")); CsrMemSet(&getMainData(linuxContext)->address, 0xFF, sizeof(unifi_MACAddress)); getMainData(linuxContext)->mibfiles.numElements = 0; getMainData(linuxContext)->mibfiles.dataList = (unifi_DataBlock*)CsrPmalloc(sizeof(unifi_DataBlock) * MAX_MIB_FILES); getMainData(linuxContext)->calibrationDataFile = NULL; getMainData(linuxContext)->calibrationData.length = 0; getMainData(linuxContext)->calibrationData.data = NULL; getMainData(linuxContext)->nextCaldataSaveTime = fsm_get_time_of_day_ms(context->fsmContext) + CALDATA_SAVE_INTERVAL_MS; getMainData(linuxContext)->exitOnError = FALSE; getMainData(linuxContext)->stopOnError = FALSE; #ifdef CSR_AMP_ENABLE context->palDataFsmContext = paldata_init(linuxContext); sme_install_wakeup_callback(context->palDataFsmContext, fsm_wakeup_callback); #endif /* Initialise basic constructs used by the SME */ context->fsmContext = sme_init(context, NULL); sme_install_wakeup_callback(context->fsmContext, fsm_wakeup_callback); #ifdef CSR_WIFI_NME_ENABLE context->nmeFsmContext = csr_wifi_nme_init(linuxContext, NULL); csr_wifi_nme_install_wakeup_callback(context->nmeFsmContext, fsm_wakeup_callback); #endif #ifdef FSM_DEBUG fsm_install_on_transition_callback(context->fsmContext, fsm_on_transition_trace_callback); fsm_install_unhandled_event_callback(context->fsmContext, fsm_on_unhandled_trace_callback); fsm_install_save_event_callback(context->fsmContext, fsm_on_saved_trace_callback); fsm_install_invalid_event_callback(context->fsmContext, fsm_on_invalid_trace_callback); fsm_install_ignore_event_callback(context->fsmContext, fsm_on_ignored_trace_callback); #ifdef CSR_WIFI_NME_ENABLE fsm_install_on_transition_callback(context->nmeFsmContext, nme_on_transition_trace_callback); fsm_install_unhandled_event_callback(context->nmeFsmContext, nme_on_unhandled_trace_callback); fsm_install_save_event_callback(context->nmeFsmContext, nme_on_saved_trace_callback); fsm_install_invalid_event_callback(context->nmeFsmContext, nme_on_invalid_trace_callback); fsm_install_ignore_event_callback(context->nmeFsmContext, nme_on_ignored_trace_callback); #endif #endif registerSignalHandlers(); /* If no args print the usage incase the user does not know what the help option is */ if (argc == 1) { print_usage(); } for (i = 1; i < argc; i++) { if (CsrStrNCmp(argv[i], "-ipc_port:", 10) == 0) { #ifdef IPC_IP ipc_portNumber = (CsrUint32)atoi(&argv[i][10]); sme_trace_info((TR_IPC, "sme_schedule_init() : IPC Port override -> %s :: %d", argv[i], ipc_portNumber)); #endif continue; } #ifdef CSR_AMP_ENABLE if (CsrStrNCmp(argv[i], "-ipc_hciport:", 13) == 0) { #ifdef IPC_IP ipc_hciPortNumber = (CsrUint32)atoi(&argv[i][13]); sme_trace_info((TR_IPC, "sme_schedule_init() : HCI IPC Port override -> %s :: %d", argv[i], ipc_hciPortNumber)); #endif continue; } if (CsrStrNCmp(argv[i], "-ipc_aclport:", 13) == 0) { #ifdef IPC_IP ipc_aclPortNumber = (CsrUint32)atoi(&argv[i][13]); sme_trace_info((TR_IPC, "sme_schedule_init() : ACL IPC Port override -> %s :: %d", argv[i], ipc_aclPortNumber)); #endif continue; } #endif /* TODO :: This is depricated... Remove! */ if (CsrStrNCmp(argv[i], "-ipc_connect=", 13) == 0) { #ifdef IPC_CHARDEVICE connectStr = &argv[i][13]; sme_trace_crit((TR_IPC, "sme_schedule_init() : -ipc_connect option is depricated. DO NOT USE!")); sme_trace_info((TR_IPC, "sme_schedule_init() : IPC Connect String -> %s :: %s", argv[i], connectStr)); #endif continue; } if (CsrStrNCmp(argv[i], "-dev=", 5) == 0) { #ifdef IPC_CHARDEVICE connectStr = &argv[i][5]; sme_trace_info((TR_IPC, "sme_schedule_init() : char device -> %s :: %s", argv[i], connectStr)); #endif continue; } if (CsrStrNCmp(argv[i], "-paldatadev=", 12) == 0) { continue; } #ifdef CSR_AMP_ENABLE if (CsrStrNCmp(argv[i], "-palselectchannel=", 18) == 0) { int len = CsrStrLen(argv[i]); char* str = (char*)CsrPmalloc(len); CsrMemCpy(str,&(argv[i][1]), len-1); str[len-1] = '\0'; sme_trace_info((TR_IPC, "sme_schedule_init() : pal channel to select -> %s :: %d , len-%d,str-%s", argv[i], (CsrUint8)atoi(&argv[i][18]),len,str)); unifi_dbg_cmd_req(context->fsmContext, str); continue; } if (CsrStrNCmp(argv[i], "-paldisableqos", 18) == 0) { int len = CsrStrLen(argv[i]); char* str = (char*)CsrPmalloc(len); CsrMemCpy(str,&(argv[i][1]), len-1); str[len-1] = '\0'; sme_trace_info((TR_IPC, "sme_schedule_init() : disable qos to select -%s , len-%d,str-%s", argv[i],len,str)); unifi_dbg_cmd_req(context->fsmContext, str); continue; } if (CsrStrNCmp(argv[i], "-paldisablesecurity", 18) == 0) { int len = CsrStrLen(argv[i]); char* str = (char*)CsrPmalloc(len); CsrMemCpy(str,&(argv[i][1]), len-1); str[len-1] = '\0'; sme_trace_info((TR_IPC, "sme_schedule_init() : disable qos to select -%s", argv[i])); unifi_dbg_cmd_req(context->fsmContext, str); continue; } #endif if (CsrStrNCmp(argv[i], "-flightmode", 11) == 0) { flightmode = TRUE; sme_trace_info((TR_IPC, "sme_schedule_init() : unifi_mgt_wifi_flightmode_req will be sent on connect -> %s", argv[i])); continue; } if (CsrStrNCmp(argv[i], "-wifion", 7) == 0) { wifion = TRUE; sme_trace_info((TR_IPC, "sme_schedule_init() : unifi_mgt_wifi_on_req will be sent on connect -> %s", argv[i])); continue; } if (CsrStrNCmp(argv[i], "-mac=", 5) == 0) { loadMacAddress(&argv[i][5], &getMainData(linuxContext)->address); sme_trace_info((TR_IPC, "sme_schedule_init() : macAddress file -> %s", argv[i])); sme_trace_info((TR_IPC, "sme_schedule_init() : macAddress -> %s", trace_unifi_MACAddress(getMainData(linuxContext)->address, getMainData(linuxContext)->traceMacAddressBuffer))); continue; } if (CsrStrNCmp(argv[i], "-mib=", 5) == 0) { loadMibfile(&argv[i][5], &getMainData(linuxContext)->mibfiles); sme_trace_info((TR_IPC, "sme_schedule_init() : mib file -> %s", argv[i])); continue; } if (CsrStrNCmp(argv[i], "-cal=", 5) == 0) { getMainData(linuxContext)->calibrationDataFile = &argv[i][5]; (void)loadfile(getMainData(linuxContext)->calibrationDataFile, &getMainData(linuxContext)->calibrationData); sme_trace_info((TR_IPC, "sme_schedule_init() : cal file -> %s", getMainData(linuxContext)->calibrationDataFile)); continue; } /* Skip -sme_trace:... as the sme trace module will handle these */ if (CsrStrNCmp(argv[i], "-sme_trace:", 11) == 0) { continue; } if (CsrStrNCmp(argv[i], "-v", CsrStrLen(argv[i])) == 0) { print_versions(); exit(EXIT_CODE_NORMAL_EXIT); } if (CsrStrNCmp(argv[i], "-exitOnError", CsrStrLen(argv[i])) == 0) { getMainData(linuxContext)->exitOnError = TRUE; continue; } if (CsrStrNCmp(argv[i], "-stopOnError", CsrStrLen(argv[i])) == 0) { getMainData(linuxContext)->stopOnError = TRUE; continue; } if (CsrStrNCmp(argv[i], "-h", CsrStrLen(argv[i])) == 0) { print_usage(); exit(EXIT_CODE_WIFION_ERROR); } print_usage(); sme_trace_error((TR_IPC, "error : Unknown commandline option : %s", argv[i])); exit(EXIT_CODE_WIFION_ERROR); } #ifdef IPC_CHARDEVICE if (connectStr) { getMainData(context)->charIpcCon = ipc_chardevice_connect(connectStr, NULL, NULL, NULL, NULL); if (getMainData(context)->charIpcCon == NULL) { sme_trace_crit((TR_IPC, "sme_schedule_init() : char device connect to %s failed", connectStr)); exit(EXIT_CODE_WIFION_ERROR); } } #endif #ifdef IPC_IP getMainData(context)->ipIpcCon = ipc_ip_create((int)ipc_portNumber, NULL, NULL, NULL, NULL); if (getMainData(context)->ipIpcCon == NULL) { sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_portNumber)); exit(EXIT_CODE_WIFION_ERROR); } #ifdef CSR_AMP_ENABLE getMainData(context)->ipHciIpcCon = ipc_ip_create((int)ipc_hciPortNumber, NULL, NULL, NULL, NULL); if (getMainData(context)->ipHciIpcCon == NULL) { sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_hciPortNumber)); exit(EXIT_CODE_WIFION_ERROR); } getMainData(context)->ipAclIpcCon = ipc_ip_create((int)ipc_aclPortNumber, NULL, NULL, NULL, NULL); if (getMainData(context)->ipAclIpcCon == NULL) { sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_aclPortNumber)); exit(EXIT_CODE_WIFION_ERROR); } #endif #endif if (getMainData(linuxContext)->calibrationData.length) { unifi_AppValue appValue; appValue.id = unifi_CalibrationDataValue; appValue.unifi_Value_union.calibrationData = getMainData(linuxContext)->calibrationData; unifi_mgt_claim_sync_access(linuxContext->fsmContext); (void)unifi_mgt_set_value(linuxContext->fsmContext, &appValue); unifi_mgt_release_sync_access(linuxContext->fsmContext); } if (flightmode) { unifi_mgt_wifi_flightmode_req(linuxContext->fsmContext, NULL, &getMainData(context)->address, getMainData(linuxContext)->mibfiles.numElements, getMainData(linuxContext)->mibfiles.dataList); } if (wifion) { /* Set the nextCaldataSaveTime to 1 minute from now */ getMainData(linuxContext)->nextCaldataSaveTime = fsm_get_time_of_day_ms(context->fsmContext) + CALDATA_INITIAL_SAVE_INTERVAL_MS; unifi_mgt_wifi_on_req(linuxContext->fsmContext, NULL, &getMainData(context)->address, getMainData(linuxContext)->mibfiles.numElements, getMainData(linuxContext)->mibfiles.dataList); } }