static int doBind(int clsock,PCStr(clhost),int clport,int tsock,PCStr(arg)){ IStr(respudp,128); IStr(local,128); IStr(remote,128); IStr(opts,128); IStr(host,128); int port; int fd; int rsock; int cpid = -1; sv1log("==SU BIND %s...\n",arg); strcpy(local,"*"); strcpy(remote,"*"); strcpy(opts,"listen=32"); Xsscanf(arg,"%s %s %s %s",AVStr(respudp),AVStr(local), AVStr(remote),AVStr(opts)); if( isWindows() || SENDFD_OVERTCP ){ rsock = clsock; sscanf(respudp,"pid=%d",&cpid); }else{ rsock = UDP_client_open("BIND/sudo","sendfd",respudp,1); sv1log("==SU rsock=%d %s\n",rsock,respudp); if( rsock < 0 ){ return -1; } } port = 0; Xsscanf(local,"%[^:]:%d",AVStr(host),&port); fd = newSocket("BIND/sudo",""); bindSock(fd,"BIND/SUDO",-1,AVStr(host),port,32); sendFd(rsock,fd,cpid); if( isWindows() ){ }else{ close(rsock); } getpairName(fd,AVStr(local),AVStr(remote)); close(fd); sv1log("==SU BOUND %d %s %s\n",fd,local,remote); /* SendTo(clsock,"OK\r\n",4,clhost,clport); */ IGNRETP write(clsock,"OK\r\n",4); sv1log("==SU returned OK\n"); return 0; }
int file_isSOCKET(int fd){ FileStat stat; if( isWindows() ){ return 0 < SocketOf(fd); }else if( fstat(fd,&stat) == 0 ){ if( S_ISSOCK(stat.st_mode) ) return 1; } return 0; }
int FL_fcloseFILE(FL_PAR,FILE *fp){ int fd = fileno(fp); fflush(fp); #if 1 setInvalidFd(fp); #else if( isWindows() ){ fp->_file = open("nul",0); }else fp->_file = -1; #endif fclose(fp); return fd; }
int inputReady(int sock,int *rd){ int fv[1]; int qv[1]; int rv[1]; int ready; if( isWindows() && !file_isSOCKET(sock) ){ ready = pollPipe(sock,TIMEOUT_IMM); return ready; } fv[0] = sock; qv[0] = PS_IN|PS_PRI; ready = PollInsOuts(0,1,fv,qv,rv); if( rd ) *rd = rv[0]; return ready; }
int AuthFunc(DGC*Conn,void*faddr,PCStr(File),int Line){ int fi; SubFunc *Sf; int found = 0; FILE *tty; for( fi = 0; fi < elnumof(subfuncs); fi++ ){ Sf = &subfuncs[fi]; if( (void*)Sf->f_func == faddr ){ found = 1; break; } } if( !found ){ lprintf("Unknown funciton: %X %s:%d\n",faddr,File,Line); Finish(-1); } if( Sf->f_stats & FC_DISABLE ){ lprintf("Disabled funciton: %X %s:%d %s\n",faddr,File,Line, Sf->f_name); if( FimpByOwner(Sf->f_name) ){ }else Finish(-1); } if( isWindows() ) /* this failes always on Win32 by the specification. tty = fopen("con","rw"); */ tty = fopen("con","r"); else tty = fopen("/dev/tty","rw"); if( tty == NULL ){ /* AUTHORIZER=as:imp::who@host ? */ if( 1 /* if not authenticated */ ){ lprintf("Forbidden remote function usage: %s:%d -F%s\n", File,Line,Sf->f_name); Finish(-1); } }else{ fclose(tty); } return 0; }
int thread_wait(int tid,int timeout){ int rcode; int nmask,smask; if( ThreadWait ){ thwait++; if( lTHREADLOG() ){ syslog_ERROR("thread_wait(%X %d)\n",tid,timeout); } if( !isWindows() && 0 < timeout ){ if( thread_wait_timeout(tid,timeout) < 0 ){ thwaitTimeout++; return -1; } } if( wait_thread(tid,timeout) < 0 ) { thwaitWaiterr++; return -1; } nmask = sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGPIPE); nmask |= sigmask(SIGHUP); smask = sigblock(nmask); rcode = (*ThreadWait)(tid,timeout); if( rcode == 0 ){ ActiveThreads--; putpplog("actthreads()--=%d [%X]\n",ActiveThreads,tid); } else{ thwaitCodeerr++; } sigsetmask(smask); return rcode; /* return (*ThreadWait)(tid,timeout); */ } return -1; }
gzFile GZdopen(int fd,const char *mode){ gzFile gz; int handle; thread_yield(); inGzip++; FL_F_Gzip = "Gzdopen"; FL_L_Gzip = __LINE__; if( isWindows() && !withDG_Zlib() ){ handle = 0x80000000 | fd2handle(fd); gz = gzdopen(handle,mode); if( gz == 0 ){ syslog_ERROR("-- failed gzdopen(0x%X)\n",handle); gz = gzdopen(fd,mode); } }else{ gz = gzdopen(fd,mode); } inGzip--; if( gz == 0 ){ syslog_ERROR("-- failed gzdopen(%d)\n",fd); } return gz; }
int pollIZ(const char *wh,double timeout,int in,int exsock){ int rem; int tom = 1000; int to1; int rdy1; int nrdy = 0; Verbose("---- poll(%s) [%d][%d] %.1f ...\n",wh,in,exsock,timeout); if( isWindows() && readyAlways(in) ){ /* 9.9.5 for Windows */ nrdy = 1; if( 0 <= exsock && !IsAlive(exsock) ){ nrdy |= 2; } }else for( rem = (int)(timeout*1000); 0 < rem; rem -= to1 ){ if( 0 <= exsock && !IsAlive(exsock) ){ nrdy |= 2; break; } if( tom < rem ) to1 = tom; else to1 = rem; rdy1 = PollIn(in,to1); if( rdy1 != 0 ){ nrdy |= 1; } Verbose("---- poll(%s) [%d][%d] %.1f %.1f rdy=%X\n",wh, in,exsock,timeout,rem/1000.0,nrdy); if( nrdy ){ break; } } if( LOG_VERBOSE || (nrdy == 0) || (nrdy & 2) ) sv1log("---- poll(%s) [%d][%d] %.1f (%.1f) rdy=%X\n",wh, in,exsock,timeout,rem/1000.0,nrdy); return nrdy; }
void sigANY(int sig){ ThreadSig *ts; vfuncp func; int tid = TID; int tix; int ti; signal(sig,sigANY); /* for non-BSD */ tix = 1+getthreadix(); nsig++; /* putfLog("####SIG(%d) tix[%d] *%d",sig,tix,nsig); VStrSIG(); */ if( lTHREADSIG() ) fprintf(stderr,"-- %X[%d] %d#gotsig %d\n",tid,tix,nsig,sig); if( sig < 0 || 32 <= sig ){ fprintf(stderr,"-- %X[%d] %d#gotsig %d BAD\n",tid,tix,nsig,sig); return; } ts = &sigs[tix][sig]; if( ts->ts_stat == 0 || ts->ts_func == sigIGNORE ){ for( ti = 0; ti < MAX_THREADS; ti++ ){ ts = &sigs[1+ti][sig]; if( ts->ts_stat && ts->ts_func != sigIGNORE ){ if( ti != tix ){ fprintf(stderr,"-- %X[%d] gotsig %d FORW >>> %X[%d] %s:%d\n", tid,tix,sig,ts->ts_tid,1+ti, ts->ts_F,ts->ts_L); if( isWindows() ){ /* thread_kill not implemented yet */ }else{ thread_kill(ts->ts_tid,sig); return; } } break; } ts = 0; } if( ts == 0 ){ ts = &sigs[0][sig]; } } if( ts->ts_stat == 0 ){ fprintf(stderr,"-- %X[%d] %d#gotsig %d UNDEF ????\n", tid,tix,nsig,sig); return; } func = ts->ts_func; if( func == SIG_DFL ){ fprintf(stderr,"-- %X[%d] %d#gotsig %d DEFAULT <= %s:%d\n", tid,tix,nsig,sig,TS_FL); }else if( func == SIG_IGN ){ fprintf(stderr,"-- %X[%d] %d#gotsig %d IGNORED <= %s:%d\n", tid,tix,nsig,sig,TS_FL); }else{ if( lTHREADSIG() ) fprintf(stderr,"-- %X[%d] %d#gotsig %d HANDLED <= %s:%d %X\n", tid,tix,nsig,sig,TS_FL,xp2i(func)); (*func)(sig); if( lTHREADSIG() ) fprintf(stderr,"-- %X[%d] %d#gotsig %d HANDLED <= %s:%d %X\n", tid,tix,nsig,sig,TS_FL,xp2i(func)); } if( sig == SIGSEGV ){ void msleep(int); msleep(250); } }
int gunzipFilterX(FILE *in,FILE *out,SyncF syncf,void *sp,int si){ gzFile gz; int rcc; int wcc; int werr; CStr(buf,1024*8); int size; double Start = Time(); const char *em; int en; int ef; int ready; int rd; int eof = 0; int nonblock; int serrno = 0; int ibz = sizeof(buf); int gi; int fd = -1; inlen = 0; errno = 0; fd = dup(fileno(in)); if( isWindows() ){ int pollPipe(int,int); nonblock = 0; ready = fPollIn(in,10*1000); gz = GZdopen(fd,"r"); if( gz == 0 ) syslog_ERROR("##gunzipFilter[%d/%d] gz=%X ready=%d/%d\n", fd,fileno(in),p2i(gz),ready,pollPipe(fd,1)); }else{ /* * to make smooth streaming of data relayed on narrow network * apply NBIO to gzopen() which will do fread() at the start. * applying NBIO also to gzread() seems to break the gzip. */ /* setNonblockingIO(fileno(in),1); */ setNonblockingIO(fd,1); nonblock = 1; ready = fPollIn(in,10*1000); if( ready == 0 ){ fprintf(stderr,"----[%d] gunzipFilter: ready[%d]=%d\n", getpid(),fileno(in),ready); } /* gz = GZdopen(fd = dup(fileno(in)),"r"); */ gz = GZdopen(fd,"r"); if( DGzlibVer == 0 ) { /* setNonblockingIO(fileno(in),0); */ setNonblockingIO(fd,0); nonblock = 0; } } if( syncf != 0 ){ syslog_ERROR("--- gunzipFX SYNC %X(%X,%d)\n",xp2i(syncf),p2i(sp),si); (*syncf)(sp,si); } ibz = 1024; //ibz = 256; size = 0; /* if( gz = GZdopen(dup(fileno(in)),"r") ){ */ if( gz ){ LOGX_gunzip++; setCloseOnFork("GUNZIPstart",fd); em = gzerror(gz,&en); /* while( 0 < (rcc = gzread(gz,buf,sizeof(buf))) ){ */ for( gi = 0;; gi++ ){ if( gotsigTERM("gunzip gi=%d em=%X",gi,p2i(em)) ){ if( numthreads() ){ if( em ){ putfLog("thread-gunzip gi=%d _exit() em=(%s)",gi,em?em:""); _exit(0); } thread_exit(0); } break; } if( nonblock ){ if( 0 < gi ){ /* setNonblockingIO(fileno(in),0); */ setNonblockingIO(fd,0); nonblock = 0; } } /* if( 0 < size && inputReady(fileno(in),NULL) == 0 ){ */ /* if( 0 < size && inputReady(fd,NULL) == 0 ){ */ if( eof == 0 ) if( 0 < size ) if( ready = inputReady(fd,&rd) ){ if( ready == 2 ){ /* both PS_IN and PS_PRI */ eof = 1; } }else{ //fprintf(stderr,"[%d] -- gzread#%d %d / %d FLUSH\n",getpid(),gi,rcc,size); fflush(out); } ready = fPollIn(in,10*1000); errno = 0; rcc = gzread(gz,buf,QVSSize(buf,ibz)); serrno = errno; if( rcc <= 0 ){ break; } //fprintf(stderr,"[%d] -- gzread %d / %d\n",getpid(),rcc,size); wcc = fwrite(buf,1,rcc,out); /* this fflush seems significant */ werr = fflush(out); if( wcc < rcc || werr || ferror(out) || gotSIGPIPE() ){ porting_dbg("+++EPIPE[%d] gunzip fwrite() %d/%d err=%d/%d %d SIG*%d",fileno(out),wcc,rcc,werr,ferror(out),size,gotSIGPIPE()); break; } size += rcc; if( size < sizeof(buf) ){ fflush(out); }else{ ibz = sizeof(buf); } } fflush(out); if( rcc < 0 || size == 0 ){ em = gzerror(gz,&en); ef = gzeof(gz); if( en == -1 /* see errno */ && serrno == 0 ){ /* no error */ }else{ daemonlog("F","FATAL: gzread(%d)=%d/%d eof=%d %d %s %d\n", fd,rcc,size,ef,en,em,serrno); porting_dbg("FATAL: gzread(%d)=%d/%d eof=%d %d %s", fd,rcc,size,ef,en,em); if( lTHREAD() ) fprintf(stderr,"--[%d]gzread(%d)=%d/%d eof=%d %d %s\n", getpid(),fd,rcc,size,ef,en,em); } } clearCloseOnFork("GUNZIPend",fd); GZclose(gz); if( isWindowsCE() || lMULTIST() ){ /* duplicated close of fd is harmful */ }else if( isWindows() ) close(fd); fseek(out,0,0); syslog_DEBUG("(%f)gunzipFilter -> %d\n",Time()-Start,size); if( lTHREAD() ) if( 0 < inlen ) syslog_ERROR("###GUNZIP filter %d/%d\n",inlen,size); return size; } return 0; }
int gzipFilterX(FILE *in,FILE *out,SyncXF syncf,void *sp,int si){ gzFile gz; int len,rcc; CStr(buf,1024*8); int size; int gsize; int wcc; int bcc = 0; double Start = Time(); double Prevf = 0; int ibz = sizeof(buf); int gi; int fd = -1; int ofd = fileno(out); int xfd; int zerr = 0; /* int rready = -1; */ errno = 0; fd = dup(fileno(out)); if( fd < 0 ){ syslog_ERROR("--gzipFilter[%d]<-[%d] errno=%d\n",fd,ofd,errno); return -1; } /* if( 0 <= GZIPready ) rready = dup(GZIPready); */ len = 0; /* if( gz = GZdopen(dup(fileno(out)),"w") ){ */ if( file_isSOCKET(ofd) || file_ISSOCK(ofd) ) if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){ fprintf(stderr,"[%d.%X] gzip DISCONN\n",getpid(),getthreadid()); fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n", getpid(),getthreadid(),ofd,IsConnected(ofd,NULL), file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd)); sendsync(rready,1); close(fd); return -1; } gz = GZdopen(fd,"w"); if( file_isSOCKET(ofd) || file_ISSOCK(ofd) ) if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){ fprintf(stderr,"[%d.%X] gzip DISCONN gx=%d\n",getpid(),getthreadid(),p2i(gz)); fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n", getpid(),getthreadid(),ofd,IsConnected(ofd,NULL), file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd)); close(fd); sendsync(rready,2); close(fd); return -1; } if( gz ){ LOGX_gzip++; if( Gzip_NoFlush ){ GZDBG(stderr,"-- %X gzip flush disabled(%d)\n", TID,Gzip_NoFlush); } Prevf = Time(); sendsync(rready,0); setCloseOnFork("GZIPstart",fd); /* while( rcc = fread(buf,1,sizeof(buf),in) ){ */ for( gi = 0;; gi++ ){ if( gotsigTERM("gzip gi=%d",gi) ){ if( numthreads() && !ismainthread() ){ thread_exit(0); } break; } if( !Gzip_NoFlush ) if( bcc ) if( 0 < len && finputReady(in,NULL) == 0 ){ zerr = gzflush(gz,Z_SYNC_FLUSH); if( zerr ){ porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE()); } bcc = 0; } if( lSINGLEP() ) /* could be generic */ { if( 0 < len ) if( !Gzip_NoFlush || 4 < gi && 5 < Time()-Prevf ){ GZDBG(stderr,"-- %X gzip flush %d(%f) %d/%d\n", TID,Gzip_NoFlush,Time()-Start,len,gi); Prevf = Time(); zerr = gzflush(gz,Z_SYNC_FLUSH); bcc = 0; if( zerr ){ GZDBG(stderr,"-- %X gzip gzflush()%d err=%d\n", TID,len,zerr); break; } } } /* rcc = fread(buf,1,sizeof(buf),in); */ rcc = xread(in,AVStr(buf),QVSSize(buf,ibz)); if( rcc <= 0 ){ break; } wcc = gzwrite(gz,buf,rcc); //fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len); if( wcc <= 0 ){ porting_dbg("+++EPIPE[%d] gzwrite() %d/%d %d SIG*%d",fd,wcc,rcc,len,gotSIGPIPE()); fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len); break; } if( wcc != rcc ){ syslog_ERROR("gzwrite %d/%d\n",wcc,rcc); } if( 0 < wcc ){ bcc += wcc; } if( sizeof(buf) <= len ){ ibz = sizeof(buf); } if( !Gzip_NoFlush ) if( bcc ) if( sizeof(buf) <= bcc || len < 16*1024 ){ zerr = gzflush(gz,Z_SYNC_FLUSH); bcc = 0; } if( zerr || gotSIGPIPE() ){ porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE()); break; } len += rcc; } if( len == 0 ){ const char *em; int en; int ef; em = gzerror(gz,&en); ef = gzeof(gz); if( en == -1 /* see errno */ && errno == 0 ){ /* no error */ }else{ daemonlog("F","FATAL: gzwrite(%d)=%d/%d eof=%d %d %s\n", fd,len,bcc,ef,en,em); porting_dbg("FATAL: gzwrite(%d)=%d/%d eof=%d %d %s", fd,len,bcc,ef,en,em); } } clearCloseOnFork("GZIPend",fd); gzflush(gz,Z_SYNC_FLUSH); xfd = dup(fd); gsize = GZtell(gz); GZclose(gz); if( isWindowsCE() || lMULTIST() ){ /* duplicated close of fd is harmful */ }else if( isWindows() ) close(fd); /* to clear osf-handle mapping */ Lseek(xfd,0,2); size = Lseek(xfd,0,1); Lseek(xfd,0,0); close(xfd); syslog_DEBUG("(%f)gzipFilter %d -> %d / %d\n",Time()-Start, len,gsize,size); return len; } sendsync(rready,3); close(fd); return 0; }
/* int WaitXX(int mode,int *sigp) */ int WaitXXX(int mode,int *sigp,int *statp) { int status[4]; /**/ int pid,xpid,sig,xcode,st; int serrno; if( sigp ) *sigp = 0; for(;;) { pid = wait3(status,mode,NULL); if( statp ) { *statp = getWaitExitCode(status); } if( !lTRACE() ) if( sigp == NULL ) break; if( pid <= 0 ) break; st = status[0]; if( 0 <= (xcode = getWaitExitCode(status)) ) { if( isWindows() ) { /* introduced in 6.0.4 for PTRACE ? * but seems useless to wait exited process * and anyway unsupported on Windows */ xpid = -1; } else xpid = waitpid(pid,status,0); if( lTRVERB() ) TraceLog("- Wait [%04X] pid=%d EXITED(%d) %d\n", st,pid,xcode,xpid); return pid; } if( 0 < (sig = getWaitExitSig(status)) ) { xpid = waitpid(pid,status,0); TraceLog("- Wait [%04X] pid=%d SIGNALED(%d=%s)%s %d\n", st,pid,sig,sigsym(sig), getWaitExitCore(status)?" COREDUMP":"",xpid); if( sigp ) *sigp = sig; return pid; } if( 0 < (sig = getWaitStopSig(status)) ) { if( lTRVERB() || !usualsig(sig) ) TraceLog("- Wait [%04X] pid=%d STOPSIG(%d=%s)\n", st,pid,sig,sigsym(sig)); if( sig == SIGTRAP ) { if( lNOEXEC() ) ptraceKill(pid); else ptraceContinue(pid,0); } else ptraceContinue(pid,sig); continue; } TraceLog("- Wait [%04X] pid=%d wait unknown\n",st,pid); if( mode == WAIT_WNOHANG ) break; } /* serrno = errno; syslog_ERROR("-- Wait()=%d, errno=%d\n",pid,errno); errno = serrno; */ return pid; }
int do_autotest_regression_streaming_transcode_negative(int argc, const char* argv[]) { int rv = VPL_OK; u32 retry = 0; u32 photoAlbumNum = 0; u32 photoNum = 0; u32 expectedPhotoNum = 0; std::string photosToStream = "-1"; // meaning no limit int cloudPCId = 1; int clientPCId = 2; std::string CloudPC_alias = "CloudPC"; std::string MD_alias = "MD"; std::string osVersion; const char* TEST_TRANSCODE2_STR = "SdkTranscodeStreamingPositive"; bool full = false; if (argc == 6 && (strcmp(argv[5], "-f") == 0 || strcmp(argv[5], "--fulltest") == 0) ) { full = true; } if (checkHelp(argc, argv) || (argc < 5) || (argc == 6 && !full)) { printf("AutoTest %s <username> <password> <expectedPhotoNum> [<fulltest>(-f/--fulltest)]\n", argv[0]); return 0; // No arguments needed } LOG_ALWAYS("AutoTest Transcode Streaming: Domain(%s) User(%s) Password(%s) ExpectedPhotoNum(%s)", argv[1], argv[2], argv[3], argv[4]); // Does a hard stop for all ccds { const char *testArg[] = { "StopCCD" }; stop_ccd_hard(ARRAY_ELEMENT_COUNT(testArg), testArg); } expectedPhotoNum = static_cast<u32>(atoi(argv[4])); VPLFile_Delete("dumpfile"); LOG_ALWAYS("\n\n==== Launching Cloud PC CCD (instanceId %d) ====", cloudPCId); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, CloudPC_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(cloudPCId); } CHECK_LINK_REMOTE_AGENT(CloudPC_alias, TEST_TRANSCODE2_STR, rv); START_CCD(TEST_TRANSCODE2_STR, rv); START_CLOUDPC(argv[2], argv[3], TEST_TRANSCODE2_STR, true, rv); VPLThread_Sleep(VPLTIME_FROM_MILLISEC(1000)); LOG_ALWAYS("\n\n==== Launching MD CCD (instanceId %d) ====", clientPCId); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, MD_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(clientPCId); } CHECK_LINK_REMOTE_AGENT(MD_alias, TEST_TRANSCODE2_STR, rv); QUERY_TARGET_OSVERSION(osVersion, TEST_TRANSCODE2_STR, rv); START_CCD(TEST_TRANSCODE2_STR, rv); UPDATE_APP_STATE(TEST_TRANSCODE2_STR, rv); START_CLIENT(argv[2], argv[3], TEST_TRANSCODE2_STR, true, rv); VPLThread_Sleep(VPLTIME_FROM_MILLISEC(1000)); // make sure both cloudpc/client has the device linked info updated LOG_ALWAYS("\n\n== Checking cloudpc and Client device link status =="); { std::vector<u64> deviceIds; u64 userId = 0; u64 cloudPCDeviceId = 0; u64 MDDeviceId = 0; const char *testCloudStr = "CheckCloudPCDeviceLinkStatus"; const char *testMDStr = "CheckMDDeviceLinkStatus"; SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, CloudPC_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(cloudPCId); } rv = getUserIdBasic(&userId); if (rv != 0) { LOG_ERROR("Fail to get user id:%d", rv); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testCloudStr, rv); } rv = getDeviceId(&cloudPCDeviceId); if (rv != 0) { LOG_ERROR("Fail to get CloudPC device id:%d", rv); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testCloudStr, rv); } SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, MD_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(cloudPCId); } rv = getDeviceId(&MDDeviceId); if (rv != 0) { LOG_ERROR("Fail to get MD device id:%d", rv); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testMDStr, rv); } deviceIds.push_back(cloudPCDeviceId); LOG_ALWAYS("Add Device Id "FMTu64, cloudPCDeviceId); deviceIds.push_back(MDDeviceId); LOG_ALWAYS("Add Device Id "FMTu64, MDDeviceId); rv = wait_for_devices_to_be_online_by_alias(TEST_TRANSCODE2_STR, CloudPC_alias.c_str(), cloudPCId, userId, deviceIds, 20); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testCloudStr, rv); rv = wait_for_devices_to_be_online_by_alias(TEST_TRANSCODE2_STR, MD_alias.c_str(), clientPCId, userId, deviceIds, 20); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testMDStr, rv); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, MD_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(clientPCId); } rv = wait_for_cloudpc_get_accesshandle(userId, cloudPCDeviceId, 20); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "CheckCloudPCGetAccessHandle", rv); } LOG_ALWAYS("\n\n==== Testing ClearMetadata (CloudPC) ===="); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, CloudPC_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(cloudPCId); } { const char *testStr = "ClearMetadata"; const char *testArg[] = { testStr }; rv = msa_delete_catalog(ARRAY_ELEMENT_COUNT(testArg), testArg); if(rv != 0) { LOG_ERROR("RegressionStreaming_ClearMetadata failed!"); } CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, testStr, rv); } #if defined(CLOUDNODE) LOG_ALWAYS("\n\n==== Testing CloudMedia CloudnodeAddPhoto (ClientPC) ===="); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, MD_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(clientPCId); } { std::string dxroot; std::string photoSetPath; rv = getDxRootPath(dxroot); if (rv != VPL_OK) { LOG_ERROR("Fail to set %s root path", argv[0]); goto exit; } photoSetPath.assign(dxroot.c_str()); const char *testStr1 = "CloudMedia"; const char *testStr2 = "CloudnodeAddPhoto"; photoSetPath.append("/GoldenTest/image_transcode_negative_test_1"); const char *testArg4[] = { testStr1, testStr2, photoSetPath.c_str() }; rv = cloudmedia_commands(3, testArg4); if (rv != VPL_OK) { LOG_ERROR("SdkTranscodeStreaming2_CloudMedia_CloudnodeAddPhoto failed!"); } CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "CloudMedia_CloudnodeAddPhoto", rv); } #endif // CLOUDNODE LOG_ALWAYS("\n\n==== Testing CloudMedia AddPhoto (CloudPC) ===="); SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, CloudPC_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(cloudPCId); } { std::string dxroot; std::string photoSetPath; rv = getDxRootPath(dxroot); if (rv != VPL_OK) { LOG_ERROR("Fail to set %s root path", argv[0]); goto exit; } photoSetPath.assign(dxroot.c_str()); const char *testStr1 = "CloudMedia"; const char *testStr2 = "AddPhoto"; photoSetPath.append("/GoldenTest/image_transcode_negative_test_1"); const char *testArg4[] = { testStr1, testStr2, photoSetPath.c_str() }; rv = cloudmedia_commands(3, testArg4); if (rv != VPL_OK) { LOG_ERROR("SdkTranscodeStreaming2_CloudMedia_AddPhoto failed!"); } CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "CloudMedia_AddPhoto", rv); } // Verify if the metadata is synced retry = 0; SET_TARGET_MACHINE(TEST_TRANSCODE2_STR, MD_alias.c_str(), rv); if (rv < 0) { setCcdTestInstanceNum(clientPCId); } LOG_ALWAYS("\n\n==== List Metadata (ClientPC) ===="); { VPLTime_t startTime = VPLTime_GetTimeStamp(); while(1) { rv = mca_get_photo_object_num(photoAlbumNum, photoNum); if(rv != VPL_OK) { LOG_ERROR("Cannot get photo count from metadata"); } else if(photoNum == expectedPhotoNum) { u64 elapsedTime = VPLTIME_TO_SEC(VPLTime_GetTimeStamp() - startTime); LOG_ALWAYS("Retry (%d) times waited ("FMTu64") seconds for photo to be synced.", retry, elapsedTime); break; } if(retry++ > METADATA_SYNC_TIMEOUT) { u64 elapsedTime = VPLTIME_TO_SEC(VPLTime_GetTimeStamp() - startTime); LOG_ERROR("Timeout retry (%d) waiting for metadata to sync; waited for ("FMTu64") seconds.", retry, elapsedTime); rv = -1; break; } else { LOG_ALWAYS("Waiting (cnt %d) photoNum (%d) photoAlbumNum (%d)", retry, photoNum, photoAlbumNum); } VPLThread_Sleep(VPLTIME_FROM_SEC(1)); } LOG_ALWAYS("Photo added by CloudPC: %d; Expected photo: %d", photoNum, expectedPhotoNum); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "Verify_Uploaded_Photo_Num1", rv); } LOG_ALWAYS("\n\n==== SetupStreamTest to generate dump file ===="); { const char *testStr = "SetupStreamTest"; const char *testArg[] = { testStr, "-d", "dumpfile", "-f", "2", "-M", photosToStream.c_str() }; rv = setup_stream_test(ARRAY_ELEMENT_COUNT(testArg), testArg); CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "SetupStreamTest_dumpfile", rv); } // Negative Test - Scale an invalid photo to 800x800 LOG_ALWAYS("\n\n==== Negative Test, scale an invalid photo to 800x800 ===="); { const char *testStr = "TimeStreamDownload"; const char *testArg[] = { testStr, "-d", "dumpfile", "-R", "800,800", "-f", "JPG" }; rv = time_stream_download(ARRAY_ELEMENT_COUNT(testArg), testArg); if (rv == -1) { rv = 0; } else if (rv == 0) { if(osVersion == OS_LINUX) { rv = -1; CHECK_AND_PRINT_EXPECTED_TO_FAIL(TEST_TRANSCODE2_STR, "NegativeTest_InvalidImage", rv, "13344"); rv = 0; goto exit; } } else { LOG_ERROR("Expected -1, but got %d", rv); rv = -1; } CHECK_AND_PRINT_RESULT(TEST_TRANSCODE2_STR, "NegativeTest_InvalidImage", rv); } exit: LOG_ALWAYS("\n\n== Freeing Client =="); if(set_target_machine(MD_alias.c_str()) < 0) setCcdTestInstanceNum(clientPCId); { const char *testArg[] = { "StopClient" }; stop_client(ARRAY_ELEMENT_COUNT(testArg), testArg); } if (isWindows(osVersion) || osVersion.compare(OS_LINUX) == 0) { const char *testArg[] = { "StopCCD" }; stop_ccd_soft(ARRAY_ELEMENT_COUNT(testArg), testArg); } LOG_ALWAYS("\n\n== Freeing Cloud PC =="); if(set_target_machine(CloudPC_alias.c_str()) < 0) setCcdTestInstanceNum(cloudPCId); { const char *testArg[] = { "StopCloudPC" }; stop_cloudpc(ARRAY_ELEMENT_COUNT(testArg), testArg); } { const char *testArg[] = { "StopCCD" }; stop_ccd_soft(ARRAY_ELEMENT_COUNT(testArg), testArg); } return rv; }
int bindViaSudo(int sock,VSAddr *sap,int len){ int tsock; CStr(msg,128); CStr(addrport,128); CStr(local,128); CStr(remote,128); int wcc; double Start = Time(); int newfd; CStr(respudp,1024); int rsock; int fd; if( IamSUDO ){ return -1; } if( connectSudo(&tsock) != 0 ) return -1; if( isWindows() || SENDFD_OVERTCP ){ rsock = tsock; sprintf(respudp,"pid=%d",getpid()); }else{ rsock = getMyresp(AVStr(respudp)); if( rsock < 0 ){ return -1; } } VSA_satoap(sap,AVStr(addrport)); sv1log("--SU command BIND %s\n",addrport); sprintf(msg,"BIND %s %s\r\n",respudp,addrport); sv1log("--SU command BIND sockfd=%d ==> %d\n",sock,tsock); wcc = write(tsock,msg,strlen(msg)); sv1log("--SU polling %d %d ...\n",tsock,rsock); if( PollIn(tsock,3*1000) <= 0 ){ close(rsock); return -1; } sv1log("--SU poll done %d %d\n",tsock,rsock); if( tsock != rsock ){ /* Windows */ if( PollIn(rsock,3*1000) <= 0 ){ sv1log("--SU poll UDP timeout %d\n",rsock); close(rsock); return -1; } } fd = recvFd(rsock); sv1log("--SU recvFd rsock:%d ==> %d\n",rsock,fd); if( fd < 0 ){ return -1; } getpairName(fd,AVStr(local),AVStr(remote)); sv1log("--SU recvFd rsock:%d ==> %d [%s]\n",rsock,fd,local); close(tsock); sv1log("--SU [%s]=>[%s]\n",addrport,local); if( streq(addrport,local) ){ sv1log("--SU DUP [%d]=>[%d]\n",fd,sock); dup2(fd,sock); close(fd); return 0; }else{ close(fd); return -1; } }