bool EGPlanner::checkTerminationConditions() { if (!isActive()) { return true; } bool termination = false; //max steps equal to -1 means run forever if (mMaxSteps != -1 && mCurrentStep >= mMaxSteps) { if (!mRepeat) { pausePlanner(); termination = true; } else { resetParameters(); } if (!mMultiThread) { Q_EMIT update(); } } else if (mMaxTime != -1) { //check time limit //for now exceeding the time limit simply kills it for good if (getRunningTime() > mMaxTime) { termination = true; stopPlanner(); } } if (termination) { Q_EMIT complete(); } return termination; }
/*! Attempts to maintain a list of unique solutions. Therefore, whenever a new state is added to the list, we check if any of the states that are already in the list are within a given distance of the new state. If so, the best one is kept and the other one is thrown away. This method does not gurantee unique states, but it comes close and runs in linear time for each addition, rather than square time for maintenance. */ bool EGPlanner::addToListOfUniqueSolutions(GraspPlanningState *s, std::list<GraspPlanningState*> *list, double distance) { std::list<GraspPlanningState*>::iterator it; it = list->begin(); bool add = true; while (it!=list->end()) { double d = stateDistance(s,*it); if ( fabs(d) < distance ) { DBGP("Distance: " << fabs(d) ); //states are close to each other if ( s->getEnergy() < (*it)->getEnergy() ) { //new state is better; remove old one from list delete (*it); it = list->erase(it); DBGP("Old state removed"); } else { //old state is better; we don't want to add the new one add = false; break; } } else { //states are not close, proceed through the list it++; } } if (add) { list->push_back(s); s->addAttribute("PlanningTime", getRunningTime()); s->addAttribute("PlanningSteps", mCurrentStep); } return add; }
void EGPlanner::pausePlanner() { if (getState() != RUNNING) return; mRunningTime = getRunningTime(); if (!mMultiThread) { if (mIdleSensor) delete mIdleSensor; mIdleSensor = NULL; mHand->showVirtualContacts(true); } setState(READY); PROF_STOP_TIMER(EG_PLANNER); PROF_PRINT_ALL; if (!mMultiThread) emit complete(); }
void TraceProcess::traceMe() { struct user_regs_struct regs; DLOG(INFO) << pid << " trace_me\n"; //the waitpid function will be interuppted by the SIGCHLD signal int wret; #ifdef HAVE_WAIT4 while((wret = wait4(this->pid, &status, 0, &process_usage)) > 0) { getusage = true; #else while((wret = waitpid(this->pid, &status, 0)) > 0) { #endif //DLOG(INFO) << pid << " waitpid return " << wret << "\n"; if(WIFSIGNALED(status)) { DLOG(INFO) << "TraceProcess()::traceMe(): child was killed by signal\n"; _exit = true; if(WTERMSIG(status) == SIGKILL && this->_result == -1) { this->_result = RUNTIME_ERROR; } break; } if(!WIFSTOPPED(status)) { //if(WEXITSTATUS(status)) { // this->_result = RUNTIME_ERROR; //} _exit = true; break; } int sig = WSTOPSIG(status); if(sig != SIGTRAP) { DLOG(INFO) << "TraceProcess()::traceMe(): caught a signal " << sig << "\n"; getRunningTime(); getRunningMemory(); switch(sig) { case SIGFPE: DLOG(INFO) << "TraceProcess()::traceMe(): SIGFPE\n"; this->_result = FLOATING_POINT_ERROR; break; case SIGXCPU: DLOG(INFO) << "TraceProcess()::traceMe(): SIGXCPU\n"; this->_result = TIME_LIMIT_EXCEEDED; break; case SIGBUS: case SIGSEGV: DLOG(INFO) << "TraceProcess()::traceMe(): SIGSEGV\n"; this->_result = SEGMENTATION_FAULT; break; case SIGXFSZ: DLOG(INFO) << "TraceProcess()::traceMe(): SIGXFSZ\n"; this->_result = OUTPUT_LIMIT_EXCEEDED; break; case SIGILL: case SIGKILL: DLOG(INFO) << "TraceProcess()::traceMe(): SIGKILL\n"; if(this->_result == -1) { this->_result = RUNTIME_ERROR; } break; case SIGALRM: ; } ptrace(PTRACE_SYSCALL, this->pid, NULL, sig); continue; } ptrace(PTRACE_GETREGS, this->pid, 0, ®s); switch(regs.ORIG_EAX) { case SYS_exit: case SYS_exit_group: DLOG(INFO) << "TraceProcess()::traceMe(): child sys_exit\n"; getRunningTime(); getRunningMemory(); break; case SYS_execve: if(!first_exec) { first_exec = true; DLOG(INFO) << pid << " execve, ptrace it\n"; ptrace(PTRACE_SYSCALL, this->pid, NULL, NULL); continue; } break; case SYS_brk: if(!insyscall) { brk = (unsigned long)regs.EBX; insyscall = true; }else{ if(((unsigned long)regs.EAX) < brk) { DLOG(INFO) << "TraceProcess()::traceMe(): brk request " << brk << " return " << regs.EAX << "\n"; this->_result = MEMORY_LIMIT_EXCEEDED; ptrace(PTRACE_KILL, this->pid, 0, 0); continue; } insyscall = false; } break; case SYS_open: if(!insyscall) { char path[FILENAME_MAX + 1]; insyscall = true; getdata(regs.EBX, path, sizeof(path)); DLOG(INFO) << "open file:" << path << "\n"; if(!canOpen(path, regs.ECX)) { regs.ORIG_EAX = SYS_exit; regs.EBX = 1; ptrace(PTRACE_SETREGS, this->pid, 0, ®s); this->_result = RUNTIME_ERROR; break; } }else{ insyscall = false; } ptrace(PTRACE_SYSCALL, this->pid, 0, 0); continue; } if(regs.ORIG_EAX < sizeof(disabled_syscall) && disabled_syscall[regs.ORIG_EAX]) { DLOG(INFO) << "TraceProcess()::traceMe(): Restricted syscall " << regs.ORIG_EAX << "\n"; this->_result = RESTRICTED_FUNCTION; getRunningTime(); getRunningMemory(); regs.ORIG_EAX = SYS_exit; regs.EAX = SYS_exit; regs.EBX = 1; ptrace(PTRACE_SETREGS, this->pid, NULL, ®s); ptrace(PTRACE_KILL, this->pid, 0, 0); continue; }else{ ptrace(PTRACE_SYSCALL, this->pid, 0, 0); } ptrace(PTRACE_SYSCALL, this->pid, NULL, NULL); } }