launch_daemon: Improved job overwriting.
* Certain things are set on job construction only. * Now checks if the message has the field before updating it. * Might not be final yet (it is confusing that 'requires' will add to the requirements, but 'launch' will replace all arguments).
This commit is contained in:
@@ -37,8 +37,15 @@ BaseJob::Condition() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
::Condition*
|
||||||
|
BaseJob::Condition()
|
||||||
|
{
|
||||||
|
return fCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BaseJob::SetCondition(const ::Condition* condition)
|
BaseJob::SetCondition(::Condition* condition)
|
||||||
{
|
{
|
||||||
fCondition = condition;
|
fCondition = condition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ public:
|
|||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
const ::Condition* Condition() const;
|
const ::Condition* Condition() const;
|
||||||
void SetCondition(const ::Condition* condition);
|
::Condition* Condition();
|
||||||
|
void SetCondition(::Condition* condition);
|
||||||
bool CheckCondition(ConditionContext& context) const;
|
bool CheckCondition(ConditionContext& context) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const ::Condition* fCondition;
|
::Condition* fCondition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -583,26 +583,39 @@ LaunchDaemon::_AddJob(Target* target, bool service, BMessage& message)
|
|||||||
name.ToLower();
|
name.ToLower();
|
||||||
|
|
||||||
Job* job = FindJob(name);
|
Job* job = FindJob(name);
|
||||||
if (job == NULL)
|
if (job == NULL) {
|
||||||
job = new Job(name);
|
job = new (std::nothrow) Job(name);
|
||||||
|
if (job == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
job->SetEnabled(!message.GetBool("disabled", !job->IsEnabled()));
|
job->SetService(service);
|
||||||
job->SetService(service);
|
job->SetCreateDefaultPort(service);
|
||||||
job->SetCreateDefaultPort(!message.GetBool("legacy", !service));
|
job->SetTarget(target);
|
||||||
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);
|
_SetCondition(job, message);
|
||||||
|
|
||||||
|
|
||||||
BMessage portMessage;
|
BMessage portMessage;
|
||||||
for (int32 index = 0;
|
for (int32 index = 0;
|
||||||
message.FindMessage("port", index, &portMessage) == B_OK; index++) {
|
message.FindMessage("port", index, &portMessage) == B_OK; index++) {
|
||||||
job->AddPort(portMessage);
|
job->AddPort(portMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* argument;
|
if (message.HasString("launch")) {
|
||||||
for (int32 index = 0;
|
job->Arguments().MakeEmpty();
|
||||||
message.FindString("launch", index, &argument) == B_OK; index++) {
|
|
||||||
job->AddArgument(argument);
|
const char* argument;
|
||||||
|
for (int32 index = 0; message.FindString("launch", index, &argument)
|
||||||
|
== B_OK; index++) {
|
||||||
|
job->AddArgument(argument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* requirement;
|
const char* requirement;
|
||||||
@@ -683,16 +696,21 @@ LaunchDaemon::_AddTarget(Target* target)
|
|||||||
void
|
void
|
||||||
LaunchDaemon::_SetCondition(BaseJob* job, const BMessage& message)
|
LaunchDaemon::_SetCondition(BaseJob* job, const BMessage& message)
|
||||||
{
|
{
|
||||||
Condition* condition = NULL;
|
Condition* condition = job->Condition();
|
||||||
|
bool updated = false;
|
||||||
|
|
||||||
BMessage conditions;
|
BMessage conditions;
|
||||||
if (message.FindMessage("if", &conditions) == B_OK)
|
if (message.FindMessage("if", &conditions) == B_OK) {
|
||||||
condition = Conditions::FromMessage(conditions);
|
condition = Conditions::FromMessage(conditions);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.GetBool("no_safemode"))
|
if (message.GetBool("no_safemode")) {
|
||||||
condition = Conditions::AddNotSafeMode(condition);
|
condition = Conditions::AddNotSafeMode(condition);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (condition != NULL)
|
if (updated)
|
||||||
job->SetCondition(condition);
|
job->SetCondition(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user