From: Davin McCall Date: Sun, 6 Oct 2019 01:58:38 +0000 (+0100) Subject: dinitcheck: process all dependencies X-Git-Tag: v0.8.0~37 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6109e099052c4e96b45ee1b4624b092450de61f0;p=oweals%2Fdinit.git dinitcheck: process all dependencies --- diff --git a/src/dinitcheck.cc b/src/dinitcheck.cc index 2865e17..9f7d761 100644 --- a/src/dinitcheck.cc +++ b/src/dinitcheck.cc @@ -1,3 +1,4 @@ +#include #include #include #include @@ -25,7 +26,7 @@ using string_iterator = std::string::iterator; static const char *user_home_path = nullptr; // Get user home (and set user_home_path). (The return may become invalid after -// changing the evironment (HOME variable) or using the getpwuid() function). +// changing the environment (HOME variable) or using the getpwuid() function). static const char * get_user_home() { if (user_home_path == nullptr) { @@ -42,10 +43,10 @@ static const char * get_user_home() class prelim_dep { + public: std::string name; dependency_type dep_type; - public: prelim_dep(std::string &name_p, dependency_type dep_type_p) : name(name_p), dep_type(dep_type_p) { } prelim_dep(std::string &&name_p, dependency_type dep_type_p) @@ -67,6 +68,12 @@ using service_set_t = std::map; service_record *load_service(service_set_t &services, const std::string &name, const std::vector &service_dirs); +// Add some missing standard library functionality... +template bool contains(std::vector vec, const T& elem) +{ + return std::find(vec.begin(), vec.end(), elem) != vec.end(); +} + int main(int argc, char **argv) { using namespace std; @@ -123,13 +130,22 @@ int main(int argc, char **argv) for (const auto &name : services_to_check) { try { - load_service(service_set, name, service_dirs); + service_record *sr = load_service(service_set, name, service_dirs); + service_set[name] = sr; + // add dependencies to services_to_check + for (auto &dep : sr->dependencies) { + if (service_set.count(dep.name) == 0 && !contains(services_to_check, dep.name)) { + services_to_check.push_back(dep.name); + } + } } catch (service_load_exc &exc) { std::cerr << "Unable to load service '" << name << "': " << exc.exc_description << "\n"; } } + // check for circular dependencies + return 0; }