コード例 #1
0
ファイル: LaunchDaemon.cpp プロジェクト: garodimb/haiku
void
LaunchDaemon::_HandleGetLaunchJobInfo(BMessage* message)
{
	uid_t user = _GetUserID(message);
	if (user < 0)
		return;

	const char* name = message->GetString("name");
	Job* job = FindJob(name);
	if (job == NULL && !fUserMode) {
		_ForwardEventMessage(user, message);
		return;
	}

	BMessage info(uint32(job != NULL ? B_OK : B_NAME_NOT_FOUND));
	if (job != NULL) {
		_GetBaseJobInfo(job, info);

		info.SetInt32("team", job->Team());
		info.SetBool("enabled", job->IsEnabled());
		info.SetBool("running", job->IsRunning());
		info.SetBool("launched", job->IsLaunched());
		info.SetBool("service", job->IsService());

		if (job->Target() != NULL)
			info.SetString("target", job->Target()->Name());

		for (int32 i = 0; i < job->Arguments().CountStrings(); i++)
			info.AddString("launch", job->Arguments().StringAt(i));

		for (int32 i = 0; i < job->Requirements().CountStrings(); i++)
			info.AddString("requires", job->Requirements().StringAt(i));

		PortMap::const_iterator iterator = job->Ports().begin();
		for (; iterator != job->Ports().end(); iterator++)
			info.AddMessage("port", &iterator->second);
	}
	message->SendReply(&info);
}
コード例 #2
0
ファイル: Job.cpp プロジェクト: jessicah/haiku-private
Job::Job(const Job& other)
    :
    BaseJob(other.Name()),
    fEnabled(other.IsEnabled()),
    fService(other.IsService()),
    fCreateDefaultPort(other.CreateDefaultPort()),
    fLaunching(other.IsLaunching()),
    fInitStatus(B_NO_INIT),
    fTeam(-1),
    fDefaultPort(-1),
    fToken((uint32)B_PREFERRED_TOKEN),
    fLaunchStatus(B_NO_INIT),
    fTarget(other.Target()),
    fPendingLaunchDataReplies(0, false)
{
    mutex_init(&fLaunchStatusLock, "launch status lock");

    fCondition = other.fCondition;
    // TODO: copy events
    //fEvent = other.fEvent;
    fEnvironment = other.fEnvironment;
    fSourceFiles = other.fSourceFiles;

    for (int32 i = 0; i < other.Arguments().CountStrings(); i++)
        AddArgument(other.Arguments().StringAt(i));

    for (int32 i = 0; i < other.Requirements().CountStrings(); i++)
        AddRequirement(other.Requirements().StringAt(i));

    PortMap::const_iterator constIterator = other.Ports().begin();
    for (; constIterator != other.Ports().end(); constIterator++) {
        fPortMap.insert(
            std::make_pair(constIterator->first, constIterator->second));
    }

    PortMap::iterator iterator = fPortMap.begin();
    for (; iterator != fPortMap.end(); iterator++)
        iterator->second.RemoveData("port");
}
コード例 #3
0
ファイル: LaunchDaemon.cpp プロジェクト: puckipedia/haiku
void
LaunchDaemon::_HandleGetLaunchData(BMessage* message)
{
	uid_t user = _GetUserID(message);
	if (user < 0)
		return;

	BMessage reply((uint32)B_OK);
	bool launchJob = true;

	Job* job = FindJob(get_leaf(message->GetString("name")));
	if (job == NULL) {
		Session* session = FindSession(user);
		if (session != NULL) {
			// Forward request to user launch_daemon
			if (session->Daemon().SendMessage(message) == B_OK)
				return;
		}
		reply.what = B_NAME_NOT_FOUND;
	} else if (!job->IsLaunched()) {
		if (job->InitCheck() == B_NO_INIT || !job->CheckCondition(*this)) {
			// The job exists, but cannot be started yet, as its
			// conditions are not met; don't make it available yet
			// TODO: we may not want to initialize jobs with conditions
			// that aren't met yet
			reply.what = B_NO_INIT;
		} else if (job->Event() != NULL) {
			if (!Events::TriggerDemand(job->Event())) {
				// The job is not triggered by demand; we cannot start it now
				reply.what = B_NO_INIT;
			} else {
				// The job has already been triggered, don't launch it again
				launchJob = false;
			}
		}
	}

	if (reply.what == B_OK) {
		// If the job has not been launched yet, we'll pass on our
		// team here. The rationale behind this is that this team
		// will temporarily own the synchronous reply ports.
		reply.AddInt32("team", job->Team() < 0
			? current_team() : job->Team());

		PortMap::const_iterator iterator = job->Ports().begin();
		for (; iterator != job->Ports().end(); iterator++) {
			BString name;
			if (iterator->second.HasString("name"))
				name << iterator->second.GetString("name") << "_";
			name << "port";

			reply.AddInt32(name.String(),
				iterator->second.GetInt32("port", -1));
		}

		// Launch the job if it hasn't been launched already
		if (launchJob)
			_LaunchJob(job);
	}
	message->SendReply(&reply);
}