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)); }
void LaunchDaemon::_HandleLaunchTarget(BMessage* message) { uid_t user = _GetUserID(message); if (user < 0) return; const char* name = message->GetString("target"); const char* baseName = message->GetString("base target"); Target* target = FindTarget(name); if (target == NULL && baseName != NULL) { Target* baseTarget = FindTarget(baseName); if (baseTarget != NULL) { target = new Target(name); // Copy all jobs with the base target into the new target for (JobMap::iterator iterator = fJobs.begin(); iterator != fJobs.end();) { Job* job = iterator->second; iterator++; if (job->Target() == baseTarget) { Job* copy = new Job(*job); copy->SetTarget(target); fJobs.insert(std::make_pair(copy->Name(), copy)); } } } } if (target == NULL) { Session* session = FindSession(user); if (session != NULL) { // Forward request to user launch_daemon if (session->Daemon().SendMessage(message) == B_OK) return; } BMessage reply(B_NAME_NOT_FOUND); message->SendReply(&reply); return; } BMessage data; if (message->FindMessage("data", &data) == B_OK) target->AddData(data.GetString("name"), data); _LaunchJobs(target); }