diff --git a/cmd/ifquery.c b/cmd/ifquery.c index 855cbb0..fb91883 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -290,7 +290,7 @@ ifquery_main(int argc, char *argv[]) return EXIT_FAILURE; } - if (!lif_lifecycle_count_rdepends(&exec_opts, &collection)) + if (lif_lifecycle_count_rdepends(&exec_opts, &collection) == -1) { fprintf(stderr, "%s: could not validate dependency tree\n", argv0); return EXIT_FAILURE; diff --git a/cmd/ifupdown.c b/cmd/ifupdown.c index 18bf8eb..0b09d67 100644 --- a/cmd/ifupdown.c +++ b/cmd/ifupdown.c @@ -229,7 +229,7 @@ ifupdown_main(int argc, char *argv[]) return EXIT_FAILURE; } - if (!lif_lifecycle_count_rdepends(&exec_opts, &collection)) + if (lif_lifecycle_count_rdepends(&exec_opts, &collection) == -1) { fprintf(stderr, "%s: could not validate dependency tree\n", argv0); return EXIT_FAILURE; diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index 7f0b032..87e0d0a 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -419,7 +419,7 @@ count_interface_rdepends(const struct lif_execute_opts *opts, struct lif_dict *c return true; } -bool +ssize_t lif_lifecycle_count_rdepends(const struct lif_execute_opts *opts, struct lif_dict *collection) { struct lif_node *iter; @@ -435,9 +435,21 @@ lif_lifecycle_count_rdepends(const struct lif_execute_opts *opts, struct lif_dic if (!count_interface_rdepends(opts, collection, iface, iface->rdepends_count)) { fprintf(stderr, "ifupdown: dependency graph is broken for interface %s\n", iface->ifname); - return false; + return -1; } } - return true; + /* figure out the max depth */ + size_t maxdepth = 0; + + LIF_DICT_FOREACH(iter, collection) + { + struct lif_dict_entry *entry = iter->data; + struct lif_interface *iface = entry->data; + + if (iface->rdepends_count > maxdepth) + maxdepth = iface->rdepends_count; + } + + return maxdepth; } diff --git a/libifupdown/lifecycle.h b/libifupdown/lifecycle.h index 1dcf2e9..fecf9fe 100644 --- a/libifupdown/lifecycle.h +++ b/libifupdown/lifecycle.h @@ -22,7 +22,7 @@ extern bool lif_lifecycle_query_dependents(const struct lif_execute_opts *opts, struct lif_interface *iface, const char *lifname); extern bool lif_lifecycle_run_phase(const struct lif_execute_opts *opts, struct lif_interface *iface, const char *phase, const char *lifname, bool up); extern bool lif_lifecycle_run(const struct lif_execute_opts *opts, struct lif_interface *iface, struct lif_dict *collection, struct lif_dict *state, const char *lifname, bool up); -extern bool lif_lifecycle_count_rdepends(const struct lif_execute_opts *opts, struct lif_dict *collection); +extern ssize_t lif_lifecycle_count_rdepends(const struct lif_execute_opts *opts, struct lif_dict *collection); #endif