-static bool all_configured(Manager *m) {
- _cleanup_free_ unsigned *indices = NULL;
- char **ifname;
- bool one_ready = false;
- int r, n, i;
-
- n = sd_network_get_ifindices(&indices);
- if (n <= 0)
- return false;
-
- /* wait for networkd to be aware of all the links given on the commandline */
- STRV_FOREACH(ifname, arg_interfaces) {
- _cleanup_rtnl_message_unref_ sd_rtnl_message *message = NULL, *reply = NULL;
- bool found = false;
- int index;
-
- r = sd_rtnl_message_new_link(m->rtnl, &message, RTM_GETLINK, 0);
- if (r < 0) {
- log_warning("colud not create GETLINK message: %s", strerror(-r));
- return false;
- }
-
- r = sd_rtnl_message_append_string(message, IFLA_IFNAME, *ifname);
- if (r < 0) {
- log_warning("could not attach ifname to GETLINK message: %s", strerror(-r));
- return false;
- }
-
- r = sd_rtnl_call(m->rtnl, message, 0, &reply);
- if (r < 0) {
- if (r != -ENODEV)
- log_warning("could not get link info for %s: %s", *ifname,
- strerror(-r));
-
- /* link does not yet exist */
- return false;
- }
-
- r = sd_rtnl_message_link_get_ifindex(reply, &index);
- if (r < 0) {
- log_warning("could not get ifindex: %s", strerror(-r));
- return false;
- }
-
- if (index <= 0) {
- log_warning("invalid ifindex %d for %s", index, *ifname);
- return false;
- }
-
- for (i = 0; i < n; i++) {
- if (indices[i] == (unsigned) index) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- /* link exists, but networkd is not yet aware of it */
- return false;
- }
- }
-
- /* wait for all links networkd manages to be in admin state 'configured'
- and at least one link to gain a carrier */
- for (i = 0; i < n; i++) {
- _cleanup_free_ char *state = NULL, *oper_state = NULL;
-
- if (sd_network_link_is_loopback(indices[i]))
- /* ignore loopback devices */
- continue;
-
- r = sd_network_get_link_state(indices[i], &state);
- if (r != -EUNATCH && (r < 0 || !streq(state, "configured"))) {
- /* managed by networkd, but not yet configured */
- return false;
- }
-
- r = sd_network_get_link_operational_state(indices[i], &oper_state);
- if (r >= 0 && streq(oper_state, "carrier"))
- /* we wait for at least one link to be ready,
- regardless of who manages it */
- one_ready = true;
- }
-
- return one_ready;
-}
-
-static int monitor_event_handler(sd_event_source *s, int fd, uint32_t revents,
- void *userdata) {
- Manager *m = userdata;
-
- assert(m);
- assert(m->event);
-
- if (all_configured(m))
- sd_event_exit(m->event, 0);
-
- return 1;
-}
-
-void manager_free(Manager *m) {
- if (!m)
- return;
-
- sd_event_unref(m->event);
- sd_rtnl_unref(m->rtnl);
-
- free(m);
-}
-