void HardRenderer::initPresentVSync(const bool vsync) { if(isLoaded()) return; if(vsync) initInfo()->flags |= SDL_RENDERER_PRESENTVSYNC; else initInfo()->flags &= ~Uint32(SDL_RENDERER_PRESENTVSYNC); }
void HardRenderer::initHardwareAccel(const bool accel) { if(isLoaded()) return; if(accel) initInfo()->flags |= SDL_RENDERER_ACCELERATED; else initInfo()->flags &= ~Uint32(SDL_RENDERER_ACCELERATED); }
int main() { ConnInfo info; MYSQL_RES *result; MYSQL_ROW *row; MYSQL_FIELD *field; initInfo(&info); createConnection(&info); mysql_query(info.conn, "select * from user_table"); result = mysql_use_result(info.conn); while((row = mysql_fetch_row(result)) != NULL) { printf("\n"); printf("id|%s\n", row[0] ? row[0] : "NULL"); printf("name|%s\n", row[1] ? row[1] : "NULL"); printf("pass|%s\n", row[2] ? row[2] : "NULL"); } // mysql_free_result(result); // mysql_close(info.conn); return 0; }
void MTMCScheduler::start() { isTerminated = false; MCThreadInfo initInfo(nRunThreads, -1); MTMCSimulator->prepare(initInfo); RNGThread.reset(new thread(boost::bind(std::mem_fun<void, MTMCScheduler>(&MTMCScheduler::genRN),this))); for (unsigned int i = 0; i<nRunThreads; i++) { MCThreadInfo threadInfo(nRunThreads,i); MCRunThreads[i].reset(new thread (boost::bind(std::mem_fun<void, MTMCScheduler,MCThreadInfo>(&MTMCScheduler::oneThreadSimu), this, threadInfo))); } RNGThread->join(); for (unsigned int i = 0; i<nRunThreads;i++) MCRunThreads[i]->join(); MTMCSimulator->postProcess(); }
jboolean saveToFile(JNIEnv* env, jobject thiz, jstring path, int w, int h, const char* filetype) { char const * filepath = env->GetStringUTFChars(path, NULL); imginfo_t imginfo; imginfo.pixwidth = w; imginfo.pixheight = h; initInfo(filetype); calc_dimensions(&imginfo, s_state->plist); FILE* f = fopen(filepath,"w+"); if(f) { struct backend_s * b = info.backend; if (b->init_f) { if(b->init_f(f) != 0) { fclose(f); return JNI_FALSE; } } b->page_f(f, s_state->plist, &imginfo); if (b->term_f) { if(b->term_f(f) != 0) { fclose(f); return JNI_FALSE; } } fclose(f); return JNI_TRUE; } return JNI_FALSE; }
bool HIDDevice::openDevice() { memset(&ReadOverlapped, 0, sizeof(OVERLAPPED)); Device = HIDManager->CreateHIDFile(DevDesc.Path.ToCStr()); if (Device == INVALID_HANDLE_VALUE) { OVR_DEBUG_LOG(("Failed 'CreateHIDFile' while opening device, error = 0x%X.", ::GetLastError())); Device = 0; return false; } if (!HIDManager->HidD_SetNumInputBuffers(Device, 128)) { OVR_ASSERT_LOG(false, ("Failed 'HidD_SetNumInputBuffers' while initializing device.")); ::CloseHandle(Device); Device = 0; return false; } // Create a manual-reset non-signaled event. ReadOverlapped.hEvent = ::CreateEvent(0, TRUE, FALSE, 0); if (!ReadOverlapped.hEvent) { OVR_ASSERT_LOG(false, ("Failed to create event.")); ::CloseHandle(Device); Device = 0; return false; } if (!initInfo()) { OVR_ASSERT_LOG(false, ("Failed to get HIDDevice info.")); ::CloseHandle(ReadOverlapped.hEvent); memset(&ReadOverlapped, 0, sizeof(OVERLAPPED)); ::CloseHandle(Device); Device = 0; return false; } if (!initializeRead()) { OVR_ASSERT_LOG(false, ("Failed to get intialize read for HIDDevice.")); ::CloseHandle(ReadOverlapped.hEvent); memset(&ReadOverlapped, 0, sizeof(OVERLAPPED)); ::CloseHandle(Device); Device = 0; return false; } return true; }
// Virtual notify from OnSipInitStateMachine of state changes // virtual call will occur during Poll() method void OnSipTapi::InitStateChange(OnSipInitStates::InitStates state,OnSipInitStateData stateData,StateChangeReason::eOnStateChangeReason reason) { Logger::log_debug( _T("OnSipTapi::InitStateChange state=%d reason=%d"), state, reason ); OnSipXmpp::InitStateChange( state, stateData, reason ); // Keep event data OnSipInitState initInfo(state,stateData,reason); m_lstInitEvents.push_back(initInfo); }
HardRenderer::HardRenderer(const shared_ptr<Window> &w, const bool hardwareAccel, const bool vSync, const int i): win(w), index(i) { auto inf = initInfo(); if(inf == NULL) return; inf->flags = 0; if(hardwareAccel) inf->flags |= SDL_RENDERER_ACCELERATED; if(vSync) inf->flags |= SDL_RENDERER_PRESENTVSYNC; }
const SUCCESS HardRenderer::load() { if(isLoaded()) return SUCCEEDED; if(win->load() < SUCCEEDED || initInfo() == NULL) return FAILED; if(setRenderer(SDL_CreateRenderer(win->getWindow(), index, initInfo()->flags)) < SUCCEEDED) return FAILED; SDL_SetRenderDrawColor(getRenderer(), 0, 0, 0, 0); Loadable::load(); clear(); getInfo(); return SUCCEEDED; }
void BaoGet::init(void *data){ m_tips = CCUIHELPER->createWidgetFromJsonFile("BaoGet.json"); BaoInfoParam* param = (BaoInfoParam*)data; int id = 0; if (param) { id = param->id; } CC_SAFE_DELETE(param); initInfo(id); setAnimType(WINDOW_ANIM_RIGHT); }
int main( void ){ disableWDT();// Stop watchdog timer initQueue(); initScheduler(); initButton(); initLed(); initComUart(); initInfo(); mainTask.cmdName = cmdNameMain; mainTask.user = main_user; mainTask.handler = &mainHandler; registerTask( &mainTask ); setDCOCLK( DCO_1M ); setSMCLK( SMCLK_DCO, CLK_DIV_1 ); if( getFreeMessage( &mainMessage ) == queue_ok ){ mainMessage->source = main_user; mainMessage->destination = led_user; mainMessage->id = MSG_ID_LED_GREEN; mainMessage->priority = normal_priority; mainMessage->event = undef_event; putMessage( mainMessage ); } if( getFreeMessage( &mainMessage ) == queue_ok){ mainMessage->destination = com_uart_user; mainMessage->source = main_user; mainMessage->id = MSG_ID_UART_WELCOME; putMessage( mainMessage ); } initCli(); enableTimerA0CCInterrupt(); setTimerA0Mode( TAMODE_CONT ); setTimerA0ClockSource( TA_SMCLK ); setTimerA0Divider( TA_DIV_1 ); __enable_interrupt(); __bis_SR_register( 0x18 ); //__bis_SR_register( 0x18 ); // LPM0 with interrupts enabled while( 1 ){}; return 0; }
namespace HighResolutionTime { static mach_timebase_info_data_t initInfo() { mach_timebase_info_data_t info; mach_timebase_info(&info); return info; } static mach_timebase_info_data_t sInfo = initInfo(); Timestamp now() { return mach_absolute_time() * sInfo.numer / sInfo.denom; } }
// TCL command interpreter int CsmaAloha::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if (argc==2) { if(strcasecmp(argv[1], "setAckMode") == 0) { ack_mode = CSMA_ACK_MODE; return TCL_OK; } else if(strcasecmp(argv[1], "setNoAckMode") == 0) { ack_mode = CSMA_NO_ACK_MODE; return TCL_OK; } else if(strcasecmp(argv[1], "initialize") == 0) { if (initialized == false) initInfo(); if (print_transitions) fout.open("/tmp/CSMAstateTransitions.txt",ios_base::app); return TCL_OK; } else if(strcasecmp(argv[1], "printTransitions") == 0) { print_transitions = true; return TCL_OK; } else if(strcasecmp(argv[1], "getQueueSize") == 0) { tcl.resultf("%d",Q.size()); return TCL_OK; } else if(strcasecmp(argv[1],"getUpLayersDataRx") == 0) { tcl.resultf("%d",getUpLayersDataPktsRx()); return TCL_OK; } } else if(argc==3) { if(strcasecmp(argv[1],"setMacAddr") == 0) { addr = atoi(argv[2]); if(debug_) cout << "Csma_Aloha MAC address of current node is " << addr <<endl; return TCL_OK; } } return MMac::command(argc, argv); }
bool Teacher::login(QString loginNumber, QString password, DBInfo dbInfo) { if (!tSql->connectToDB()) return false; if (password == tSql->getPwd(loginNumber) && 0 == tSql->getLevel(loginNumber)) { userInfo.number = loginNumber; initInfo(); return true; } else { QMessageBox::warning(0, QObject::tr("ERROR"), QObject::tr("Wrong Login Infomation!")); return false; } tSql->closeConnection(); }
/** * With big Screen the plan could be to 'detach' the image * window if visible and to create a ne wone * init* already supports it but I make no use of it for * now. We set filename and raise * * ### FIXME and talk to alwin */ void PMainWindow::slotShowInfo( const QString& inf ) { if (m_disp && m_disp->fullScreen() && m_disp->isVisible()) { return; } if ( !m_info ) { initInfo(); } m_info->setPath( inf ); if (m_SmallWindow) { m_aNext->removeFrom(toolBar); m_aPrevious->removeFrom(toolBar); fsButton->hide(); } m_aNext->setEnabled(false); m_aPrevious->setEnabled(false); m_aDirUp->setEnabled(false); m_aShowInfo->setEnabled(false); m_aViewfile->setEnabled(true); m_aStartSlide->setEnabled(false); m_stack->raiseWidget( ImageInfo ); }
void MainWindow::login() { if (isSqlSetted) { int status; LoginDialog *loginDlg = new LoginDialog; loginDlg->setWindowIcon(QIcon(":/resources/icon/login.png")); status = loginDlg->exec(); //user = new Teacher(dbInfo); if (loginDlg->isStuChecked()) user = new Student(dbInfo); else if (loginDlg->isTeaChecked()) user = new Teacher(dbInfo); else if (loginDlg->isAdmChecked()) user = new Administrator(dbInfo); else { if (status == QDialog::Accepted) QMessageBox::warning(this, tr("ERROR"), tr("ERROR occurs while creating user object!")); return; } // user->login("T00000001", "123", dbInfo); // initInfo(); if (user->login(loginDlg->getLoginNumber(), loginDlg->getPassword(), dbInfo)) initInfo(); //初始化界面 delete loginDlg; } else { QMessageBox::warning(this, tr("SQL"), tr("SQL not Setted!")); getDBInfo(); } }
void RecoveryByL2::doL2(double pbeta) { int i, j; beta = pbeta; p = new double[(int)meshmodel->numvertices * 3 + (int)meshmodel->numtriangles * 3]; v = new double[(int)meshmodel->numvertices * 3]; initInfo(); updateInfo(); initVerThreeSeparateRelation(); for(i = 0;i < (int)meshmodel->numvertices;i++){ for(j = 0;j < 3;j++){ p[i * 3 + j] = model[3 * i + j]; } } for(i = (int)meshmodel->numvertices * 3;i < (int)meshmodel->numvertices * 3 + (int)meshmodel->numtriangles * 3;i++){ p[i] = 0; } SubSolving s_l0(verThreeSeparateRelation, info, infocnt, arinfocnt, (int)meshmodel->numvertices * 3); s_l0.init(); //传入beta,arpha s_l0.getParameter(p, v, info, beta, arpha); s_l0.update(); s_l0.slove(); for(i = 0;i < (int)meshmodel->numvertices;i++){ for(j = 0; j < 3;j++) model[3 * i + j] = v[3 * i + j]; } delInfo(); delVerThreeSeparateRelation(); }
void PMainWindow::slotConfig() { /* * have a tab with the possible views * a tab for globals image cache size.. scaled loading * and one tab for the KeyConfigs */ QDialog dlg(this, 0, true); dlg.setCaption( tr("Opie Eye - Config" ) ); QHBoxLayout *lay = new QHBoxLayout(&dlg); Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); lay->addWidget( wid ); BaseSetup*bSetup = new BaseSetup(m_cfg,wid); wid->addTab(bSetup,"SettingsIcon","Basics setup"); ViewMap *vM = viewMap(); ViewMap::Iterator _it = vM->begin(); QMap<PDirView*, QWidget*> lst; for( ; _it != vM->end(); ++_it ) { PDirView *view = (_it.data())(*m_cfg); PInterfaceInfo *inf = view->interfaceInfo(); QWidget *_wid = inf->configWidget( *m_cfg ); if (!_wid) continue; _wid->reparent(wid, QPoint() ); lst.insert( view, _wid ); wid->addTab( _wid, "fileopen", inf->name() ); } /* * Add the KeyConfigWidget */ Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); QWidget*w = m_stack->visibleWidget(); bool reminfo = false; if ( !m_info ) { reminfo = true; initInfo(); m_info->hide(); } keyWid->insert( tr("Imageinfo Keyboard Actions"), m_info->manager() ); bool remdisp = false; if ( !m_disp ) { remdisp = true; initDisp(); m_disp->hide(); } keyWid->insert( tr("Imageview Keyboard Actions"), m_disp->manager() ); keyWid->load(); wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") ); wid->setCurrentTab(0); bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); /* * clean up *apply changes */ QMap<PDirView*, QWidget*>::Iterator it; for ( it = lst.begin(); it != lst.end(); ++it ) { if ( act ) it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); delete it.key(); } if ( act ) { keyWid->save(); m_disp->manager()->save(); m_info->manager()->save(); m_view->manager()->save(); bSetup->save_values(); m_view->resetView(); readConfig(); } delete keyWid; m_stack->raiseWidget(w); if (remdisp) { m_disp->hide(); } if (reminfo) { m_info->hide(); } if (m_disp) { m_disp->setIntensity(m_Intensity,true); } }
bool HIDDevice::openDevice() { // Have to iterate through devices again to generate paths. CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager->HIDManager); CFIndex deviceCount = CFSetGetCount(deviceSet); // Allocate a block of memory and read the set into it. IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount); CFSetGetValues(deviceSet, (const void **) devices); // Iterate over devices. IOHIDDeviceRef device = NULL; for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { IOHIDDeviceRef tmpDevice = devices[deviceIndex]; if (!tmpDevice) { continue; } String path; if (!HIDManager->getPath(tmpDevice, &path)) { continue; } if (path == DevDesc.Path) { device = tmpDevice; break; } } OVR_FREE(devices); if (!device) { CFRelease(deviceSet); return false; } // Attempt to open device. if (IOHIDDeviceOpen(device, kIOHIDOptionsTypeSeizeDevice) != kIOReturnSuccess) { CFRelease(deviceSet); return false; } // Retain the device before we release the set. CFRetain(device); CFRelease(deviceSet); Device = device; if (!initInfo()) { IOHIDDeviceClose(Device, kIOHIDOptionsTypeSeizeDevice); CFRelease(Device); Device = NULL; return false; } // Setup the Run Loop and callbacks. IOHIDDeviceScheduleWithRunLoop(Device, HIDManager->getRunLoop(), kCFRunLoopDefaultMode); IOHIDDeviceRegisterInputReportCallback(Device, ReadBuffer, ReadBufferSize, staticHIDReportCallback, this); IOHIDDeviceRegisterRemovalCallback(Device, staticDeviceRemovedCallback, this); return true; }
GLMmodel* L0ByEdge::doL0(double parpha, double pbeta, double plambda, int pmaxtimes) { int cc = 1, i, j, k; double tsum[3], sum; //得到边,求info getEdge(); if(pmaxtimes >= 0){ arpha = parpha; beta = pbeta; lambda = plambda; maxtimes = pmaxtimes; }else{ autoGetParameter(); } initInfo(); delEdge(); p = new double*[3]; v = new double*[3]; if(NULL == p || NULL == v){ printf("Error in L0ByEdge::doL0----- p , v\n"); return NULL; } for(i = 0;i < 3;i++){ p[i] = new double[(int)meshmodel->numvertices + infocnt]; v[i] = new double[(int)meshmodel->numvertices]; if(NULL == p[i] || NULL == v[i]){ printf("Error in L0ByEdge::doL0----- p[%d] , v[%d]\n",i,i); return NULL; } } for(i = 0; i < 3;i++){ for(j = 0;j < (int)meshmodel->numvertices;j++){ p[i][j] = model[3 * j + i]; v[i][j] = model[3 * j + i]; } } for(i = (int)meshmodel->numvertices;i < (int)meshmodel->numvertices + arinfocnt;i++){ for(j = 0;j < 3;j++){ p[j][i] = 0; } } //得到排序后二环领域,包括自身点 initVerSpreadNeighborVer(); //稀疏求解初始化 SubSolving s_l0(verSpreadNeighborVer, info, infocnt, arinfocnt, (int)meshmodel->numvertices); s_l0.init(); while(cc <= maxtimes){ updateInfo(); for(i = arinfocnt;i < infocnt;i++){ sum = 0; for(j = 0;j < 3;j++) tsum[j] = 0; for(j = 0;j < 4;j++) { for(k = 0;k < 3;k++){ tsum[k] += info[i][j].w * model[info[i][j].data * 3 + k]; } } for(j = 0;j < 3;j++){ sum += tsum[j] * tsum[j]; } if(sum <= lambda / beta){ for(j = 0;j < 3;j++) p[j][i + (int)meshmodel->numvertices] = 0.0; } else{ for(j = 0;j < 3;j++) p[j][i + (int)meshmodel->numvertices] = beta * tsum[j]; } } //传入beta,arpha s_l0.getParameter(p[0], v[0], info, beta, arpha); s_l0.update(); for(i = 0;i < 3;i++){ //传入p,v s_l0.getParameter(p[i], v[i], info, beta, arpha); s_l0.slove(); for(j = 0;j < (int)meshmodel->numvertices;j++){ model[3 * j + i] = v[i][j]; } } printf("%d\t time finished\n",cc); cc++; beta = beta * sqrt(2); arpha = arpha / 2; } //删除info,和关系链表 delInfo(); delVerSpreadNeighborVer(); for(i = 0;i < (int)meshmodel->numvertices;i++){ for(j = 0;j < 3;j++){ meshmodel->vertices[3 * (i + 1) + j] = model[3 * i + j]; } } return meshmodel; }
void RecoveryByVerNormalL0::slove() { int i, j; int maxtimes = 10; double beta = 0.07; double arpha = 2; double lambda = 0.003; initRelation(); initInfo(); p = new double[3 * (int)meshmodel->numvertices + infocnt]; v = new double[3 * (int)meshmodel->numvertices]; for(i = 0;i < 3 * (int)meshmodel->numvertices;i++) { p[i] = meshmodel->vertices[i + 3]; } for(i = 0; i < arinfocnt;i++){ p[i + 3 * (int)meshmodel->numvertices] = 0.0; } for(i = 0;i < 3 * (int)meshmodel->numvertices;i++) { v[i] = meshmodel->vertices[i + 3]; } SubSolving s_l0(relation, info, infocnt, arinfocnt , 3 * (int)meshmodel->numvertices); s_l0.init(); int cc = 1; while(cc <= maxtimes) { for(i = arinfocnt;i < infocnt;i++) { double sum = 0; for(j = 0;j < 6;j++) { sum += info[i][j].w * v[info[i][j].data]; } if(sum * sum <= lambda / beta) { p[i + (int)meshmodel->numvertices * 3] = 0.0; } else { p[i + (int)meshmodel->numvertices * 3] = sum * beta; } } s_l0.getParameter(p, v,info, beta, arpha); s_l0.update(); s_l0.getParameter(p, v,info, beta, arpha); s_l0.slove(); printf("\trecoveryByL0\t%d\ttime\tfinished\n",cc); // arpha /= 2; beta = sqrt(2) * beta; cc++; } printf("\n\n"); for(i = 0;i < 3 * (int)meshmodel->numvertices;i++) { meshmodel->vertices[i + 3] = v[i]; } }
void UDPSocket::setPeer(string host, string service) { initInfo(host,service,ANY_F,UDP_SOCK); }
int main(int argc, const char *argv[]) { poptContext optCon; /* context for parsing command-line options */ int rc, version = 0, debugMask = 0, pipeFD[2] = {-1, -1}, magic = FORKMAGIC; char *logdest = NULL, *configfile = "/etc/parastation.conf"; FILE *logfile = NULL; struct poptOption optionsTable[] = { { "debug", 'd', POPT_ARG_INT, &debugMask, 0, "enable debugging with mask <mask>", "mask"}, { "configfile", 'f', POPT_ARG_STRING, &configfile, 0, "use <file> as config-file (default is /etc/parastation.conf)", "file"}, { "logfile", 'l', POPT_ARG_STRING, &logdest, 0, "use <file> for logging (default is syslog(3))." " <file> may be 'stderr' or 'stdout'", "file"}, { "version", 'v', POPT_ARG_NONE, &version, 0, "output version information and exit", NULL}, POPT_AUTOHELP { NULL, '\0', 0, NULL, 0, NULL, NULL} }; optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); rc = poptGetNextOpt(optCon); /* Store arguments for later modification in forwarders, etc. */ PSID_argc = argc; PSID_argv = argv; if (version) { printVersion(); return 0; } if (logdest) { if (strcasecmp(logdest, "stderr")==0) { logfile = stderr; } else if (strcasecmp(logdest, "stdout")==0) { logfile = stdout; } else { logfile = fopen(logdest, "a+"); if (!logfile) { char *errstr = strerror(errno); fprintf(stderr, "Cannot open logfile '%s': %s\n", logdest, errstr ? errstr : "UNKNOWN"); exit(1); } } } if (!logfile) { openlog("psid", LOG_PID|LOG_CONS, LOG_DAEMON); } PSID_initLogs(logfile); printWelcome(); if (rc < -1) { /* an error occurred during option processing */ poptPrintUsage(optCon, stderr, 0); PSID_log(-1, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); if (!logfile) fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); return 1; } /* Save some space in order to modify the cmdline later on */ PSC_saveTitleSpace(PSID_argc, PSID_argv, 1); if (logfile!=stderr && logfile!=stdout) { /* Daemonize only if neither stdout nor stderr is used for logging */ if (pipe(pipeFD) < 0) { PSID_exit(errno, "unable to create pipe"); } /* Start as daemon */ switch (fork()) { case -1: PSID_exit(errno, "unable to fork server process"); break; case 0: /* I'm the child (and running further) */ close (pipeFD[0]); break; default: /* I'm the parent and exiting */ close (pipeFD[1]); /* Wait for child's magic data */ rc = read(pipeFD[0], &magic, sizeof(magic)); if (rc != sizeof(magic) || magic != (FORKMAGIC)) return -1; return 0; } } #define _PATH_TTY "/dev/tty" /* First disconnect from the old controlling tty. */ { int fd = open(_PATH_TTY, O_RDWR | O_NOCTTY); if (fd >= 0) { if (ioctl(fd, TIOCNOTTY, NULL)) { PSID_warn(-1, errno, "%s: ioctl(TIOCNOTTY)", __func__); } close(fd); } } /* * Disable stdin,stdout,stderr and install dummy replacement * Take care if stdout/stderr is used for logging */ { int dummy_fd; dummy_fd=open("/dev/null", O_WRONLY , 0); dup2(dummy_fd, STDIN_FILENO); if (logfile!=stdout) dup2(dummy_fd, STDOUT_FILENO); if (logfile!=stderr) dup2(dummy_fd, STDERR_FILENO); close(dummy_fd); } /* Forget about inherited window sizes */ unsetenv("LINES"); unsetenv("COLUMNS"); if (debugMask) { PSID_setDebugMask(debugMask); PSC_setDebugMask(debugMask); PSID_log(-1, "Debugging mode (mask 0x%x) enabled\n", debugMask); } /* Init the Selector facility as soon as possible */ if (!Selector_isInitialized()) Selector_init(logfile); PSID_registerLoopAct(Selector_gc); /* Initialize timer facility explicitely to ensure correct logging */ if (!Timer_isInitialized()) Timer_init(logfile); /* * Create the Local Service Port as early as possible. Actual * handling is enabled later. This gives psiadmin the chance to * connect. Additionally, this will guarantee exclusiveness */ PSID_createMasterSock(PSmasterSocketName); PSID_checkMaxPID(); /* read the config file */ PSID_readConfigFile(logfile, configfile); /* Now we can rely on the config structure */ { in_addr_t addr; PSID_log(-1, "My ID is %d\n", PSC_getMyID()); addr = PSIDnodes_getAddr(PSC_getMyID()); PSID_log(-1, "My IP is %s\n", inet_ntoa(*(struct in_addr *) &addr)); } if (!logfile && PSID_config->logDest!=LOG_DAEMON) { PSID_log(-1, "Changing logging dest from LOG_DAEMON to %s\n", PSID_config->logDest==LOG_KERN ? "LOG_KERN": PSID_config->logDest==LOG_LOCAL0 ? "LOG_LOCAL0" : PSID_config->logDest==LOG_LOCAL1 ? "LOG_LOCAL1" : PSID_config->logDest==LOG_LOCAL2 ? "LOG_LOCAL2" : PSID_config->logDest==LOG_LOCAL3 ? "LOG_LOCAL3" : PSID_config->logDest==LOG_LOCAL4 ? "LOG_LOCAL4" : PSID_config->logDest==LOG_LOCAL5 ? "LOG_LOCAL5" : PSID_config->logDest==LOG_LOCAL6 ? "LOG_LOCAL6" : PSID_config->logDest==LOG_LOCAL7 ? "LOG_LOCAL7" : "UNKNOWN"); closelog(); openlog("psid", LOG_PID|LOG_CONS, PSID_config->logDest); printWelcome(); } /* call startupScript, if any */ if (PSID_config->startupScript && *PSID_config->startupScript) { int ret = PSID_execScript(PSID_config->startupScript, NULL, NULL, NULL); if (ret > 1) { PSID_log(-1, "startup script '%s' failed. Exiting...\n", PSID_config->startupScript); PSID_finalizeLogs(); exit(1); } } /* Setup handling of signals */ initSigHandlers(); if (PSID_config->coreDir) { if (chdir(PSID_config->coreDir) < 0) { PSID_warn(-1, errno, "Unable to chdir() to coreDirectory '%s'", PSID_config->coreDir); } } PSIDnodes_setProtoV(PSC_getMyID(), PSProtocolVersion); PSIDnodes_setDmnProtoV(PSC_getMyID(), PSDaemonProtocolVersion); PSIDnodes_setHWStatus(PSC_getMyID(), 0); PSIDnodes_setKillDelay(PSC_getMyID(), PSID_config->killDelay); PSIDnodes_setAcctPollI(PSC_getMyID(), PSID_config->acctPollInterval); /* Bring node up with correct numbers of CPUs */ declareNodeAlive(PSC_getMyID(), PSID_getPhysCPUs(), PSID_getVirtCPUs()); /* Initialize timeouts, etc. */ PSID_initStarttime(); /* initialize various modules */ PSIDcomm_init(); /* This has to be first since it gives msgHandler hash */ PSIDclient_init(); initState(); initOptions(); initStatus(); initSignal(); PSIDspawn_init(); initPartition(); initHW(); initAccount(); initInfo(); initEnvironment(); /* Plugins shall be last since they use most of the ones before */ initPlugins(); /* Now we start all the hardware -- this might include the accounter */ PSID_log(PSID_LOG_HW, "%s: starting up the hardware\n", __func__); PSID_startAllHW(); /* * Prepare hostlist to initialize RDP and MCast */ { in_addr_t *hostlist; int i; hostlist = malloc(PSC_getNrOfNodes() * sizeof(unsigned int)); if (!hostlist) { PSID_exit(errno, "Failed to get memory for hostlist"); } for (i=0; i<PSC_getNrOfNodes(); i++) { hostlist[i] = PSIDnodes_getAddr(i); } if (PSID_config->useMCast) { /* Initialize MCast */ int MCastSock = initMCast(PSC_getNrOfNodes(), PSID_config->MCastGroup, PSID_config->MCastPort, logfile, hostlist, PSC_getMyID(), MCastCallBack); if (MCastSock<0) { PSID_exit(errno, "Error while trying initMCast"); } setDeadLimitMCast(PSID_config->deadInterval); PSID_log(-1, "MCast and "); } else { setStatusTimeout(PSID_config->statusTimeout); setMaxStatBCast(PSID_config->statusBroadcasts); setDeadLimit(PSID_config->deadLimit); setTmOutRDP(PSID_config->RDPTimeout); } /* Initialize RDP */ RDPSocket = RDP_init(PSC_getNrOfNodes(), PSIDnodes_getAddr(PSC_getMyID()), PSID_config->RDPPort, logfile, hostlist, PSIDRDP_handleMsg, RDPCallBack); if (RDPSocket<0) { PSID_exit(errno, "Error while trying initRDP"); } PSID_log(-1, "RDP (%d) initialized.\n", RDPSocket); free(hostlist); } /* Now start to listen for clients */ PSID_enableMasterSock(); /* Once RDP and the master socket are ready parents might be released */ if (pipeFD[1] > -1) { if (write(pipeFD[1], &magic, sizeof(magic)) <= 0) { /* We don't care */ } close(pipeFD[1]); } PSID_log(-1, "SelectTime=%d sec DeadInterval=%d\n", PSID_config->selectTime, PSID_config->deadInterval); /* Trigger status stuff, if necessary */ if (PSID_config->useMCast) { declareMaster(PSC_getMyID()); } else { int id = 0; while (id < PSC_getMyID() && (send_DAEMONCONNECT(id) < 0 && errno == EHOSTUNREACH)) { id++; } if (id == PSC_getMyID()) declareMaster(id); } /* * Main loop */ while (1) { int res = Swait(PSID_config->selectTime * 1000); if (res < 0) PSID_warn(-1, errno, "Error while Swait()"); /* Handle actions registered to main-loop */ PSID_handleLoopActions(); } }