FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 01-10-2011, 01:21 PM
Radek Vykydal
 
Default Wait for activation of specific devices instead of NM (#638131)

---
isys/iface.c | 29 +++++++++++++++++++++++++++
isys/iface.h | 2 +
loader/net.c | 62 ++++++++++++++++++++++++++++++++++++++++-----------------
loader/net.h | 3 +-
4 files changed, 76 insertions(+), 20 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 ee370ac..469f798 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->device);
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, _("
This cannot be corrected in cmdline mode.
"
"Halting.
"));
@@ -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->device);
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;
@@ -2026,6 +2026,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;
@@ -2106,29 +2111,32 @@ 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(char *ifname) {
+ int count = 0, i;
NMClient *client = NULL;
NMState state;
GMainLoop *loop;
GMainContext *ctx;
+ const GPtrArray *devices;
+ NMDevice *device = NULL;

- if (iface == NULL) {
+ if (ifname == NULL) {
return 1;
}

- logMessage(DEBUGLVL, "configuring device %s", iface->device);
+ logMessage(DEBUGLVL, "activating device %s", ifname);

/* display status */
if (FL_CMDLINE(flags)) {
- printf(_("Waiting for NetworkManager to configure %s.
"),
- iface->device);
+ printf(_("Waiting for NetworkManager to activate %s.
"),
+ ifname);
} else {
winStatus(55, 3, NULL,
- _("Waiting for NetworkManager to configure %s.
"),
- iface->device, 0);
+ _("Waiting for NetworkManager to activate %s.
"),
+ ifname, 0);
}

g_type_init();
@@ -2140,6 +2148,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 *name = nm_device_get_iface(candidate);
+ if (!strcmp(name, ifname)) {
+ device = candidate;
+ break;
+ }
+ }
+ if (device == NULL) {
+ logMessage(ERROR, "%s (%d): network device %s not found",
+ __func__, __LINE__, ifname);
+ 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);
@@ -2155,12 +2179,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__, ifname);
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..b5769a5 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -76,6 +76,7 @@ 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(char * ifname);
+int wait_for_iface_disconnection(char *ifname);

#endif
--
1.7.2

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

Thread Tools




All times are GMT. The time now is 10:57 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org