[PATCH 4/9] Wait for activation of specific devices instead of NM (#638131)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 isys/iface.c |   29 +++++++++++++++++++++++++++++
 isys/iface.h |    2 ++
 loader/net.c |   56 ++++++++++++++++++++++++++++++++++++++++----------------
 loader/net.h |    2 +-
 4 files changed, 72 insertions(+), 17 deletions(-)

diff --git a/isys/iface.c b/isys/iface.c
index bc88725..ad39447 100644
--- a/isys/iface.c
+++ b/isys/iface.c
@@ -441,6 +441,35 @@ gboolean is_nm_running(void) {
     return running;
 }
 
+gboolean is_iface_activated(char * ifname) {
+    int i, state;
+    NMClient *client = NULL;
+    const GPtrArray *devices;
+
+    g_type_init();
+
+    client = nm_client_new();
+    if (!client)
+        return FALSE;
+
+    devices = nm_client_get_devices(client);
+    for (i = 0; i < devices->len; i++) {
+        NMDevice *candidate = g_ptr_array_index(devices, i);
+        const char *devname = nm_device_get_iface(candidate);
+        if (strcmp(ifname, devname))
+            continue;
+        state = nm_device_get_state(candidate);
+        g_object_unref(client);
+        if (state == NM_DEVICE_STATE_ACTIVATED)
+            return TRUE;
+        else
+            return FALSE;
+    }
+
+    g_object_unref(client);
+    return FALSE;
+}
+
 /*
  * Wait for NetworkManager to appear on the system bus
  */
diff --git a/isys/iface.h b/isys/iface.h
index 31dde19..8f90271 100644
--- a/isys/iface.h
+++ b/isys/iface.h
@@ -152,6 +152,8 @@ int iface_have_in6_addr(struct in6_addr *addr6);
  */
 gboolean is_nm_connected(void);
 
+gboolean is_iface_activated(char * ifname);
+
 /*
  * Start NetworkManager
  */
diff --git a/loader/net.c b/loader/net.c
index bacedbe..3b7e966 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -482,12 +482,12 @@ int readNetConfig(char * device, iface_t * iface,
             return LOADER_BACK;
         }
 
-        i = get_connection(iface);
+        i = wait_for_iface_activation(iface);
         newtPopWindow();
 
         if (i > 0) {
             if (FL_CMDLINE(flags)) {
-                fprintf(stderr, _("There was an error configuring your network "
+                fprintf(stderr, _("There was an error activating your network "
                                   "interface."));
                 fprintf(stderr, _("\nThis cannot be corrected in cmdline mode.\n"
                                   "Halting.\n"));
@@ -495,7 +495,7 @@ int readNetConfig(char * device, iface_t * iface,
             }
 
             newtWinMessage(_("Network Error"), _("Retry"),
-                           _("There was an error configuring your network "
+                           _("There was an error activating your network "
                              "interface."));
             return LOADER_BACK;
         }
@@ -545,12 +545,12 @@ int readNetConfig(char * device, iface_t * iface,
         return LOADER_BACK;
     }
 
-    i = get_connection(iface);
+    i = wait_for_iface_activation(iface);
     newtPopWindow();
 
     if (i > 0) {
         newtWinMessage(_("Network Error"), _("Retry"),
-                       _("There was an error configuring your network "
+                       _("There was an error activating your network "
                          "interface."));
         iface->ipv4method = IPV4_UNUSED_METHOD;
         iface->ipv6method = IPV6_UNUSED_METHOD;
@@ -2017,6 +2017,11 @@ int activateDevice(struct loaderData_s * loaderData, iface_t * iface) {
             break;
         } while (1);
 
+        if (is_iface_activated(iface->device)) {
+            logMessage(INFO, "device %s is already activated", iface->device);
+            return 0;
+        }
+
         /* we don't want to end up asking about interface more than once
          * if we're in a kickstart-ish case (#100724) */
         loaderData->netDev_set = 1;
@@ -2097,28 +2102,31 @@ void splitHostname (char *str, char **host, char **port)
 }
 
 /*
- * Start NetworkManager and wait for a valid link, return non-zero on error.
+ * Wait for activation of iface by NetworkManager, return non-zero on error.
+ * If iface == NULL wait for any device.
  */
-int get_connection(iface_t *iface) {
-    int count = 0;
+int wait_for_iface_activation(iface_t *iface) {
+    int count = 0, i;
     NMClient *client = NULL;
     NMState state;
     GMainLoop *loop;
     GMainContext *ctx;
+    const GPtrArray *devices;
+    NMDevice *device = NULL;
 
     if (iface == NULL) {
         return 1;
     }
 
-    logMessage(DEBUGLVL, "configuring device %s", iface->device);
+    logMessage(DEBUGLVL, "activating device %s", iface->device);
 
     /* display status */
     if (FL_CMDLINE(flags)) {
-        printf(_("Waiting for NetworkManager to configure %s.\n"),
+        printf(_("Waiting for NetworkManager to activate %s.\n"),
                iface->device);
     } else {
         winStatus(55, 3, NULL,
-                  _("Waiting for NetworkManager to configure %s.\n"),
+                  _("Waiting for NetworkManager to activate %s.\n"),
                   iface->device, 0);
     }
 
@@ -2131,6 +2139,22 @@ int get_connection(iface_t *iface) {
         return 2;
     }
 
+    devices = nm_client_get_devices(client);
+    for (i = 0; i < devices->len; i++) {
+        NMDevice *candidate = g_ptr_array_index(devices, i);
+        const char *devname = nm_device_get_iface(candidate);
+        if (!strcmp(iface->device, devname)) {
+            device = candidate;
+            break;
+        }
+    }
+    if (device == NULL) {
+        logMessage(ERROR, "%s (%d): network device %s not found",
+                   __func__, __LINE__, iface->device);
+        g_object_unref(client);
+        return 3;
+    }
+
     /* Create a loop for processing dbus signals */
     loop = g_main_loop_new(NULL, FALSE);
     ctx = g_main_loop_get_context(loop);
@@ -2146,12 +2170,12 @@ int get_connection(iface_t *iface) {
         while (g_main_context_pending (ctx)) {
             g_main_context_iteration (ctx, FALSE);
         }
-        state = nm_client_get_state(client);
-
-        if (state == NM_STATE_CONNECTED) {
-            logMessage(INFO, "%s (%d): NetworkManager connected",
-                       __func__, __LINE__);
+        state = nm_device_get_state(device);
+        if (state == NM_DEVICE_STATE_ACTIVATED) {
+            logMessage(INFO, "%s (%d): device %s activated",
+                       __func__, __LINE__, iface->device);
             res_init();
+            g_main_loop_unref(loop);
             g_object_unref(client);
             return 0;
         }
diff --git a/loader/net.h b/loader/net.h
index d2cd57c..ca9c0a9 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -76,6 +76,6 @@ int kickstartNetworkUp(struct loaderData_s * loaderData,
 int activateDevice(struct loaderData_s * loaderData,
                        iface_t * iface);
 void splitHostname (char *str, char **host, char **port);
-int get_connection(iface_t * iface);
+int wait_for_iface_activation(iface_t * iface);
 
 #endif
-- 
1.7.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux