BOOL LogMng::WriteRecvMsg(MsgBuf *msg, int opt, THosts *hosts, ShareInfo *shareInfo, const std::vector<HostSub> *recvList, int64 *msg_id) { if (msg->command & IPMSG_NOLOGOPT) return FALSE; WriteStart(); logMsg->flags |= DB_FLAG_FROM; SetLogMsgUser(cfg, &msg->hostSub, hosts, logMsg); char buf[MAX_PATH_U8]; char *p = buf; p += strcpyz(p, LOGMSG_FROM); p += MakeListString(cfg, &msg->hostSub, hosts, p, TRUE); p += strcpyz(p, "\r\n"); Write(buf); if (recvList && recvList->size() >= 1) { for (auto &h: *recvList) { p = buf; p += strcpyz(p, LOGMSG_CC); p += MakeListString(cfg, (HostSub *)&h, hosts, p, TRUE); p += strcpyz(p, "\r\n"); Write(buf); SetLogMsgUser(cfg, (HostSub *)&h, hosts, logMsg); } } return WriteMsg(msg->packetNo, msg->msgBuf.s(), msg->command, opt, msg->timestamp, shareInfo, msg_id); }
static bool AssignCodes( int num, arccmd *cmd ) /*********************************************/ // this generates the shannon-fano code values in reverse order in the high // bits of the code array. returns TRUE if codes successfully assigned. { unsigned codeinc; unsigned lastlen; unsigned codeval; int index; SortLengths( num ); if( len[ indicies[ num - 1 ] ] > MAX_CODE_BITS ) { if( !(cmd->flags & BE_QUIET) ) { WriteMsg( "Can't do shannon-fano compression: code length too long\n" ); } return( FALSE ); } memset( code, 0, NUM_CHARS * sizeof( unsigned ) ); codeval = 0; codeinc = 0; lastlen = 0; for( index = num - 1; index >= 0; index -- ) { codeval += codeinc; if( len[ indicies[ index ] ] != lastlen ) { lastlen = len[ indicies[ index ] ]; codeinc = 1 << (MAX_CODE_BITS - lastlen); } code[ indicies[ index ] ] = codeval; } return( TRUE ); }
bool mainSpectralAngleMatrix(string filepath2, string filepath3, char* logfile, vector<int> bandlist, string interkind, vector<double>& m_qRes) { m_qRes.clear(); int32_t res = SpectralAngleMatrix(const_cast<char*>(filepath2.c_str()), const_cast<char*>(filepath3.c_str()), logfile, bandlist, interkind, m_qRes); if(res != 1) { WriteMsg(logfile,-1,"Algorithm mainSpectralAngleMatrix executing error!"); return false; } return true; }
bool mainRadiationUniform(string& filepath , char* logfilepath, vector<double>& m_qRes) { m_qRes.clear(); int32_t res = RadiationUniform(const_cast<char*>(filepath.c_str()),logfilepath, m_qRes); if(res != 1) { WriteMsg(logfilepath,-1,"Algorithm executing error!"); return false; } return true; }
bool mainClarity(string& filepath , char* logfilepath, vector<double>& m_qRes) { m_qRes.clear(); int32_t res = Clarity(const_cast<char*>(filepath.c_str()),logfilepath, m_qRes); if(res != 1) { printf("Algorithm executing error!\n"); WriteMsg(logfilepath,-1,"Algorithm executing error!"); return false; } return true; }
void task_deregister_send(_task* parent, place_t remote_place) { if(_placetodispatcher(remote_place) == _placetodispatcher(_here())) { task_deregister(parent); } else { volatile _task* temp = parent; void * buf = (void*) &temp; uint64_t bufsize = sizeof(_task*); WriteMsg(remote_place, ASYNC_ACK, (uint64_t)bufsize, (void*)buf); } }
BOOL LogMng::WriteRecvMsg(MsgBuf *msg, THosts *hosts, ShareInfo *shareInfo) { if (msg->command & IPMSG_NOLOGOPT) return FALSE; WriteStart(); char buf[MAX_PATH] = " From: "; MakeListString(cfg, &msg->hostSub, hosts, buf + strlen(buf)); strcat(buf, "\r\n"); Write(buf); return WriteMsg(msg->msgBuf, msg->command, shareInfo); }
//通过命名管道连接引擎 bool CEngine::LinkEngineWithNamed() { status = 0; CreatePipeAndConnectClient();//创建命名管道并等待客户端连接 char Filter[]="(exe files)|*.exe|(all files)|*.*||";//文件滤镜 CFileDialog FileName(true,NULL,NULL,Filter,NULL,gameSet.EngineInitDir); if(FileName.DoModal()==IDOK) { path=FileName.GetFilePath(); LPCTSTR folder=FileName.GetFolderPath(path); char EngineDir[MAX_PATH]={0}; strcpy(EngineDir,folder); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si,sizeof(si)); si.cb=sizeof(si); si.dwFlags=STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES; si.wShowWindow=SW_SHOW; si.hStdInput=GetStdHandle(STD_INPUT_HANDLE); si.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE); si.hStdError=GetStdHandle(STD_ERROR_HANDLE); if(!CreateProcess(path,"",NULL,NULL,true,0,NULL,EngineDir,&si,&pi))//打开引擎进程 { ErrorBox("CreateProcess failed"); status = -1; return false; } SetCurrentDirectory(gameSet.CurDir);//恢复当前主应用程序的进程 CreateEngineInfoBoard(); } else { status = -1; return false; } WaitForSingleObject(ol.hEvent,INFINITE);//等待客户端成功建立连接 WriteMsg("name?\n");//询问引擎名称 char rMsg[256]; memset(rMsg,0,sizeof(rMsg)); GetCommand("name",rMsg); strcpy(name,"Name: "); strcat(name,rMsg+strlen("name "));//设置引擎的名称 return true; }
int32_t task_dispatch(_async child, place_t remote_place) { _task* self = (_task*)_thread_getspecific(); task_register(self); uint64_t bufsize; if(_placetodispatcher(remote_place) == _placetodispatcher(_here())) { bufsize = child.size; bufsize += sizeof(method_t); bufsize += sizeof(_task*); void* buf = (void*) malloc(bufsize); _task** parent = (_task**)buf; *parent = self; method_t* method = (method_t*)(buf+sizeof(_task*)); *method = child.method; void* params = (void*) (buf + sizeof(method_t) + sizeof(_task*)); memcpy(params, child.params, child.size); struct Msg* msg = (struct Msg*) malloc(sizeof(struct Msg)); // (((_task*)_thread_getspecific()) -> total_memory) += sizeof(struct Msg); msg -> placeTo = remote_place; msg -> placeFrom = _here(); msg -> msgType = ASYNC; msg -> size = bufsize; msg -> tb.addr = buf; msg -> tb.sz = bufsize; _create_async_local(msg); } else { void* buf = _pack_ASYNC(&bufsize, sizeof(method_t) + sizeof(_task*), child); _task** parent = (_task**)buf; *parent = self; method_t* method = (method_t*)(buf+sizeof(_task*)); *method = child.method; int32_t success = WriteMsg(remote_place, ASYNC, (uint64_t)bufsize, (void*)buf); //may not be needed ///GC_FREE(buf); free(buf); if (success == EXIT_SUCCESS) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } } }
int RunTest(){ int place = 0; int BUF_SIZE = 80; char buf[BUF_SIZE]; /* Input buffer */ const int fd = 4; fputs ("Started Dispatcher waiting input\n", stderr); FILE *fp; fp = fopen("/Users/dupper/Desktop/dupTestCode/in.txt", "rt"); /* Make fd into FILE* for reading */ fputs("Found the file descriptor\n", stderr); if (fp == NULL) { fprintf(stderr,"BAD FILE DESCRIPTOR %d TO CONFIG\n", fd); return EXIT_FAILURE; } while(fgets(buf, 80, fp) != NULL) { fprintf(stderr, "READING FILE\n"); /* get a line, up to 80 chars from fr. done if NULL */ sscanf (buf, "%d", &place); fprintf(stderr,"%d:Convert place number from string to int\n", place); /* convert the string to a long int */ fprintf (stderr, "%d,%d\n", place,place); } fprintf(stderr,"%d:Read config file\n", place); fclose(fp); int resultWrite =-1; int resultRead =-1; if(place==1){ resultWrite =WriteMsg("Hello world\n", place); }else{ resultRead = ReadMsg(place); } if((resultRead == -1 && resultWrite== EXIT_SUCCESS) || (resultWrite == -1 && resultRead== EXIT_SUCCESS)){ fprintf(stderr,"%d:Success\n", place); return EXIT_SUCCESS; }else{ fprintf(stderr,"%d:Failure\n", place); return EXIT_FAILURE; } }
VOID __cdecl DebugLog( DBG_LEVEL level, PCHAR file, ULONG line, PCHAR func, PCHAR fmt,...) //ANY_LEVEL { DBG_LEVEL DbgLevel; PCHAR DbgLevelName; va_list args; PCHAR buff; int left,res,len; CHAR Msg[MSG_MAX_LEN]; DbgLevel = level & DbgLevelMax; if( DbgLevel < g_DebugLevel) return; buff = Msg; left = MSG_MAX_LEN-1; #define CASE_DBG_LEVEL(x,y) case x: DbgLevelName = y; goto write; switch(DbgLevel) { CASE_DBG_LEVEL(DbgLevelNone,"None"); CASE_DBG_LEVEL(DbgLevelTrace,"Trace"); CASE_DBG_LEVEL(DbgLevelDebug,"Debug"); CASE_DBG_LEVEL(DbgLevelInfo,"Info"); CASE_DBG_LEVEL(DbgLevelError,"Error"); CASE_DBG_LEVEL(DbgLevelCriticalTrace,"CritTrace"); CASE_DBG_LEVEL(DbgLevelCriticalDebug,"CritDebug"); CASE_DBG_LEVEL(DbgLevelCriticalInfo,"CritInfo"); CASE_DBG_LEVEL(DbgLevelCriticalError,"CritError"); CASE_DBG_LEVEL(DbgLevelBeforeBsod,"BSOD"); write: WriteMsg(&buff,&left,"[%s,",DbgLevelName); break; default: DbgLevelName = "Unknown"; WriteMsg(&buff,&left,"[%s(%i),",DbgLevelName,DbgLevel); break; } WriteMsg(&buff,&left,KIP_DRIVER_NAMEA ": "); WriteMsg(&buff,&left,"%s() ",func); if ( DbgLevel >= DbgLevelDebug && file ){ WriteMsg(&buff,&left,":%s:%i,",TruncatePath(file),line); } WriteMsg(&buff,&left,"t%X] ",PsGetCurrentThreadId()); va_start(args,fmt); WriteMsg2(&buff,&left,fmt,args); va_end(args); Msg[MSG_MAX_LEN-1] = 0; len = strlen(Msg); DbgPrint("%s",Msg); return; }
//Clarity-影像清晰度(点锐度算法) int32_t Clarity(char* filepath,char* logfilepath, vector<double>& result) { GDALDataset *poDataset = NULL; GDALAllRegister(); poDataset=(GDALDataset *)GDALOpen(filepath,GA_ReadOnly); if(poDataset == NULL) { printf("Image file open error!\n"); WriteMsg(logfilepath,-1,"Image file open error!"); return -1; } else { printf("Clarity algorithm is executing!\n"); WriteMsg(logfilepath,0,"Clarity algorithm is executing!"); } //开始解析图像数据集 int32_t n,i,j; int32_t bandnum,width,height; bandnum=poDataset->GetRasterCount(); width=poDataset->GetRasterXSize(); height=poDataset->GetRasterYSize(); GDALRasterBand *pband = NULL; uint16_t *banddata=(uint16_t *)CPLMalloc(sizeof(uint16_t)*width*height); for(n=0;n<bandnum;n++) { pband=poDataset->GetRasterBand(n+1); pband->RasterIO(GF_Read,0,0,width,height,banddata,width,height,GDT_UInt16,0,0); double clarity=0.0; int32_t blkcount=0; for(i=1;i<height-1;i++) { for(j=1;j<width-1;j++) { if(banddata[i*width+j]==0) continue; double colmean=0.0; colmean += fabs(1.0*banddata[(i-1)*width+(j-1)]-banddata[i*width+j])/sqrt(2.0); colmean += fabs(1.0*banddata[(i-1)*width+j]-banddata[i*width+j]); colmean += fabs(1.0*banddata[(i-1)*width+(j+1)]-banddata[i*width+j])/sqrt(2.0); colmean += fabs(1.0*banddata[i*width+(j-1)]-banddata[i*width+j]); colmean += fabs(1.0*banddata[i*width+(j+1)]-banddata[i*width+j]); colmean += fabs(1.0*banddata[(i+1)*width+(j-1)]-banddata[i*width+j])/sqrt(2.0); colmean += fabs(1.0*banddata[(i+1)*width+j]-banddata[i*width+j]); colmean += fabs(1.0*banddata[(i+1)*width+(j+1)]-banddata[i*width+j])/sqrt(2.0); colmean = colmean/8.0; clarity +=colmean; blkcount++; } } result.push_back(clarity/blkcount); GDALClose(pband); pband=NULL; //Writing the process and status of this Algorithm. int32_t temp = (int)(100.0*(n+1)/bandnum); temp = (temp>99) ? 99:temp; printf("Clarity algorithm is executing %d%%!\n",temp); WriteMsg(logfilepath,temp,"Clarity algorithm is executing!"); } CPLFree(banddata); banddata=NULL; GDALClose(poDataset); poDataset=NULL; return 1; }
int32_t RadiationUniform(char* filepath1, char* logfilepath, vector<double>& striperesult) { GDALDataset *poDataset; GDALAllRegister(); poDataset=(GDALDataset *)GDALOpen(filepath1,GA_ReadOnly); if( poDataset == NULL ) { cerr << "RadiationUniform filepath " << filepath1 << endl; WriteMsg(logfilepath,-1,"Image file open error!"); return -1; } else { WriteMsg(logfilepath,0,"Striperesidual algorithm is executing!"); } int32_t n,i,j; int32_t bandnum,width,height; bandnum=poDataset->GetRasterCount(); width=poDataset->GetRasterXSize(); height=poDataset->GetRasterYSize(); GDALRasterBand *pband; uint16_t *banddata=(uint16_t *)CPLMalloc(sizeof(uint16_t)*width*height); for(n=0;n<bandnum;n++) { pband=poDataset->GetRasterBand(n+1); pband->RasterIO(GF_Read,0,0,width,height,banddata,width,height,GDT_UInt16,0,0); double *colmeans=(double *)CPLMalloc(sizeof(double)*width); double imgmean=0.0; for(j=0;j<width;j++) { colmeans[j]=0.0; } for(i=0;i<height;i++) { for(j=0;j<width;j++) { colmeans[j]=colmeans[j]+banddata[i*width+j]/(double)height; } } for(j=0;j<width;j++) { imgmean = imgmean+colmeans[j]/(double)width; } double sum=0.0; for(j=1;j<width;j++) { sum = sum + (colmeans[j]-imgmean)*(colmeans[j]-imgmean)/width; } striperesult.push_back(100.0*(1-sqrt(sum)/imgmean)); CPLFree(colmeans); colmeans=NULL; GDALClose(pband); pband=NULL; //Writing the process and status of this Algorithm. int32_t temp = (int)(100.0*(n+1)/bandnum); temp = (temp>99) ? 99:temp; WriteMsg(logfilepath,temp,"Striperesidual algorithm is executing!"); } CPLFree(banddata); banddata=NULL; GDALClose(poDataset); poDataset=NULL; return 1; }
BOOL LogMng::WriteSendMsg(ULONG packetNo, LPCSTR msg, ULONG command, int opt, time_t t, ShareInfo *shareInfo, int64 *msg_id) { return WriteMsg(packetNo, msg, command, opt, t, shareInfo, msg_id); }
BOOL LogMng::WriteSendMsg(LPCSTR msg, ULONG command, ShareInfo *shareInfo) { return WriteMsg(msg, command, shareInfo); }
//卸载引擎 bool CEngine::UnloadEngine() { DWORD k; if(status == -1)//看是否已卸载 { MsgBox("Engine has unloaded!","Msg",1500); return true; } if (!GetExitCodeProcess(pde.hEProcess, &k))//获取退出码 { ErrorBox("Get exit code failed!"); } else { if(k!=STILL_ACTIVE)//异常退出 { MsgBox("Program has been ended for unknown reasons!","error",3000); if(linkType==UNNAMEDPIPE) {//关闭引擎的同时关闭显示窗口,释放依赖匿名管道 TerminateProcess(pde.hCProcess,0); CloseHandle(pde.console_write); CloseHandle(pde.platform_write); CloseHandle(pde.platform_read); } status = -1; return true; } } WriteMsg("quit\n");//发送退出命令 DWORD temp=WaitForSingleObject(pde.hEProcess, 1000); if (temp == WAIT_OBJECT_0) { if (linkType == UNNAMEDPIPE) {//关闭引擎的同时关闭显示窗口,释放依赖匿名管道 TerminateProcess(pde.hCProcess, 0); CloseHandle(pde.console_write); CloseHandle(pde.platform_write); CloseHandle(pde.platform_read); } MsgBox("UnLoadEngine succeed!", "Msg", 1500); } else if (temp == WAIT_TIMEOUT) { if (TerminateProcess(pde.hEProcess, 0))//卸载成功 { if (linkType == UNNAMEDPIPE) {//关闭引擎的同时关闭显示窗口,释放依赖匿名管道 TerminateProcess(pde.hCProcess, 0); CloseHandle(pde.console_write); CloseHandle(pde.platform_write); CloseHandle(pde.platform_read); } MsgBox("UnLoadEngine succeed!", "Msg", 1500); } else { ErrorBox("UnLoadEngine failed"); return false; } } status = -1; return true; }
int32_t SpectralAngleMatrix(char* filepath2,char* filepath3,char* logfilepath, vector<int> bandlist, string interkind, vector<double>& SpectralAngleMatrix) { GDALDataset *poDataset2,*poDataset3; GDALAllRegister(); poDataset2=(GDALDataset *)GDALOpen(filepath2,GA_ReadOnly); poDataset3=(GDALDataset *)GDALOpen(filepath3,GA_ReadOnly); if( (poDataset2 == NULL) || (poDataset3 == NULL) ) { WriteMsg(logfilepath,-1,"Image file open error!"); GDALClose(poDataset2); poDataset2=NULL; GDALClose(poDataset3); poDataset3=NULL; return -1; } else { WriteMsg(logfilepath,0,"SpectralAngleMatrix algorithm is executing!"); } int32_t n,i,j; int32_t width2,height2; int32_t bandnum3,width3,height3; width2=poDataset2->GetRasterXSize(); height2=poDataset2->GetRasterYSize(); bandnum3=poDataset3->GetRasterCount(); width3=poDataset3->GetRasterXSize(); height3=poDataset3->GetRasterYSize(); if(bandlist.size() != bandnum3) { GDALClose(poDataset2); poDataset2=NULL; GDALClose(poDataset3); poDataset3=NULL; WriteMsg(logfilepath, -1, "bandlist.size() != bandnum3 || width2 != width3 || height2 != height3"); return -1; } GDALRasterBand *pband; float *banddata2,*banddata3; float *tempdata1,*tempdata2,*tempdata3; banddata2=(float*)CPLMalloc(sizeof(float)*width2*height2); banddata3=(float*)CPLMalloc(sizeof(float)*width3*height3); tempdata1=(float *)CPLMalloc(sizeof(float)*width3*height3); tempdata2=(float *)CPLMalloc(sizeof(float)*width3*height3); tempdata3=(float *)CPLMalloc(sizeof(float)*width3*height3); float* new_data = (float*)malloc(sizeof(float)*width3*height3); if(new_data == NULL) { GDALClose(poDataset2); poDataset2=NULL; GDALClose(poDataset3); poDataset3=NULL; WriteMsg(logfilepath, -1, "new_data malloc error !"); return -1; } Tools obj; map<string, int> m_interalg; m_interalg["Nearest_1_0"]=1; m_interalg["Linear_1_0"]=2; m_interalg["CubicConv_1_0"]=3; for(n=0;n<bandnum3;n++) { pband=poDataset2->GetRasterBand(bandlist[n]); pband->RasterIO(GF_Read,0,0,width2,height2,banddata2,width2,height2,GDT_Float32,0,0); GDALClose(pband); pband=NULL; obj.Interpolation(banddata2,height2, width2, 1, new_data, height3, width3, m_interalg[interkind]); pband=poDataset3->GetRasterBand(n+1); pband->RasterIO(GF_Read,0,0,width3,height3,banddata3,width3,height3,GDT_Float32,0,0); GDALClose(pband); pband=NULL; int32_t tempnum2=0; int32_t tempnum3=0; for(i=0;i<height3;i++) { for(j=0;j<width3;j++) { if(n==0) { tempdata1[i*width3+j]=0.0; tempdata2[i*width3+j]=0.0; tempdata3[i*width3+j]=0.0; } tempnum2=new_data[i*width2+j]; tempnum3=banddata3[i*width3+j]; if(tempnum2>0 && tempnum3>0) { tempdata1[i*width3+j]=tempdata1[i*width3+j]+(1.0*tempnum2*tempnum3/bandnum3); tempdata2[i*width3+j]=tempdata2[i*width3+j]+(1.0*tempnum2*tempnum2/bandnum3); tempdata3[i*width3+j]=tempdata3[i*width3+j]+(1.0*tempnum3*tempnum3/bandnum3); } } } int32_t temp = (int)(100.0*(n+1)/bandnum3); temp = (temp>99) ? 99:temp; WriteMsg(logfilepath,temp,"SpectralAngleMatrix algorithm is executing!"); } free(new_data); CPLFree(banddata2); banddata2=NULL; CPLFree(banddata3); banddata3=NULL; int64_t count=0; long double sum=0.0; for(i=0;i<height3;i++) { for(j=0;j<width3;j++) { if(j==20) { int a=2; } if(tempdata2[i*width3+j]!=0 && tempdata3[i*width3+j]!=0) { double tempdbl1=((double)tempdata1[i*width3+j])/(sqrt(tempdata2[i*width3+j])*sqrt(tempdata3[i*width3+j])); if(tempdbl1>1.0) { tempdbl1=1.0; } else if(tempdbl1<-1.0) { tempdbl1=-1.0; } sum=sum+acos(tempdbl1); count++; } } } sum = sum/count; SpectralAngleMatrix.push_back(sum); CPLFree(tempdata1); tempdata1=NULL; CPLFree(tempdata2); tempdata2=NULL; CPLFree(tempdata3); tempdata3=NULL; GDALClose(poDataset2); poDataset2=NULL; GDALClose(poDataset3); poDataset3=NULL; return 1; }
int NS_main(int argc, NS_tchar **argv) { if (argc < 3) { fprintf(stderr, \ "\n" \ "Application Update Service Test Helper\n" \ "\n" \ "Usage: WORKINGDIR INFILE OUTFILE -s SECONDS [FILETOLOCK]\n" \ " or: WORKINGDIR LOGFILE [ARG2 ARG3...]\n" \ " or: signature-check filepath\n" \ " or: setup-symlink dir1 dir2 file symlink\n" \ " or: remove-symlink dir1 dir2 file symlink\n" \ " or: check-symlink symlink\n" \ "\n" \ " WORKINGDIR \tThe relative path to the working directory to use.\n" \ " INFILE \tThe relative path from the working directory for the file to\n" \ " \tread actions to perform such as finish.\n" \ " OUTFILE \tThe relative path from the working directory for the file to\n" \ " \twrite status information.\n" \ " SECONDS \tThe number of seconds to sleep.\n" \ " FILETOLOCK \tThe relative path from the working directory to an existing\n" \ " \tfile to open exlusively.\n" \ " \tOnly available on Windows platforms and silently ignored on\n" \ " \tother platforms.\n" \ " LOGFILE \tThe relative path from the working directory to log the\n" \ " \tcommand line arguments.\n" \ " ARG2 ARG3...\tArguments to write to the LOGFILE after the preceding command\n" \ " \tline arguments.\n" \ "\n" \ "Note: All paths must be relative.\n" \ "\n"); return 1; } if (!NS_tstrcmp(argv[1], NS_T("check-signature"))) { #ifdef XP_WIN if (ERROR_SUCCESS == VerifyCertificateTrustForFile(argv[2])) { return 0; } else { return 1; } #else // Not implemented on non-Windows platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("setup-symlink"))) { #ifdef XP_UNIX NS_tchar path[MAXPATHLEN]; NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); mkdir(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3]); mkdir(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3], argv[4]); FILE * file = NS_tfopen(path, NS_T("w")); if (file) { NS_tfputs(NS_T("test"), file); fclose(file); } symlink(path, argv[5]); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); if (argc > 6 && !NS_tstrcmp(argv[6], NS_T("change-perm"))) { chmod(path, 0644); } return 0; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("remove-symlink"))) { #ifdef XP_UNIX NS_tchar path[MAXPATHLEN]; NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); chmod(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3], argv[4]); unlink(path); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3]); rmdir(path); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); rmdir(path); return 0; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("check-symlink"))) { #ifdef XP_UNIX struct stat ss; lstat(argv[2], &ss); return S_ISLNK(ss.st_mode) ? 0 : 1; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("wait-for-service-stop"))) { #ifdef XP_WIN const int maxWaitSeconds = NS_ttoi(argv[3]); LPCWSTR serviceName = argv[2]; DWORD serviceState = WaitForServiceStop(serviceName, maxWaitSeconds); if (SERVICE_STOPPED == serviceState) { return 0; } else { return serviceState; } #else // Not implemented on non-Windows platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("wait-for-application-exit"))) { #ifdef XP_WIN const int maxWaitSeconds = NS_ttoi(argv[3]); LPCWSTR application = argv[2]; DWORD ret = WaitForProcessExit(application, maxWaitSeconds); if (ERROR_SUCCESS == ret) { return 0; } else if (WAIT_TIMEOUT == ret) { return 1; } else { return 2; } #else // Not implemented on non-Windows platforms return 1; #endif } int i = 0; if (NS_tchdir(argv[1]) != 0) { return 1; } // File in use test helper section if (!NS_tstrcmp(argv[4], NS_T("-s"))) { NS_tchar *cwd = NS_tgetcwd(nullptr, 0); NS_tchar inFilePath[MAXPATHLEN]; NS_tsnprintf(inFilePath, sizeof(inFilePath)/sizeof(inFilePath[0]), NS_T("%s/%s"), cwd, argv[2]); NS_tchar outFilePath[MAXPATHLEN]; NS_tsnprintf(outFilePath, sizeof(outFilePath)/sizeof(outFilePath[0]), NS_T("%s/%s"), cwd, argv[3]); int seconds = NS_ttoi(argv[5]); #ifdef XP_WIN HANDLE hFile = INVALID_HANDLE_VALUE; if (argc == 7) { hFile = CreateFileW(argv[6], DELETE | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hFile == INVALID_HANDLE_VALUE) { WriteMsg(outFilePath, "error_locking"); return 1; } } WriteMsg(outFilePath, "sleeping"); while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { Sleep(1000); } if (argc == 7) { CloseHandle(hFile); } #else WriteMsg(outFilePath, "sleeping"); while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { sleep(1); } #endif WriteMsg(outFilePath, "finished"); return 0; } // Command line argument test helper section NS_tchar logFilePath[MAXPATHLEN]; NS_tsnprintf(logFilePath, sizeof(logFilePath)/sizeof(logFilePath[0]), NS_T("%s"), argv[2]); FILE* logFP = NS_tfopen(logFilePath, NS_T("wb")); for (i = 1; i < argc; ++i) { fprintf(logFP, LOG_S "\n", argv[i]); } fclose(logFP); logFP = nullptr; return 0; }
int32_t dispatcher_terminate(place_t remote_place) { char* mymsg = "DIES"; volatile int32_t y = 10; int32_t succ = WriteMsg(remote_place, TERMINATE, (uint64_t)(sizeof(char)*5), (void *)mymsg); return succ; }