Skip to content

Commit

Permalink
launch_daemon: Added "setting" condition.
Browse files Browse the repository at this point in the history
* Moved the mail_daemon to the user startup, and start it only if
  enabled in the settings.
  • Loading branch information
axeld committed Nov 6, 2015
1 parent c2f71fa commit d8c0972
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
6 changes: 0 additions & 6 deletions data/launch/system
Expand Up @@ -43,12 +43,6 @@ service x-vnd.Haiku-midi_server {
on_demand
}

service x-vnd.Haiku-mail_daemon {
launch /system/servers/mail_daemon -E
no_safemode
legacy
}

service x-vnd.Haiku-net_server {
launch /system/servers/net_server
no_safemode
Expand Down
7 changes: 7 additions & 0 deletions data/launch/user
Expand Up @@ -16,6 +16,13 @@ target desktop {
}
}

service x-vnd.Haiku-mail_daemon {
launch /system/servers/mail_daemon -E
if setting ~/config/settings/Mail/new_mail_daemon DaemonAutoStarts
no_safemode
legacy
}

job user-bootscript {
launch /bin/sh ~/config/settings/boot/UserBootscript
}
Expand Down
82 changes: 82 additions & 0 deletions src/servers/launch/Conditions.cpp
Expand Up @@ -9,8 +9,10 @@
#include <stdio.h>

#include <Entry.h>
#include <File.h>
#include <ObjectList.h>
#include <Message.h>
#include <Path.h>
#include <StringList.h>

#include "NetworkWatcher.h"
Expand Down Expand Up @@ -112,6 +114,21 @@ class NetworkAvailableCondition : public Condition {
};


class SettingCondition : public Condition {
public:
SettingCondition(const BMessage& args);

virtual bool Test(ConditionContext& context) const;

virtual BString ToString() const;

private:
BPath fPath;
BString fField;
BString fValue;
};


static Condition*
create_condition(const char* name, const BMessage& args)
{
Expand All @@ -130,6 +147,8 @@ create_condition(const char* name, const BMessage& args)
return new FileExistsCondition(args);
if (strcmp(name, "network_available") == 0)
return new NetworkAvailableCondition();
if (strcmp(name, "setting") == 0)
return new SettingCondition(args);

return NULL;
}
Expand Down Expand Up @@ -481,6 +500,69 @@ NetworkAvailableCondition::ToString() const
}


// #pragma mark - setting


SettingCondition::SettingCondition(const BMessage& args)
{
fPath.SetTo(Utility::TranslatePath(args.GetString("args", 0, NULL)));
fField = args.GetString("args", 1, NULL);
fValue = args.GetString("args", 2, NULL);
}


bool
SettingCondition::Test(ConditionContext& context) const
{
BFile file(fPath.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK)
return false;

BMessage settings;
if (settings.Unflatten(&file) == B_OK) {
type_code type;
int32 count;
if (settings.GetInfo(fField, &type, &count) == B_OK) {
switch (type) {
case B_BOOL_TYPE:
{
bool value = settings.GetBool(fField);
bool expect = fValue.IsEmpty();
if (!expect) {
expect = fValue == "true" || fValue == "yes"
|| fValue == "on" || fValue == "1";
}
return value == expect;
}
case B_STRING_TYPE:
{
BString value = settings.GetString(fField);
if (fValue.IsEmpty() && !value.IsEmpty())
return true;

return fValue == value;
}
}
}
}
// TODO: check for driver settings, too?

return false;
}


BString
SettingCondition::ToString() const
{
BString string = "setting file ";
string << fPath.Path() << ", field " << fField;
if (!fValue.IsEmpty())
string << ", value " << fValue;

return string;
}


// #pragma mark -


Expand Down

0 comments on commit d8c0972

Please sign in to comment.