コード例 #1
0
/*! Deletes any children that are done. If there are seeds available and
	emtpty children slots it also fires of new children. If a new child
	is fired and the main planner is still in the area, the main planner 
	is also reset so it goes plan somewhere else.
*/
void
GuidedPlanner::checkChildren()
{
	//first check if any children have stopped
	SimAnnPlanner *pl;
	std::vector<SimAnnPlanner*>::iterator it;
	it = mChildPlanners.begin();
	while(it!=mChildPlanners.end()) {
		pl = (*it);
		if ( !pl->isActive() ) {
			stopChild(pl);
			it = mChildPlanners.erase( it );
			delete pl;
			DBGA("Child stopped.");
		} else {
			it++;
		}
	}

	//if the planner is paused, do not fire any new children
	if (!isActive()) return;

	//now check if we have seeds and children available
	while ((int)mChildPlanners.size() < mMaxChildren && !mChildSeeds.empty()) {	
		GraspPlanningState *seed = mChildSeeds.front();
		mChildSeeds.pop_front();
		//avoid this state in the future since it will be searched by a child
		mAvoidList.push_back(seed);
		startChild(seed);
		if (mCurrentState->distance(seed) < mDistanceThreshold) {
			//re-anneal to make sure we search in some other area
			resetParameters();
		}
	}
}
コード例 #2
0
ファイル: watcher.cpp プロジェクト: SaghroGuy/osquery
bool WatcherRunner::watch(const PlatformProcess& child) const {
  int status = 0;

  ProcessState result = checkChildProcessStatus(child, status);
  if (Watcher::fatesBound()) {
    // A signal was handled while the watcher was watching.
    return false;
  }

  if (!child.isValid() || result == PROCESS_ERROR) {
    // Worker does not exist or never existed.
    return false;
  } else if (result == PROCESS_STILL_ALIVE) {
    // If the inspect finds problems it will stop/restart the worker.
    if (!isChildSane(child)) {
      stopChild(child);
      return false;
    }
    return true;
  }

  if (result == PROCESS_EXITED) {
    // If the worker process existed, store the exit code.
    Watcher::instance().worker_status_ = status;
  }

  return true;
}
コード例 #3
0
void VideoController::digitalVideo(bool showState, uint32_t ipAddress)
{
    if (showState)
    {
        pid_t pid = fork();
        if (pid == -1)
        {
            COMM_EXCEPTION(LaunchException, "Failed to fork server process");
        }
        
        if (pid == 0)
        {
            ip::address_v4 addr(ipAddress);
            std::string str = addr.to_string();
            
            std::cout << "Send video to " << str << std::endl;
            int execResult = execlp(
                "/etc/cherokey-robot/run_video_wifi", "run_video_wifi",
                str.c_str(), NULL);
            
            exit(execResult);
        }
        else
        {
            videoProcessPID = pid;
        }
    }
    else
    {
        stopChild();
    }
}
コード例 #4
0
void VideoController::compositeVideo(bool showState)
{
    if (showState)
    {
        pid_t pid = fork();
        if (pid == -1)
        {
            COMM_EXCEPTION(LaunchException, "Failed to fork server process");
        }
        
        if (pid == 0)
        {
            int execResult = execlp(
                "/etc/cherokey-robot/run_video_composite", NULL);
            
            exit(execResult);
        }
        else
        {
            videoProcessPID = pid;
        }
        
        try
        {
            videoTXPower->setLogicalLevel(pc::GPIO_LOGIC_LEVEL::high);
        }
        catch (std::exception&)
        {
            stopChild();
            throw;
        }
    }
    else
    {
        stopChild();
        videoTXPower->setLogicalLevel(pc::GPIO_LOGIC_LEVEL::low);
    }
}
コード例 #5
0
ファイル: sudo.cpp プロジェクト: ThomasVie/lxqt-sudo
int Sudo::parent()
{
    //set the FD as non-blocking
    if (0 != fcntl(mPwdFd, F_SETFL, O_NONBLOCK))
    {
        QMessageBox(QMessageBox::Critical, mDlg->windowTitle()
                , tr("Failed to set non-block: %1").arg(strerror(errno)), QMessageBox::Ok).exec();
        return 1;
    }

    FILE * pwd_f = fdopen(mPwdFd, "r+");
    if (nullptr == pwd_f)
    {
        QMessageBox(QMessageBox::Critical, mDlg->windowTitle()
                , tr("Failed to fdopen: %1").arg(strerror(errno)), QMessageBox::Ok).exec();
        return 1;
    }

    QTextStream child_str{pwd_f};

    QObject::connect(mDlg.data(), &QDialog::finished, [&] (int result)
        {
            if (QDialog::Accepted == result)
            {
                child_str << mDlg->password().append(nl);
                child_str.flush();
            } else
            {
                stopChild();
                lxqtApp->quit();
            }
        });

    QString last_line;
    QScopedPointer<QSocketNotifier> pwd_watcher{new QSocketNotifier{mPwdFd, QSocketNotifier::Read}};
    QObject::connect(pwd_watcher.data(), &QSocketNotifier::activated, [&]
        {
            QString line = child_str.readAll();
            if (line.isEmpty())
            {
                pwd_watcher.reset(nullptr);
                QString const & prog = BACK_SU == mBackend ? su_prog : sudo_prog;
                if (last_line.startsWith(QStringLiteral("%1:").arg(prog)))
                {
                    pwd_watcher.reset(nullptr); //stop the notifications events
                    stopChild();
                    QMessageBox(QMessageBox::Critical, mDlg->windowTitle()
                            , tr("Child '%1' process failed!\n%2").arg(prog).arg(last_line), QMessageBox::Ok).exec();
                }
                lxqtApp->quit();
            } else
            {
                if (line.endsWith(pwd_prompt_end))
                {
                    //if now echo is turned off, su/sudo requests password
                    struct termios tios;
                    //loop to be sure we don't miss the flag (we can afford such small delay in "normal" output processing)
                    for (size_t cnt = 10; 0 < cnt && 0 == tcgetattr(mPwdFd, &tios) && (ECHO & tios.c_lflag); --cnt)
                        QThread::msleep(10);
                    if (!(ECHO & tios.c_lflag))
                    {
                        mDlg->show();
                        return;
                    }
                }
                QTextStream{stderr, QIODevice::WriteOnly} << line;
                //assuming text oriented output
                QStringList lines = line.split(nl, QString::SkipEmptyParts);
                last_line = lines.isEmpty() ? QString() : lines.back();
            }

        });

    lxqtApp->exec();

    if (0 < mChildPid)
    {
        int res, status;
        res = waitpid(mChildPid, &status, 0);
        mRet = (mChildPid == res && WIFEXITED(status)) ? WEXITSTATUS(status) : 1;
    }

    return mRet;
}