/* when a PMC daemon is started, it first checks if there's already a daemon running on the network with the same nodekey, if yes, the newly started daemon automaticly runs in backup mode until demanded to switch to primary mode. */ bool setup_running_state() { __uint items; NODE_KEY nodeKey; char buffer[8192]; string dirname; *buffer = 0; /* running-state check must be done in backup mode. */ set_power_state(PWR_BACKUP); host_to_node(&g_ThisNode->key, &nodeKey); utils_trace("Finding primary site....\n"); items = discover_configfiles(&nodeKey, buffer, sizeof(buffer), 2000); if(!items){ utils_trace("No primary site found, starting as primary.\n"); set_power_state(PWR_RUNNING); }else{ if(!g_bAllowBackup){ utils_error( "Primary site unexpected, " "use '-2' command line option to force start as backup.\n" ); return __false; } utils_trace("Primary site found, server will be started in backup mode.\n"); #if 0 __uint i, filesize; char *item, *filebuf; FILE *fp; utils_trace("Primary site found, downloading configurations....\n"); item = buffer; dirname = get_working_dir(); for(i=0; i<items && *item; i++){ utils_trace("Downloading file (%d of %d) %s....\n", i+1, items, item); if(!download_file(&nodeKey, item, &filebuf, &filesize)){ utils_error("Unable to download '%s'\n", item); return false; } fp = fopen((dirname + "/" + item).data(), "wb"); if(!fp){ utils_error("Unable to write to '%s'\n", item); proxy_release_data(filebuf); return false; } fwrite(filebuf, 1, filesize, fp); fclose(fp); proxy_release_data(filebuf); item += strlen(item) + 1; rtk_sleep(100); } #endif } return true; }
void blklib_load_devices() { string f; char devices[1024]; char * dName; devlib_ent_t * d; char str[1024]; f = string(get_working_dir()) + "config/f8-devices.inf"; GetPrivateProfileSectionNames(devices, sizeof(devices), f.c_str()); dName=devices; d = device_lib; while(*dName){ if(stricmp(dName, "OEM")){ d->name = (char*)alloc_buffer_v(dName, strlen(dName) + 1, 0); GetPrivateProfileString(dName, "description", "", str, sizeof(str), f.c_str()); d->description = (char*)alloc_buffer_v(str, strlen(str) + 1, 0); GetPrivateProfileString(dName, "id", "", str, sizeof(str), f.c_str()); f8_uuid_from_string(&d->dev.clsid, str); GetPrivateProfileString(dName, "n_di", "0", str, sizeof(str), f.c_str()); d->dev.n_di = atoi(str); GetPrivateProfileString(dName, "n_do", "0", str, sizeof(str), f.c_str()); d->dev.n_do = atoi(str); GetPrivateProfileString(dName, "n_ai", "0", str, sizeof(str), f.c_str()); d->dev.n_ai = atoi(str); GetPrivateProfileString(dName, "n_ao", "0", str, sizeof(str), f.c_str()); d->dev.n_ao = atoi(str); GetPrivateProfileString(dName, "ai_width", "0", str, sizeof(str), f.c_str()); d->dev.ai_width = atoi(str); GetPrivateProfileString(dName, "ao_width", "0", str, sizeof(str), f.c_str()); d->dev.ao_width = atoi(str); if(d->dev.n_di != 0|| d->dev.n_ai != 0){ d->dev.features |= IO_DEVICE_INPUT; } if(d->dev.n_do != 0|| d->dev.n_ao != 0){ d->dev.features |= IO_DEVICE_OUTPUT; } d++; } dName += strlen(dName) + 1; } return; }
stage_t::~stage_t() { // this only happens in case the stage dir was not specified at cmd line if ( m_remove_dir_on_exit && (get_platform()->get_temp_dir() != "") && ( dir_exists(get_platform()->get_temp_dir()) ) ){ std::string old_wkg_dir = get_working_dir(); change_wkg_dir_to(get_platform()->get_temp_dir()); system ("rm -f *.zip *.bz2"); // for testing // std::cout << "Pres key for del\n"; // char ch; // std::cin.get(ch); change_wkg_dir_to(old_wkg_dir); std::string cmd = "rmdir " + get_platform()->get_temp_dir(); system (cmd.c_str()); } }
/* loads the INF file and performs checks on it */ static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec, LPCWSTR working_dir, DWORD flags, ADVInfo *info) { DWORD len; HRESULT hr; LPCWSTR ptr, path; static const WCHAR backslash[] = {'\\',0}; static const WCHAR default_install[] = { 'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0 }; if (!(ptr = strrchrW(inf_filename, '\\'))) ptr = inf_filename; len = lstrlenW(ptr); info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); if (!info->inf_filename) return E_OUTOFMEMORY; lstrcpyW(info->inf_filename, ptr); /* FIXME: determine the proper platform to install (NTx86, etc) */ if (!install_sec || !*install_sec) { len = sizeof(default_install) - 1; ptr = default_install; } else { len = lstrlenW(install_sec); ptr = install_sec; } info->install_sec = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); if (!info->install_sec) return E_OUTOFMEMORY; lstrcpyW(info->install_sec, ptr); hr = get_working_dir(info, inf_filename, working_dir); if (FAILED(hr)) return hr; len = lstrlenW(info->working_dir) + lstrlenW(info->inf_filename) + 2; info->inf_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!info->inf_path) return E_OUTOFMEMORY; lstrcpyW(info->inf_path, info->working_dir); lstrcatW(info->inf_path, backslash); lstrcatW(info->inf_path, info->inf_filename); /* RunSetupCommand opens unmodifed filename parameter */ if (flags & RSC_FLAG_INF) path = inf_filename; else path = info->inf_path; info->hinf = SetupOpenInfFileW(path, NULL, INF_STYLE_WIN4, NULL); if (info->hinf == INVALID_HANDLE_VALUE) return ADV_HRESULT(GetLastError()); set_ldids(info->hinf, info->install_sec, info->working_dir); /* FIXME: check that the INF is advanced */ info->flags = flags; info->need_reboot = FALSE; return S_OK; }
void CInMemoryBuffer::startRecord(hislog_key_t now) { SYSTEMTIME st; FILETIME ft; char buf[_MAX_PATH]; hislog_stream_list::iterator it, next; CHislogStream * str; //utils_debug("wlock 1\n"); WriteLock(); if(m_state != bs_ready){ //utils_debug("release 1\n"); Release(); throw(m_state); } ft = getTimeByKey(now); FileTimeToSystemTime(&ft, &st); _snprintf( buf, sizeof(buf), "%svar/hisd/%04d-%02d-%02d", get_working_dir(), st.wYear, st.wMonth, st.wDay ); m_pathName = buf; _snprintf( buf, sizeof(buf), "%svar/hisd/%04d-%02d-%02d/%02d-%02d-%02d.hsd", get_working_dir(), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond ); m_fileName = buf; #if 1 { DEBUG_PRINTF(( "Recording started on %s\n", timeAsString(now).c_str() )); } #endif m_startTime = now; m_endTime = now; // handle postponed deletion it = m_streams.begin(); while(it != m_streams.end()){ next = it; next++; str = it->second; if(str->m_deletePending){ delete str; m_streams.erase(it); }else{ str->clear(); } it = next; } m_state = bs_logging; //utils_debug("release 2\n"); Release(); }
void CMainFrame::OnOptQuery() { CDlgQuery dlg; COleDateTime dt; COleDateTime tm; PMCSYSTIME tmSys; PMCTIME stm, etm; if(m_qIniTime){ dlg.m_date_sta = m_dtSta; dlg.m_time_sta = m_dtSta; dlg.m_date_end = m_dtEnd; dlg.m_time_end = m_dtEnd; dlg.m_cur_sel = m_cur_sel; dlg.m_filter = m_filter; } if(dlg.DoModal()==IDOK){ m_qIniTime=true; dt = dlg.m_date_sta; tm = dlg.m_time_sta; tmSys.year = dt.GetYear(); tmSys.month = dt.GetMonth(); tmSys.day = dt.GetDay(); tmSys.hour = tm.GetHour(); tmSys.minute = tm.GetMinute(); tmSys.second = tm.GetSecond(); tmSys.milliSeconds = 0; systm2tm(&tmSys, &stm); m_dtSta.SetDateTime(tmSys.year, tmSys.month, tmSys.day, tmSys.hour, tmSys.minute, tmSys.second); dt=dlg.m_date_end; tm=dlg.m_time_end; tmSys.year=dt.GetYear(); tmSys.month=dt.GetMonth(); tmSys.day=dt.GetDay(); tmSys.hour=tm.GetHour(); tmSys.minute=tm.GetMinute(); tmSys.second=tm.GetSecond(); tmSys.milliSeconds=0; systm2tm(&tmSys, &etm); m_dtEnd.SetDateTime(tmSys.year, tmSys.month, tmSys.day, tmSys.hour, tmSys.minute, tmSys.second); m_cur_sel = dlg.m_cur_sel; m_filter = dlg.m_filter; m_filter.TrimLeft(); m_filter.TrimRight(); int count=0; switch(m_cur_sel){ case 0: count = alarms->getRecord_r(stm, etm, MAX_GET_RECORD, evtsList, m_filter); break; case 1: count = operates->getRecord_r(stm, etm, MAX_GET_RECORD, evtsList, m_filter); break; // case 2: // count = soes->getRecord_r(stm, etm, MAX_GET_RECORD, evtsList, m_filter); // break; case 2: CString userlogfile =CString(get_working_dir()) + "userlogin.csv"; FILE *puserlog=fopen((LPCTSTR)userlogfile,"rb"); if(puserlog==NULL) return; CPtrArray IFO; char line[1024]; int linecount=0; //行数计数器 while(fgets(line,1024,puserlog)) { linecount++; } fseek(puserlog,0,SEEK_SET); int num =linecount-MAX_GET_RECORD; int num1=0; while(fgets(line,1024,puserlog)) { num1++; if (num1<=num) continue; strcpy(evtsList[count].data,line); memset(line,0,sizeof(line)); count++; } fclose(puserlog); break; } GetLastError(); int i; for(i = 0; i < MAX_GET_RECORD; i++){ evtsList[i].valid = false; } for(i = 0; i < count; i++){ evtsList[i].valid = true; } m_wndView.RedrawWindow(); } }