From 158c63eb2cd0eaee977f2a535f6e6b74a3abff2e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 9 Dec 2015 10:29:15 +0100 Subject: [PATCH] device: move initialization of ifindex to constructor() Device subclasses (for example NMDeviceWifi) can use the ifindex in their constructor(), but the value now is set later in parent class constructed(). This causes the following: nm_platform_wifi_get_capabilities: assertion 'ifindex > 0' failed Fix this by initializing ifindex earlier in NMDevice's constructor(). While at it, remove the nm_assert (pllink->type != NM_LINK_TYPE_NONE); assertion, since pllink can be NULL there. Fixes: 6db04dc20664479fc71f102a536dbf2f4501c5a2 --- src/devices/nm-device.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3a4e7cc946..21f5a194a9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10081,20 +10081,27 @@ nm_device_init (NMDevice *self) priv->v6_commit_first_time = TRUE; } -static void -constructed (GObject *object) +static GObject* +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) { - NMDevice *self = NM_DEVICE (object); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMPlatform *platform; + GObject *object; + GObjectClass *klass; + NMDevice *self; + NMDevicePrivate *priv; const NMPlatformLink *pllink; - platform = nm_platform_get (); + klass = G_OBJECT_CLASS (nm_device_parent_class); + object = klass->constructor (type, n_construct_params, construct_params); + if (!object) + return NULL; + + self = NM_DEVICE (object); + priv = NM_DEVICE_GET_PRIVATE (self); if (priv->iface) { - pllink = nm_platform_link_get_by_ifname (platform, priv->iface); - - nm_assert (pllink->type != NM_LINK_TYPE_NONE); + pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); if (pllink && link_type_compatible (self, pllink->type, NULL, NULL)) { priv->ifindex = pllink->ifindex; @@ -10102,6 +10109,18 @@ constructed (GObject *object) } } + return object; +} + +static void +constructed (GObject *object) +{ + NMDevice *self = NM_DEVICE (object); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMPlatform *platform; + + platform = nm_platform_get (); + if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities) priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self); @@ -10524,6 +10543,7 @@ nm_device_class_init (NMDeviceClass *klass) object_class->finalize = finalize; object_class->set_property = set_property; object_class->get_property = get_property; + object_class->constructor = constructor; object_class->constructed = constructed; klass->link_changed = link_changed;