Skip to content

Commit

Permalink
dinitctl: reference settings via symbolic ids rather than strings
Browse files Browse the repository at this point in the history
  • Loading branch information
davmac314 committed Dec 13, 2024
1 parent abc52d0 commit faf75d7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/dinitctl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1972,10 +1972,18 @@ static int enable_disable_service(int socknum, cpbuffer_t &rbuffer, service_dir_
return (char *)nullptr; // FIXME
};

auto is_setting = [](const std::string &setting, dinit_load::setting_id_t setting_id) {
return (setting == dinit_load::all_settings[(size_t)setting_id].setting_str);
};

process_service_file(from, input_stack, [&](string &line, file_pos_ref fpr,
string &setting, dinit_load::setting_op_t op,
dinit_load::string_iterator i, dinit_load::string_iterator end) -> void {
if (setting == "waits-for" || setting == "depends-on" || setting == "depends-ms") {
using namespace dinit_load;

if (is_setting(setting, setting_id_t::WAITS_FOR)
|| is_setting(setting, setting_id_t::DEPENDS_ON)
|| is_setting(setting, setting_id_t::DEPENDS_MS)) {
string dname = dinit_load::read_setting_value(fpr, i, end);
if (dname == to) {
// There is already a dependency
Expand All @@ -1984,7 +1992,7 @@ static int enable_disable_service(int socknum, cpbuffer_t &rbuffer, service_dir_
throw service_op_cancel();
}
}
else if (setting == "waits-for.d") {
else if (is_setting(setting, setting_id_t::WAITS_FOR_D)) {
string dname = dinit_load::read_setting_value(fpr, i, end);
if (! waits_for_d.empty()) {
cerr << "dinitctl: service '" << from << "' has multiple waits-for.d directories "
Expand Down

0 comments on commit faf75d7

Please sign in to comment.