chiark / gitweb /
networkd: netdev - verify name of newlink messages
[elogind.git] / src / network / networkd-wait-online.c
index 900dc05125a800e9be402993205c4034d66f08c8..e62859e1cf9c8b229204a2e853329173026f7c0e 100644 (file)
 ***/
 
 #include "sd-event.h"
+#include "event-util.h"
 #include "sd-daemon.h"
 #include "sd-network.h"
+#include "network-util.h"
 
 #include "util.h"
 
@@ -38,20 +40,15 @@ static bool all_configured(void) {
                 _cleanup_free_ char *state = NULL;
 
                 r = sd_network_get_link_state(indices[i], &state);
-                if (r < 0)
+                if (r == -EUNATCH)
+                        continue;
+                if (r < 0 || !streq(state, "configured"))
                         return false;
 
-                if (streq(state, "configured"))
-                        one_ready = true;
-
-                if (!streq(state, "configured") && !streq(state, "unmanaged"))
-                        return false;
+                one_ready = true;
         }
 
-        if (one_ready)
-                return true;
-
-        return false;
+        return one_ready;
 }
 
 static int event_handler(sd_event_source *s, int fd, uint32_t revents,
@@ -67,9 +64,9 @@ static int event_handler(sd_event_source *s, int fd, uint32_t revents,
 }
 
 int main(int argc, char *argv[]) {
-        sd_event *event;
-        sd_event_source *event_source;
-        sd_network_monitor *monitor;
+        _cleanup_event_unref_ sd_event *event = NULL;
+        _cleanup_event_source_unref_ sd_event_source *event_source = NULL;
+        _cleanup_network_monitor_unref_ sd_network_monitor *monitor = NULL;
         int r, fd, events;
 
         log_set_target(LOG_TARGET_AUTO);
@@ -122,7 +119,7 @@ int main(int argc, char *argv[]) {
 
         sd_notify(false,
                   "READY=1\n"
-                  "STATUS=Waiting for network connecitons...");
+                  "STATUS=Waiting for network connections...");
 
         r = sd_event_loop(event);
         if (r < 0) {
@@ -134,9 +131,5 @@ out:
         sd_notify(false,
                   "STATUS=All interfaces configured...");
 
-        sd_event_source_unref(event_source);
-        sd_event_unref(event);
-        sd_network_monitor_unref(monitor);
-
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }