Beispiel #1
0
/*!	Initializes all jobs for the specified target (may be \c NULL).
	Jobs that cannot be initialized, and those that never will be due to
	conditions, will be removed from the list.
*/
void
LaunchDaemon::_InitJobs(Target* target)
{
	for (JobMap::iterator iterator = fJobs.begin(); iterator != fJobs.end();) {
		Job* job = iterator->second;
		JobMap::iterator remove = iterator++;

		if (job->Target() != target)
			continue;

		status_t status = B_NO_INIT;
		if (job->IsEnabled()) {
			// Filter out jobs that have a constant and failing condition
			if (job->Condition() == NULL || !job->Condition()->IsConstant(*this)
				|| job->Condition()->Test(*this)) {
				std::set<BString> dependencies;
				status = job->Init(*this, dependencies);
				if (status == B_OK && job->Event() != NULL)
					status = job->Event()->Register(*this);
			}
		}

		if (status != B_OK) {
			if (status != B_NO_INIT) {
				// TODO: log error
				debug_printf("Init \"%s\" failed: %s\n", job->Name(),
					strerror(status));
			}

			// Remove jobs that won't be used later on
			fJobs.erase(remove);
			delete job;
		}
	}
}
Beispiel #2
0
void
LaunchDaemon::_AddJob(Target* target, bool service, BMessage& message)
{
	BString name = message.GetString("name");
	if (name.IsEmpty()) {
		// Invalid job description
		return;
	}
	name.ToLower();

	Job* job = FindJob(name);
	if (job == NULL) {
		job = new (std::nothrow) Job(name);
		if (job == NULL)
			return;

		job->SetService(service);
		job->SetCreateDefaultPort(service);
		job->SetTarget(target);
	}

	if (message.HasBool("disabled"))
		job->SetEnabled(!message.GetBool("disabled", !job->IsEnabled()));

	if (message.HasBool("legacy"))
		job->SetCreateDefaultPort(!message.GetBool("legacy", !service));

	_SetCondition(job, message);
	_SetEvent(job, message);
	_SetEnvironment(job, message);

	BMessage portMessage;
	for (int32 index = 0;
			message.FindMessage("port", index, &portMessage) == B_OK; index++) {
		job->AddPort(portMessage);
	}

	if (message.HasString("launch")) {
		job->Arguments().MakeEmpty();

		const char* argument;
		for (int32 index = 0; message.FindString("launch", index, &argument)
				== B_OK; index++) {
			job->AddArgument(argument);
		}
	}

	const char* requirement;
	for (int32 index = 0;
			message.FindString("requires", index, &requirement) == B_OK;
			index++) {
		job->AddRequirement(requirement);
	}
	if (fInitTarget != NULL)
		job->AddRequirement(fInitTarget->Name());

	fJobs.insert(std::make_pair(job->Title(), job));
}
Beispiel #3
0
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);
}
Beispiel #4
0
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");
}