|
|
a85faa |
From db2e926da147c5bb67660e40d0b2ab4d8e6a7728 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Tue, 6 Sep 2016 10:56:32 +0200
|
|
|
a85faa |
Subject: [PATCH 01/11] logging: don't round subsecond part in logging
|
|
|
a85faa |
timestamp
|
|
|
a85faa |
|
|
|
a85faa |
tv.tv_usec is guaranteed to have less then 6 digits, however rounding it up
|
|
|
a85faa |
we might reach 1000000 and thus the value becomes mis-aligned. To round
|
|
|
a85faa |
correctly, we would have to carry over a potential overflow to the seconds.
|
|
|
a85faa |
But that seems too much effort for little gain. Just truncate the value.
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit c1b4b99a3c758f320c369a8daadb219eeb50ee83)
|
|
|
a85faa |
(cherry picked from commit 99e30bdf700220e98db76602645a9844360e3fab)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/nm-logging.c | 2 +-
|
|
|
a85faa |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/nm-logging.c b/src/nm-logging.c
|
|
|
a85faa |
index 3db8d20..6ecc160 100644
|
|
|
a85faa |
--- a/src/nm-logging.c
|
|
|
a85faa |
+++ b/src/nm-logging.c
|
|
|
a85faa |
@@ -512,7 +512,7 @@ _nm_log_impl (const char *file,
|
|
|
a85faa |
va_end (args);
|
|
|
a85faa |
|
|
|
a85faa |
g_get_current_time (&tv;;
|
|
|
a85faa |
- nm_sprintf_buf (s_buf_timestamp, " [%ld.%04ld]", tv.tv_sec, (tv.tv_usec + 50) / 100);
|
|
|
a85faa |
+ nm_sprintf_buf (s_buf_timestamp, " [%ld.%04ld]", tv.tv_sec, tv.tv_usec / 100);
|
|
|
a85faa |
|
|
|
a85faa |
switch (global.log_backend) {
|
|
|
a85faa |
#if SYSTEMD_JOURNAL
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From fdf9c355eb35a7de1919a53c09349296a395f72e Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 14:12:41 +0200
|
|
|
a85faa |
Subject: [PATCH 02/11] shared: add NM_MIN()/NM_MAX() macros to replace glib's
|
|
|
a85faa |
MIN()/MAX()
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit b2016fd2a52b82d45324526c965e7545d026cebe)
|
|
|
a85faa |
(cherry picked from commit 811aaead4ca6f2f815f49b7353fa7a88554dca42)
|
|
|
a85faa |
---
|
|
|
a85faa |
shared/nm-utils/nm-macros-internal.h | 44 ++++++++++++++++++++++++++++++++++++
|
|
|
a85faa |
1 file changed, 44 insertions(+)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
index c66cb53..2067dba 100644
|
|
|
a85faa |
--- a/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
+++ b/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
@@ -542,6 +542,50 @@ nm_strcmp_p_with_data (gconstpointer a, gconstpointer b, gpointer user_data)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
+/* Taken from systemd's UNIQ_T and UNIQ macros. */
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_UNIQ_T(x, uniq) G_PASTE(__unique_prefix_, G_PASTE(x, uniq))
|
|
|
a85faa |
+#define NM_UNIQ __COUNTER__
|
|
|
a85faa |
+
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
+/* glib's MIN()/MAX() macros don't have function-like behavior, in that they evaluate
|
|
|
a85faa |
+ * the argument possibly twice.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * Taken from systemd's MIN()/MAX() macros. */
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_MIN(a, b) __NM_MIN(NM_UNIQ, a, NM_UNIQ, b)
|
|
|
a85faa |
+#define __NM_MIN(aq, a, bq, b) \
|
|
|
a85faa |
+ ({ \
|
|
|
a85faa |
+ typeof (a) NM_UNIQ_T(A, aq) = (a); \
|
|
|
a85faa |
+ typeof (b) NM_UNIQ_T(B, bq) = (b); \
|
|
|
a85faa |
+ ((NM_UNIQ_T(A, aq) < NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \
|
|
|
a85faa |
+ })
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_MAX(a, b) __NM_MAX(NM_UNIQ, a, NM_UNIQ, b)
|
|
|
a85faa |
+#define __NM_MAX(aq, a, bq, b) \
|
|
|
a85faa |
+ ({ \
|
|
|
a85faa |
+ typeof (a) NM_UNIQ_T(A, aq) = (a); \
|
|
|
a85faa |
+ typeof (b) NM_UNIQ_T(B, bq) = (b); \
|
|
|
a85faa |
+ ((NM_UNIQ_T(A, aq) > NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \
|
|
|
a85faa |
+ })
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_CLAMP(x, low, high) __NM_CLAMP(NM_UNIQ, x, NM_UNIQ, low, NM_UNIQ, high)
|
|
|
a85faa |
+#define __NM_CLAMP(xq, x, lowq, low, highq, high) \
|
|
|
a85faa |
+ ({ \
|
|
|
a85faa |
+ typeof(x)NM_UNIQ_T(X,xq) = (x); \
|
|
|
a85faa |
+ typeof(low) NM_UNIQ_T(LOW,lowq) = (low); \
|
|
|
a85faa |
+ typeof(high) NM_UNIQ_T(HIGH,highq) = (high); \
|
|
|
a85faa |
+ \
|
|
|
a85faa |
+ ( (NM_UNIQ_T(X,xq) > NM_UNIQ_T(HIGH,highq)) \
|
|
|
a85faa |
+ ? NM_UNIQ_T(HIGH,highq) \
|
|
|
a85faa |
+ : (NM_UNIQ_T(X,xq) < NM_UNIQ_T(LOW,lowq)) \
|
|
|
a85faa |
+ ? NM_UNIQ_T(LOW,lowq) \
|
|
|
a85faa |
+ : NM_UNIQ_T(X,xq)); \
|
|
|
a85faa |
+ })
|
|
|
a85faa |
+
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
static inline guint
|
|
|
a85faa |
nm_encode_version (guint major, guint minor, guint micro) {
|
|
|
a85faa |
/* analog to the preprocessor macro NM_ENCODE_VERSION(). */
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 58ccecb75f8f367a25f1defadddb9826735a24d7 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 16:49:50 +0200
|
|
|
a85faa |
Subject: [PATCH 03/11] shared: add _NM_GET_PRIVATE() macro
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit 2cae9ba348ed6ea4d41ebd714d8c55f4d49feae9)
|
|
|
a85faa |
(cherry picked from commit 5bac57496c0ee458456f5cf68560263cea6c23de)
|
|
|
a85faa |
---
|
|
|
a85faa |
shared/nm-utils/nm-macros-internal.h | 18 ++++++++++++++++++
|
|
|
a85faa |
1 file changed, 18 insertions(+)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
index 2067dba..91970c3 100644
|
|
|
a85faa |
--- a/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
+++ b/shared/nm-utils/nm-macros-internal.h
|
|
|
a85faa |
@@ -372,6 +372,24 @@ _notify (obj_type *obj, _PropertyEnums prop) \
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
+#define __NM_GET_PRIVATE(self, type, is_check, result_cmd) \
|
|
|
a85faa |
+ ({ \
|
|
|
a85faa |
+ /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
+ * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
+ typeof (self) _self = (self); \
|
|
|
a85faa |
+ \
|
|
|
a85faa |
+ /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
+ _nm_unused const type *_self2 = (_self); \
|
|
|
a85faa |
+ \
|
|
|
a85faa |
+ nm_assert (is_check (_self)); \
|
|
|
a85faa |
+ ( result_cmd ); \
|
|
|
a85faa |
+ })
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define _NM_GET_PRIVATE(self, type, is_check) __NM_GET_PRIVATE(self, type, is_check, &_self->_priv)
|
|
|
a85faa |
+#define _NM_GET_PRIVATE_PTR(self, type, is_check) __NM_GET_PRIVATE(self, type, is_check, _self->_priv)
|
|
|
a85faa |
+
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
static inline gpointer
|
|
|
a85faa |
nm_g_object_ref (gpointer obj)
|
|
|
a85faa |
{
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From c6e898fea24c5e86a2a8b7b43fe5131f655d1c38 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 16:55:07 +0200
|
|
|
a85faa |
Subject: [PATCH 04/11] core: use _NM_GET_PRIVATE() macros
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit cdf6ad40572f23be6f8b6971bd57b1002ffb9aaf)
|
|
|
a85faa |
(cherry picked from commit 3940d63a7e6bff088bb3fb5e81c8cb2792b19b3a)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/devices/nm-device-ethernet.c | 13 +------------
|
|
|
a85faa |
src/devices/nm-device-veth.c | 13 +------------
|
|
|
a85faa |
src/devices/nm-device.c | 31 ++++++++++---------------------
|
|
|
a85faa |
src/devices/nm-device.h | 2 +-
|
|
|
a85faa |
src/devices/wifi/nm-device-wifi.c | 13 +------------
|
|
|
a85faa |
src/devices/wifi/nm-wifi-ap.c | 13 +------------
|
|
|
a85faa |
src/dns-manager/nm-dns-manager.c | 13 +------------
|
|
|
a85faa |
src/nm-auth-subject.c | 13 +------------
|
|
|
a85faa |
src/nm-checkpoint.c | 15 ++-------------
|
|
|
a85faa |
src/nm-ip4-config.c | 13 +------------
|
|
|
a85faa |
src/nm-ip6-config.c | 13 +------------
|
|
|
a85faa |
src/nm-manager.c | 15 ++-------------
|
|
|
a85faa |
src/rdisc/nm-lndp-rdisc.c | 13 +------------
|
|
|
a85faa |
src/rdisc/nm-rdisc.c | 13 +------------
|
|
|
a85faa |
src/vpn-manager/nm-vpn-connection.c | 13 +------------
|
|
|
a85faa |
15 files changed, 26 insertions(+), 180 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
|
|
|
a85faa |
index 90d472d..b213a0c 100644
|
|
|
a85faa |
--- a/src/devices/nm-device-ethernet.c
|
|
|
a85faa |
+++ b/src/devices/nm-device-ethernet.c
|
|
|
a85faa |
@@ -127,18 +127,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceEthernet,
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DEVICE_ETHERNET_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMDeviceEthernet *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_DEVICE_ETHERNET (_self)); \
|
|
|
a85faa |
- _self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_DEVICE_ETHERNET_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDeviceEthernet, NM_IS_DEVICE_ETHERNET)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c
|
|
|
a85faa |
index cca86fb..5692331 100644
|
|
|
a85faa |
--- a/src/devices/nm-device-veth.c
|
|
|
a85faa |
+++ b/src/devices/nm-device-veth.c
|
|
|
a85faa |
@@ -62,18 +62,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVeth,
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DEVICE_VETH_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMDeviceVeth *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_DEVICE_VETH (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_DEVICE_VETH_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceVeth, NM_IS_DEVICE_VETH)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
|
|
|
a85faa |
index 84246b7..240e590 100644
|
|
|
a85faa |
--- a/src/devices/nm-device.c
|
|
|
a85faa |
+++ b/src/devices/nm-device.c
|
|
|
a85faa |
@@ -75,18 +75,7 @@ _LOG_DECLARE_SELF (NMDevice);
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DEVICE_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMDevice *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_DEVICE (_self)); \
|
|
|
a85faa |
- _self->priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_DEVICE_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDevice, NM_IS_DEVICE)
|
|
|
a85faa |
|
|
|
a85faa |
enum {
|
|
|
a85faa |
STATE_CHANGED,
|
|
|
a85faa |
@@ -2029,7 +2018,7 @@ link_type_compatible (NMDevice *self,
|
|
|
a85faa |
return FALSE;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
- device_type = self->priv->link_type;
|
|
|
a85faa |
+ device_type = self->_priv->link_type;
|
|
|
a85faa |
if (device_type > NM_LINK_TYPE_UNKNOWN && device_type != link_type) {
|
|
|
a85faa |
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
a85faa |
"Needed link type 0x%x does not match the platform link type 0x%X",
|
|
|
a85faa |
@@ -10063,7 +10052,7 @@ nm_device_set_unmanaged_by_user_udev (NMDevice *self)
|
|
|
a85faa |
int ifindex;
|
|
|
a85faa |
gboolean platform_unmanaged = FALSE;
|
|
|
a85faa |
|
|
|
a85faa |
- ifindex = self->priv->ifindex;
|
|
|
a85faa |
+ ifindex = self->_priv->ifindex;
|
|
|
a85faa |
|
|
|
a85faa |
if ( ifindex <= 0
|
|
|
a85faa |
|| !nm_platform_link_get_unmanaged (NM_PLATFORM_GET, ifindex, &platform_unmanaged))
|
|
|
a85faa |
@@ -10150,7 +10139,7 @@ nm_device_reapply_settings_immediately (NMDevice *self)
|
|
|
a85faa |
if (g_strcmp0 ((zone = nm_setting_connection_get_zone (s_con_settings)),
|
|
|
a85faa |
nm_setting_connection_get_zone (s_con_applied)) != 0) {
|
|
|
a85faa |
|
|
|
a85faa |
- version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request);
|
|
|
a85faa |
+ version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->_priv->act_request);
|
|
|
a85faa |
_LOGD (LOGD_DEVICE, "reapply setting: zone = %s%s%s (version-id %llu)", NM_PRINT_FMT_QUOTE_STRING (zone), (long long unsigned) version_id);
|
|
|
a85faa |
|
|
|
a85faa |
g_object_set (G_OBJECT (s_con_applied),
|
|
|
a85faa |
@@ -10162,7 +10151,7 @@ nm_device_reapply_settings_immediately (NMDevice *self)
|
|
|
a85faa |
|
|
|
a85faa |
if ((metered = nm_setting_connection_get_metered (s_con_settings)) != nm_setting_connection_get_metered (s_con_applied)) {
|
|
|
a85faa |
|
|
|
a85faa |
- version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request);
|
|
|
a85faa |
+ version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->_priv->act_request);
|
|
|
a85faa |
_LOGD (LOGD_DEVICE, "reapply setting: metered = %d (version-id %llu)", (int) metered, (long long unsigned) version_id);
|
|
|
a85faa |
|
|
|
a85faa |
g_object_set (G_OBJECT (s_con_applied),
|
|
|
a85faa |
@@ -10341,22 +10330,22 @@ nm_device_check_connection_available (NMDevice *self,
|
|
|
a85faa |
static gboolean
|
|
|
a85faa |
available_connections_del_all (NMDevice *self)
|
|
|
a85faa |
{
|
|
|
a85faa |
- if (g_hash_table_size (self->priv->available_connections) == 0)
|
|
|
a85faa |
+ if (g_hash_table_size (self->_priv->available_connections) == 0)
|
|
|
a85faa |
return FALSE;
|
|
|
a85faa |
- g_hash_table_remove_all (self->priv->available_connections);
|
|
|
a85faa |
+ g_hash_table_remove_all (self->_priv->available_connections);
|
|
|
a85faa |
return TRUE;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static gboolean
|
|
|
a85faa |
available_connections_add (NMDevice *self, NMConnection *connection)
|
|
|
a85faa |
{
|
|
|
a85faa |
- return nm_g_hash_table_add (self->priv->available_connections, g_object_ref (connection));
|
|
|
a85faa |
+ return nm_g_hash_table_add (self->_priv->available_connections, g_object_ref (connection));
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static gboolean
|
|
|
a85faa |
available_connections_del (NMDevice *self, NMConnection *connection)
|
|
|
a85faa |
{
|
|
|
a85faa |
- return g_hash_table_remove (self->priv->available_connections, connection);
|
|
|
a85faa |
+ return g_hash_table_remove (self->_priv->available_connections, connection);
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static gboolean
|
|
|
a85faa |
@@ -12137,7 +12126,7 @@ nm_device_init (NMDevice *self)
|
|
|
a85faa |
|
|
|
a85faa |
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE, NMDevicePrivate);
|
|
|
a85faa |
|
|
|
a85faa |
- self->priv = priv;
|
|
|
a85faa |
+ self->_priv = priv;
|
|
|
a85faa |
|
|
|
a85faa |
priv->type = NM_DEVICE_TYPE_UNKNOWN;
|
|
|
a85faa |
priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
|
|
|
a85faa |
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
|
|
|
a85faa |
index 0f91b21..a757a37 100644
|
|
|
a85faa |
--- a/src/devices/nm-device.h
|
|
|
a85faa |
+++ b/src/devices/nm-device.h
|
|
|
a85faa |
@@ -125,7 +125,7 @@ struct _NMDevice {
|
|
|
a85faa |
NMExportedObject parent;
|
|
|
a85faa |
|
|
|
a85faa |
/* private */
|
|
|
a85faa |
- struct _NMDevicePrivate *priv;
|
|
|
a85faa |
+ struct _NMDevicePrivate *_priv;
|
|
|
a85faa |
};
|
|
|
a85faa |
|
|
|
a85faa |
/* The flags have an relaxing meaning, that means, specifying more flags, can make
|
|
|
a85faa |
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
|
|
|
a85faa |
index 49c380a..f97e668 100644
|
|
|
a85faa |
--- a/src/devices/wifi/nm-device-wifi.c
|
|
|
a85faa |
+++ b/src/devices/wifi/nm-device-wifi.c
|
|
|
a85faa |
@@ -138,18 +138,7 @@ struct _NMDeviceWifiClass
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DEVICE_WIFI_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMDeviceWifi *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_DEVICE_WIFI (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_DEVICE_WIFI_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWifi, NM_IS_DEVICE_WIFI)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c
|
|
|
a85faa |
index e1beb85..2232f82 100644
|
|
|
a85faa |
--- a/src/devices/wifi/nm-wifi-ap.c
|
|
|
a85faa |
+++ b/src/devices/wifi/nm-wifi-ap.c
|
|
|
a85faa |
@@ -68,18 +68,7 @@ struct _NMAccessPointClass{
|
|
|
a85faa |
NMExportedObjectClass parent;
|
|
|
a85faa |
};
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_AP_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMAccessPoint *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_AP (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_AP_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAccessPoint, NM_IS_AP)
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMAccessPoint, nm_ap, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
|
|
|
a85faa |
index 3efd5ac..ce8f4d9 100644
|
|
|
a85faa |
--- a/src/dns-manager/nm-dns-manager.c
|
|
|
a85faa |
+++ b/src/dns-manager/nm-dns-manager.c
|
|
|
a85faa |
@@ -151,18 +151,7 @@ G_DEFINE_TYPE (NMDnsManager, nm_dns_manager, G_TYPE_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
NM_DEFINE_SINGLETON_INSTANCE (NMDnsManager);
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DNS_MANAGER_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMDnsManager *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_DNS_MANAGER (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_DNS_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDnsManager, NM_IS_DNS_MANAGER)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/nm-auth-subject.c b/src/nm-auth-subject.c
|
|
|
a85faa |
index eb496b2..54d3595 100644
|
|
|
a85faa |
--- a/src/nm-auth-subject.c
|
|
|
a85faa |
+++ b/src/nm-auth-subject.c
|
|
|
a85faa |
@@ -68,18 +68,7 @@ struct _NMAuthSubjectClass {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMAuthSubject, nm_auth_subject, G_TYPE_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_AUTH_SUBJECT_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMAuthSubject *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_AUTH_SUBJECT (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_AUTH_SUBJECT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAuthSubject, NM_IS_AUTH_SUBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
/**************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c
|
|
|
a85faa |
index cb1adc3..605e070 100644
|
|
|
a85faa |
--- a/src/nm-checkpoint.c
|
|
|
a85faa |
+++ b/src/nm-checkpoint.c
|
|
|
a85faa |
@@ -70,7 +70,7 @@ typedef struct {
|
|
|
a85faa |
|
|
|
a85faa |
struct _NMCheckpoint {
|
|
|
a85faa |
NMExportedObject parent;
|
|
|
a85faa |
- NMCheckpointPrivate priv;
|
|
|
a85faa |
+ NMCheckpointPrivate _priv;
|
|
|
a85faa |
};
|
|
|
a85faa |
|
|
|
a85faa |
typedef struct {
|
|
|
a85faa |
@@ -79,18 +79,7 @@ typedef struct {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMCheckpoint, nm_checkpoint, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_CHECKPOINT_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMCheckpoint *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_CHECKPOINT (_self)); \
|
|
|
a85faa |
- &_self->priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMCheckpoint, NM_IS_CHECKPOINT)
|
|
|
a85faa |
|
|
|
a85faa |
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
|
|
a85faa |
PROP_DEVICES,
|
|
|
a85faa |
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
|
|
|
a85faa |
index 22d1d07..a4d4361 100644
|
|
|
a85faa |
--- a/src/nm-ip4-config.c
|
|
|
a85faa |
+++ b/src/nm-ip4-config.c
|
|
|
a85faa |
@@ -68,18 +68,7 @@ struct _NMIP4ConfigClass {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_IP4_CONFIG_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMIP4Config *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_IP4_CONFIG (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG)
|
|
|
a85faa |
|
|
|
a85faa |
/* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */
|
|
|
a85faa |
G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32));
|
|
|
a85faa |
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
|
|
|
a85faa |
index ac9e6cd..8002d61 100644
|
|
|
a85faa |
--- a/src/nm-ip6-config.c
|
|
|
a85faa |
+++ b/src/nm-ip6-config.c
|
|
|
a85faa |
@@ -61,18 +61,7 @@ struct _NMIP6ConfigClass {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_IP6_CONFIG_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMIP6Config *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_IP6_CONFIG (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG)
|
|
|
a85faa |
|
|
|
a85faa |
NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config,
|
|
|
a85faa |
PROP_IFINDEX,
|
|
|
a85faa |
diff --git a/src/nm-manager.c b/src/nm-manager.c
|
|
|
a85faa |
index 5794bb9..9ad6517 100644
|
|
|
a85faa |
--- a/src/nm-manager.c
|
|
|
a85faa |
+++ b/src/nm-manager.c
|
|
|
a85faa |
@@ -158,21 +158,10 @@ typedef struct {
|
|
|
a85faa |
NMExportedObjectClass parent;
|
|
|
a85faa |
} NMManagerClass;
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_MANAGER_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMManager *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_MANAGER (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
-
|
|
|
a85faa |
G_DEFINE_TYPE (NMManager, nm_manager, NM_TYPE_EXPORTED_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
+#define NM_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMManager, NM_IS_MANAGER)
|
|
|
a85faa |
+
|
|
|
a85faa |
enum {
|
|
|
a85faa |
DEVICE_ADDED,
|
|
|
a85faa |
INTERNAL_DEVICE_ADDED,
|
|
|
a85faa |
diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c
|
|
|
a85faa |
index 12c2e30..db2965b 100644
|
|
|
a85faa |
--- a/src/rdisc/nm-lndp-rdisc.c
|
|
|
a85faa |
+++ b/src/rdisc/nm-lndp-rdisc.c
|
|
|
a85faa |
@@ -60,18 +60,7 @@ struct _NMLndpRDiscClass {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMLndpRDisc, nm_lndp_rdisc, NM_TYPE_RDISC)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_LNDP_RDISC_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMLndpRDisc *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_LNDP_RDISC (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_LNDP_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpRDisc, NM_IS_LNDP_RDISC)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/rdisc/nm-rdisc.c b/src/rdisc/nm-rdisc.c
|
|
|
a85faa |
index cf993bc..3bc6975 100644
|
|
|
a85faa |
--- a/src/rdisc/nm-rdisc.c
|
|
|
a85faa |
+++ b/src/rdisc/nm-rdisc.c
|
|
|
a85faa |
@@ -87,18 +87,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMRDisc, nm_rdisc, G_TYPE_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_RDISC_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMRDisc *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_RDISC (_self)); \
|
|
|
a85faa |
- _self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMRDisc, NM_IS_RDISC)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
|
|
|
a85faa |
index 92c5bd8..69b45dc 100644
|
|
|
a85faa |
--- a/src/vpn-manager/nm-vpn-connection.c
|
|
|
a85faa |
+++ b/src/vpn-manager/nm-vpn-connection.c
|
|
|
a85faa |
@@ -168,18 +168,7 @@ struct _NMVpnConnectionClass {
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION)
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_VPN_CONNECTION_GET_PRIVATE(self) \
|
|
|
a85faa |
- ({ \
|
|
|
a85faa |
- /* preserve the const-ness of self. Unfortunately, that
|
|
|
a85faa |
- * way, @self cannot be a void pointer */ \
|
|
|
a85faa |
- typeof (self) _self = (self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- /* Get compiler error if variable is of wrong type */ \
|
|
|
a85faa |
- _nm_unused const NMVpnConnection *_self2 = (_self); \
|
|
|
a85faa |
- \
|
|
|
a85faa |
- nm_assert (NM_IS_VPN_CONNECTION (_self)); \
|
|
|
a85faa |
- &_self->_priv; \
|
|
|
a85faa |
- })
|
|
|
a85faa |
+#define NM_VPN_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMVpnConnection, NM_IS_VPN_CONNECTION)
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From ae7affc152479c0b50de63c0495bb81e7fa05405 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 16:42:59 +0200
|
|
|
a85faa |
Subject: [PATCH 05/11] dhcp-listener: refactor type definition and embed
|
|
|
a85faa |
private data in @self
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit 822f01a8fdb63831c887d5db9fb06eb840f53c88)
|
|
|
a85faa |
(cherry picked from commit 75e13f0e15b7618d7fafbe3f1b990871be0950a7)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.c | 50 +++++++++++++++++++++----------------
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.h | 4 +--
|
|
|
a85faa |
2 files changed, 31 insertions(+), 23 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
index eadff3e..d3616cb 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
@@ -13,12 +13,14 @@
|
|
|
a85faa |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
a85faa |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
a85faa |
*
|
|
|
a85faa |
- * Copyright 2014 Red Hat, Inc.
|
|
|
a85faa |
+ * Copyright 2014 - 2016 Red Hat, Inc.
|
|
|
a85faa |
*
|
|
|
a85faa |
*/
|
|
|
a85faa |
|
|
|
a85faa |
#include "nm-default.h"
|
|
|
a85faa |
|
|
|
a85faa |
+#include "nm-dhcp-listener.h"
|
|
|
a85faa |
+
|
|
|
a85faa |
#include <sys/socket.h>
|
|
|
a85faa |
#include <sys/wait.h>
|
|
|
a85faa |
#include <signal.h>
|
|
|
a85faa |
@@ -27,7 +29,6 @@
|
|
|
a85faa |
#include <errno.h>
|
|
|
a85faa |
#include <unistd.h>
|
|
|
a85faa |
|
|
|
a85faa |
-#include "nm-dhcp-listener.h"
|
|
|
a85faa |
#include "nm-core-internal.h"
|
|
|
a85faa |
#include "nm-bus-manager.h"
|
|
|
a85faa |
#include "NetworkManagerUtils.h"
|
|
|
a85faa |
@@ -36,6 +37,8 @@
|
|
|
a85faa |
#define PRIV_SOCK_PATH NMRUNDIR "/private-dhcp"
|
|
|
a85faa |
#define PRIV_SOCK_TAG "dhcp"
|
|
|
a85faa |
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
typedef struct {
|
|
|
a85faa |
NMBusManager * dbus_mgr;
|
|
|
a85faa |
gulong new_conn_id;
|
|
|
a85faa |
@@ -43,17 +46,26 @@ typedef struct {
|
|
|
a85faa |
GHashTable * signal_handlers;
|
|
|
a85faa |
} NMDhcpListenerPrivate;
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DHCP_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_LISTENER, NMDhcpListenerPrivate))
|
|
|
a85faa |
+struct _NMDhcpListener {
|
|
|
a85faa |
+ GObject parent;
|
|
|
a85faa |
+ NMDhcpListenerPrivate _priv;
|
|
|
a85faa |
+};
|
|
|
a85faa |
+
|
|
|
a85faa |
+struct _NMDhcpListenerClass {
|
|
|
a85faa |
+ GObjectClass parent_class;
|
|
|
a85faa |
+};
|
|
|
a85faa |
|
|
|
a85faa |
G_DEFINE_TYPE (NMDhcpListener, nm_dhcp_listener, G_TYPE_OBJECT)
|
|
|
a85faa |
|
|
|
a85faa |
+#define NM_DHCP_LISTENER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDhcpListener, NM_IS_DHCP_LISTENER)
|
|
|
a85faa |
+
|
|
|
a85faa |
enum {
|
|
|
a85faa |
EVENT,
|
|
|
a85faa |
LAST_SIGNAL
|
|
|
a85faa |
};
|
|
|
a85faa |
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
a85faa |
|
|
|
a85faa |
-/***************************************************/
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
static char *
|
|
|
a85faa |
get_option (GVariant *options, const char *key)
|
|
|
a85faa |
@@ -188,7 +200,7 @@ nm_dhcp_listener_init (NMDhcpListener *self)
|
|
|
a85faa |
{
|
|
|
a85faa |
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
|
|
|
a85faa |
|
|
|
a85faa |
- /* Maps GDBusConnection :: GDBusProxy */
|
|
|
a85faa |
+ /* Maps GDBusConnection :: signal-id */
|
|
|
a85faa |
priv->signal_handlers = g_hash_table_new (NULL, NULL);
|
|
|
a85faa |
|
|
|
a85faa |
priv->dbus_mgr = nm_bus_manager_get ();
|
|
|
a85faa |
@@ -208,7 +220,7 @@ nm_dhcp_listener_init (NMDhcpListener *self)
|
|
|
a85faa |
static void
|
|
|
a85faa |
dispose (GObject *object)
|
|
|
a85faa |
{
|
|
|
a85faa |
- NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (object);
|
|
|
a85faa |
+ NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE ((NMDhcpListener *) object);
|
|
|
a85faa |
|
|
|
a85faa |
nm_clear_g_signal_handler (priv->dbus_mgr, &priv->new_conn_id);
|
|
|
a85faa |
nm_clear_g_signal_handler (priv->dbus_mgr, &priv->dis_conn_id);
|
|
|
a85faa |
@@ -224,22 +236,18 @@ nm_dhcp_listener_class_init (NMDhcpListenerClass *listener_class)
|
|
|
a85faa |
{
|
|
|
a85faa |
GObjectClass *object_class = G_OBJECT_CLASS (listener_class);
|
|
|
a85faa |
|
|
|
a85faa |
- g_type_class_add_private (listener_class, sizeof (NMDhcpListenerPrivate));
|
|
|
a85faa |
-
|
|
|
a85faa |
- /* virtual methods */
|
|
|
a85faa |
object_class->dispose = dispose;
|
|
|
a85faa |
|
|
|
a85faa |
- /* signals */
|
|
|
a85faa |
signals[EVENT] =
|
|
|
a85faa |
- g_signal_new (NM_DHCP_LISTENER_EVENT,
|
|
|
a85faa |
- G_OBJECT_CLASS_TYPE (object_class),
|
|
|
a85faa |
- G_SIGNAL_RUN_LAST, 0,
|
|
|
a85faa |
- g_signal_accumulator_true_handled,
|
|
|
a85faa |
- NULL, NULL,
|
|
|
a85faa |
- G_TYPE_BOOLEAN, /* listeners return TRUE if handled */
|
|
|
a85faa |
- 4,
|
|
|
a85faa |
- G_TYPE_STRING, /* iface */
|
|
|
a85faa |
- G_TYPE_INT, /* pid */
|
|
|
a85faa |
- G_TYPE_VARIANT, /* options */
|
|
|
a85faa |
- G_TYPE_STRING); /* reason */
|
|
|
a85faa |
+ g_signal_new (NM_DHCP_LISTENER_EVENT,
|
|
|
a85faa |
+ G_OBJECT_CLASS_TYPE (object_class),
|
|
|
a85faa |
+ G_SIGNAL_RUN_LAST, 0,
|
|
|
a85faa |
+ g_signal_accumulator_true_handled,
|
|
|
a85faa |
+ NULL, NULL,
|
|
|
a85faa |
+ G_TYPE_BOOLEAN, /* listeners return TRUE if handled */
|
|
|
a85faa |
+ 4,
|
|
|
a85faa |
+ G_TYPE_STRING, /* iface */
|
|
|
a85faa |
+ G_TYPE_INT, /* pid */
|
|
|
a85faa |
+ G_TYPE_VARIANT, /* options */
|
|
|
a85faa |
+ G_TYPE_STRING); /* reason */
|
|
|
a85faa |
}
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.h b/src/dhcp-manager/nm-dhcp-listener.h
|
|
|
a85faa |
index ff31fe3..3018b97 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.h
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.h
|
|
|
a85faa |
@@ -26,8 +26,8 @@
|
|
|
a85faa |
|
|
|
a85faa |
#define NM_DHCP_LISTENER_EVENT "event"
|
|
|
a85faa |
|
|
|
a85faa |
-typedef GObject NMDhcpListener;
|
|
|
a85faa |
-typedef GObjectClass NMDhcpListenerClass;
|
|
|
a85faa |
+typedef struct _NMDhcpListener NMDhcpListener;
|
|
|
a85faa |
+typedef struct _NMDhcpListenerClass NMDhcpListenerClass;
|
|
|
a85faa |
|
|
|
a85faa |
GType nm_dhcp_listener_get_type (void);
|
|
|
a85faa |
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 377503fce41e0131e90158b6bcfdb94ff76bd7f7 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 17:17:09 +0200
|
|
|
a85faa |
Subject: [PATCH 06/11] dhcp-listener: add logging macros to nm-dhcp-listener.c
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit d37cd04fe059e9d99c7103f4e22a9a945f8d4d98)
|
|
|
a85faa |
(cherry picked from commit 3920a90e4a63b69bda583c28cc6bdfef1a9f0470)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.c | 39 ++++++++++++++++++++++++++-----------
|
|
|
a85faa |
1 file changed, 28 insertions(+), 11 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
index d3616cb..79d3513 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
@@ -55,16 +55,35 @@ struct _NMDhcpListenerClass {
|
|
|
a85faa |
GObjectClass parent_class;
|
|
|
a85faa |
};
|
|
|
a85faa |
|
|
|
a85faa |
-G_DEFINE_TYPE (NMDhcpListener, nm_dhcp_listener, G_TYPE_OBJECT)
|
|
|
a85faa |
-
|
|
|
a85faa |
-#define NM_DHCP_LISTENER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDhcpListener, NM_IS_DHCP_LISTENER)
|
|
|
a85faa |
-
|
|
|
a85faa |
enum {
|
|
|
a85faa |
EVENT,
|
|
|
a85faa |
LAST_SIGNAL
|
|
|
a85faa |
};
|
|
|
a85faa |
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
a85faa |
|
|
|
a85faa |
+G_DEFINE_TYPE (NMDhcpListener, nm_dhcp_listener, G_TYPE_OBJECT)
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_DHCP_LISTENER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDhcpListener, NM_IS_DHCP_LISTENER)
|
|
|
a85faa |
+
|
|
|
a85faa |
+NM_DEFINE_SINGLETON_GETTER (NMDhcpListener, nm_dhcp_listener_get, NM_TYPE_DHCP_LISTENER);
|
|
|
a85faa |
+
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define _NMLOG_PREFIX_NAME "dhcp-listener"
|
|
|
a85faa |
+#define _NMLOG_DOMAIN LOGD_DHCP
|
|
|
a85faa |
+#define _NMLOG(level, ...) \
|
|
|
a85faa |
+ G_STMT_START { \
|
|
|
a85faa |
+ const NMDhcpListener *_self = (self); \
|
|
|
a85faa |
+ char _prefix[64]; \
|
|
|
a85faa |
+ \
|
|
|
a85faa |
+ nm_log ((level), (_NMLOG_DOMAIN), \
|
|
|
a85faa |
+ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
|
a85faa |
+ (_self != singleton_instance \
|
|
|
a85faa |
+ ? nm_sprintf_buf (_prefix, "%s[%p]", _NMLOG_PREFIX_NAME, _self) \
|
|
|
a85faa |
+ : _NMLOG_PREFIX_NAME )\
|
|
|
a85faa |
+ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
|
a85faa |
+ } G_STMT_END
|
|
|
a85faa |
+
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
static char *
|
|
|
a85faa |
@@ -123,20 +142,20 @@ handle_event (GDBusConnection *connection,
|
|
|
a85faa |
|
|
|
a85faa |
iface = get_option (options, "interface");
|
|
|
a85faa |
if (iface == NULL) {
|
|
|
a85faa |
- nm_log_warn (LOGD_DHCP, "dhcp-event: didn't have associated interface.");
|
|
|
a85faa |
+ _LOGW ("dhcp-event: didn't have associated interface.");
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
pid_str = get_option (options, "pid");
|
|
|
a85faa |
pid = _nm_utils_ascii_str_to_int64 (pid_str, 10, 0, G_MAXINT32, -1);
|
|
|
a85faa |
if (pid == -1) {
|
|
|
a85faa |
- nm_log_warn (LOGD_DHCP, "dhcp-event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)");
|
|
|
a85faa |
+ _LOGW ("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ? pid_str : "(null)");
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
reason = get_option (options, "reason");
|
|
|
a85faa |
if (reason == NULL) {
|
|
|
a85faa |
- nm_log_warn (LOGD_DHCP, "dhcp-event: (pid %d) DHCP event didn't have a reason", pid);
|
|
|
a85faa |
+ _LOGW ("dhcp-event: (pid %d) DHCP event didn't have a reason", pid);
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
@@ -144,9 +163,9 @@ handle_event (GDBusConnection *connection,
|
|
|
a85faa |
if (!handled) {
|
|
|
a85faa |
if (g_ascii_strcasecmp (reason, "RELEASE") == 0) {
|
|
|
a85faa |
/* Ignore event when the dhcp client gets killed and we receive its last message */
|
|
|
a85faa |
- nm_log_dbg (LOGD_DHCP, "dhcp-event: (pid %d) unhandled RELEASE DHCP event for interface %s", pid, iface);
|
|
|
a85faa |
+ _LOGD ("dhcp-event: (pid %d) unhandled RELEASE DHCP event for interface %s", pid, iface);
|
|
|
a85faa |
} else
|
|
|
a85faa |
- nm_log_warn (LOGD_DHCP, "dhcp-event: (pid %d) unhandled DHCP event for interface %s", pid, iface);
|
|
|
a85faa |
+ _LOGW ("dhcp-event: (pid %d) unhandled DHCP event for interface %s", pid, iface);
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
out:
|
|
|
a85faa |
@@ -193,8 +212,6 @@ dis_connection_cb (NMBusManager *mgr,
|
|
|
a85faa |
|
|
|
a85faa |
/***************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
-NM_DEFINE_SINGLETON_GETTER (NMDhcpListener, nm_dhcp_listener_get, NM_TYPE_DHCP_LISTENER);
|
|
|
a85faa |
-
|
|
|
a85faa |
static void
|
|
|
a85faa |
nm_dhcp_listener_init (NMDhcpListener *self)
|
|
|
a85faa |
{
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 515b7f7db6e1ddecac084cd8ea4d8889c170c6f0 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 17:24:28 +0200
|
|
|
a85faa |
Subject: [PATCH 07/11] dhcp-listener/trivial: rename field to track
|
|
|
a85faa |
connections in NMDhcpListener
|
|
|
a85faa |
|
|
|
a85faa |
It's not "signal-handles", as it currently tracks the registration ID of
|
|
|
a85faa |
type int. Rename it, it is effectively the list of connections that we
|
|
|
a85faa |
track.
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit 2dd3a5245f91a7c25ae1a36a86638195500f00a8)
|
|
|
a85faa |
(cherry picked from commit 0ebdfd6cf1f1ba3c9753db4d9dd8979bb458a689)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.c | 12 ++++++------
|
|
|
a85faa |
1 file changed, 6 insertions(+), 6 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
index 79d3513..b09bc20 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
@@ -43,7 +43,7 @@ typedef struct {
|
|
|
a85faa |
NMBusManager * dbus_mgr;
|
|
|
a85faa |
gulong new_conn_id;
|
|
|
a85faa |
gulong dis_conn_id;
|
|
|
a85faa |
- GHashTable * signal_handlers;
|
|
|
a85faa |
+ GHashTable * connections;
|
|
|
a85faa |
} NMDhcpListenerPrivate;
|
|
|
a85faa |
|
|
|
a85faa |
struct _NMDhcpListener {
|
|
|
a85faa |
@@ -192,7 +192,7 @@ new_connection_cb (NMBusManager *mgr,
|
|
|
a85faa |
NULL,
|
|
|
a85faa |
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
|
a85faa |
handle_event, self, NULL);
|
|
|
a85faa |
- g_hash_table_insert (priv->signal_handlers, connection, GUINT_TO_POINTER (id));
|
|
|
a85faa |
+ g_hash_table_insert (priv->connections, connection, GUINT_TO_POINTER (id));
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
@@ -203,10 +203,10 @@ dis_connection_cb (NMBusManager *mgr,
|
|
|
a85faa |
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
|
|
|
a85faa |
guint id;
|
|
|
a85faa |
|
|
|
a85faa |
- id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->signal_handlers, connection));
|
|
|
a85faa |
+ id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->connections, connection));
|
|
|
a85faa |
if (id) {
|
|
|
a85faa |
g_dbus_connection_signal_unsubscribe (connection, id);
|
|
|
a85faa |
- g_hash_table_remove (priv->signal_handlers, connection);
|
|
|
a85faa |
+ g_hash_table_remove (priv->connections, connection);
|
|
|
a85faa |
}
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
@@ -218,7 +218,7 @@ nm_dhcp_listener_init (NMDhcpListener *self)
|
|
|
a85faa |
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
|
|
|
a85faa |
|
|
|
a85faa |
/* Maps GDBusConnection :: signal-id */
|
|
|
a85faa |
- priv->signal_handlers = g_hash_table_new (NULL, NULL);
|
|
|
a85faa |
+ priv->connections = g_hash_table_new (NULL, NULL);
|
|
|
a85faa |
|
|
|
a85faa |
priv->dbus_mgr = nm_bus_manager_get ();
|
|
|
a85faa |
|
|
|
a85faa |
@@ -243,7 +243,7 @@ dispose (GObject *object)
|
|
|
a85faa |
nm_clear_g_signal_handler (priv->dbus_mgr, &priv->dis_conn_id);
|
|
|
a85faa |
priv->dbus_mgr = NULL;
|
|
|
a85faa |
|
|
|
a85faa |
- g_clear_pointer (&priv->signal_handlers, g_hash_table_destroy);
|
|
|
a85faa |
+ g_clear_pointer (&priv->connections, g_hash_table_destroy);
|
|
|
a85faa |
|
|
|
a85faa |
G_OBJECT_CLASS (nm_dhcp_listener_parent_class)->dispose (object);
|
|
|
a85faa |
}
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 968217553d734c721988d24fffb8b1977fb6129b Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 11:06:04 +0200
|
|
|
a85faa |
Subject: [PATCH 08/11] dhcp-helper: refactor error handling
|
|
|
a85faa |
|
|
|
a85faa |
Don't exit(1) from fatal_error() because that skips destroying
|
|
|
a85faa |
local variables in main(). Just return regularly.
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit bb489163db36889a6fb80789e4e5b9dd8a15dbdd)
|
|
|
a85faa |
(cherry picked from commit a8d87ef87f2931f07e6fa6dd0df56bf3d1fdf79e)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper.c | 30 +++++++++++++++---------------
|
|
|
a85faa |
1 file changed, 15 insertions(+), 15 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
index 7667084..8c512e7 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
@@ -74,26 +74,26 @@ build_signal_parameters (void)
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
-fatal_error (void)
|
|
|
a85faa |
+kill_pid (void)
|
|
|
a85faa |
{
|
|
|
a85faa |
- const char *pid_str = getenv ("pid");
|
|
|
a85faa |
- int pid = 0;
|
|
|
a85faa |
+ const char *pid_str;
|
|
|
a85faa |
+ pid_t pid = 0;
|
|
|
a85faa |
|
|
|
a85faa |
+ pid_str = getenv ("pid");
|
|
|
a85faa |
if (pid_str)
|
|
|
a85faa |
pid = strtol (pid_str, NULL, 10);
|
|
|
a85faa |
if (pid) {
|
|
|
a85faa |
g_printerr ("Fatal error occured, killing dhclient instance with pid %d.\n", pid);
|
|
|
a85faa |
kill (pid, SIGTERM);
|
|
|
a85faa |
}
|
|
|
a85faa |
-
|
|
|
a85faa |
- exit (1);
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
int
|
|
|
a85faa |
main (int argc, char *argv[])
|
|
|
a85faa |
{
|
|
|
a85faa |
- GDBusConnection *connection;
|
|
|
a85faa |
- GError *error = NULL;
|
|
|
a85faa |
+ gs_unref_object GDBusConnection *connection = NULL;
|
|
|
a85faa |
+ gs_free_error GError *error = NULL;
|
|
|
a85faa |
+ gboolean success = FALSE;
|
|
|
a85faa |
|
|
|
a85faa |
nm_g_type_init ();
|
|
|
a85faa |
|
|
|
a85faa |
@@ -104,8 +104,7 @@ main (int argc, char *argv[])
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n",
|
|
|
a85faa |
error->message);
|
|
|
a85faa |
- g_error_free (error);
|
|
|
a85faa |
- fatal_error ();
|
|
|
a85faa |
+ goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
if (!g_dbus_connection_emit_signal (connection,
|
|
|
a85faa |
@@ -117,18 +116,19 @@ main (int argc, char *argv[])
|
|
|
a85faa |
&error)) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
g_printerr ("Error: Could not send DHCP Event signal: %s\n", error->message);
|
|
|
a85faa |
- g_error_free (error);
|
|
|
a85faa |
- fatal_error ();
|
|
|
a85faa |
+ goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
if (!g_dbus_connection_flush_sync (connection, NULL, &error)) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
g_printerr ("Error: Could not flush D-Bus connection: %s\n", error->message);
|
|
|
a85faa |
- g_error_free (error);
|
|
|
a85faa |
- fatal_error ();
|
|
|
a85faa |
+ goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
- g_object_unref (connection);
|
|
|
a85faa |
- return 0;
|
|
|
a85faa |
+ success = TRUE;
|
|
|
a85faa |
+out:
|
|
|
a85faa |
+ if (!success)
|
|
|
a85faa |
+ kill_pid ();
|
|
|
a85faa |
+ return success ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 4a84b10ea293e7f4d92b868fb37031a2cbaf1df6 Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 13:38:58 +0200
|
|
|
a85faa |
Subject: [PATCH 09/11] dhcp-helper: refactor logging to use logging macros
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit cc89996c9e826c9c8d12d5fb7bc8a2a578209eb0)
|
|
|
a85faa |
(cherry picked from commit 9d44dafc3cef8fe1b7d41c9af0f6fa30254924f1)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper.c | 45 ++++++++++++++++++++++++++++++++++-----
|
|
|
a85faa |
1 file changed, 40 insertions(+), 5 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
index 8c512e7..383c985 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
@@ -25,8 +25,43 @@
|
|
|
a85faa |
#include <string.h>
|
|
|
a85faa |
#include <signal.h>
|
|
|
a85faa |
|
|
|
a85faa |
+#include "nm-utils/nm-vpn-plugin-macros.h"
|
|
|
a85faa |
+
|
|
|
a85faa |
#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
|
|
|
a85faa |
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
+#ifdef NM_MORE_LOGGING
|
|
|
a85faa |
+#define _NMLOG_ENABLED(level) TRUE
|
|
|
a85faa |
+#else
|
|
|
a85faa |
+#define _NMLOG_ENABLED(level) ((level) <= LOG_ERR)
|
|
|
a85faa |
+#endif
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define _NMLOG(always_enabled, level, ...) \
|
|
|
a85faa |
+ G_STMT_START { \
|
|
|
a85faa |
+ if ((always_enabled) || _NMLOG_ENABLED (level)) { \
|
|
|
a85faa |
+ GTimeVal _tv; \
|
|
|
a85faa |
+ \
|
|
|
a85faa |
+ g_get_current_time (&_tv); \
|
|
|
a85faa |
+ g_print ("nm-dhcp-helper[%ld] %-7s [%ld.%04ld] " _NM_UTILS_MACRO_FIRST (__VA_ARGS__) "\n", \
|
|
|
a85faa |
+ (long) getpid (), \
|
|
|
a85faa |
+ nm_utils_syslog_to_str (level), \
|
|
|
a85faa |
+ _tv.tv_sec, _tv.tv_usec / 100 \
|
|
|
a85faa |
+ _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
|
|
a85faa |
+ } \
|
|
|
a85faa |
+ } G_STMT_END
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define _LOGD(...) _NMLOG(TRUE, LOG_INFO, __VA_ARGS__)
|
|
|
a85faa |
+#define _LOGI(...) _NMLOG(TRUE, LOG_NOTICE, __VA_ARGS__)
|
|
|
a85faa |
+#define _LOGW(...) _NMLOG(TRUE, LOG_WARNING, __VA_ARGS__)
|
|
|
a85faa |
+#define _LOGE(...) _NMLOG(TRUE, LOG_ERR, __VA_ARGS__)
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define _LOGd(...) _NMLOG(FALSE, LOG_INFO, __VA_ARGS__)
|
|
|
a85faa |
+#define _LOGi(...) _NMLOG(FALSE, LOG_NOTICE, __VA_ARGS__)
|
|
|
a85faa |
+#define _LOGw(...) _NMLOG(FALSE, LOG_WARNING, __VA_ARGS__)
|
|
|
a85faa |
+
|
|
|
a85faa |
+/*****************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
static const char * ignore[] = {"PATH", "SHLVL", "_", "PWD", "dhc_dbus", NULL};
|
|
|
a85faa |
|
|
|
a85faa |
static GVariant *
|
|
|
a85faa |
@@ -83,7 +118,7 @@ kill_pid (void)
|
|
|
a85faa |
if (pid_str)
|
|
|
a85faa |
pid = strtol (pid_str, NULL, 10);
|
|
|
a85faa |
if (pid) {
|
|
|
a85faa |
- g_printerr ("Fatal error occured, killing dhclient instance with pid %d.\n", pid);
|
|
|
a85faa |
+ _LOGI ("a fatal error occured, kill dhclient instance with pid %d\n", pid);
|
|
|
a85faa |
kill (pid, SIGTERM);
|
|
|
a85faa |
}
|
|
|
a85faa |
}
|
|
|
a85faa |
@@ -102,8 +137,8 @@ main (int argc, char *argv[])
|
|
|
a85faa |
NULL, NULL, &error);
|
|
|
a85faa |
if (!connection) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
- g_printerr ("Error: could not connect to NetworkManager D-Bus socket: %s\n",
|
|
|
a85faa |
- error->message);
|
|
|
a85faa |
+ _LOGE ("could not connect to NetworkManager D-Bus socket: %s",
|
|
|
a85faa |
+ error->message);
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
@@ -115,13 +150,13 @@ main (int argc, char *argv[])
|
|
|
a85faa |
build_signal_parameters (),
|
|
|
a85faa |
&error)) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
- g_printerr ("Error: Could not send DHCP Event signal: %s\n", error->message);
|
|
|
a85faa |
+ _LOGE ("could not send DHCP Event signal: %s", error->message);
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
if (!g_dbus_connection_flush_sync (connection, NULL, &error)) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
- g_printerr ("Error: Could not flush D-Bus connection: %s\n", error->message);
|
|
|
a85faa |
+ _LOGE ("could not flush D-Bus connection: %s", error->message);
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From c042d8b3e6c181755d0c2f0fc97e9c5fd04a81fa Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 11:54:46 +0200
|
|
|
a85faa |
Subject: [PATCH 10/11] dhcp: add new header "nm-dhcp-helper-api.h"
|
|
|
a85faa |
|
|
|
a85faa |
(cherry picked from commit 7684b68c49812ed7b2ec493889fae04db066b665)
|
|
|
a85faa |
(cherry picked from commit 3ac3125aff9987b3ac0284daaa3faae93291a603)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/Makefile.am | 1 +
|
|
|
a85faa |
src/dhcp-manager/Makefile.am | 5 ++++-
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper-api.h | 31 +++++++++++++++++++++++++++++++
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper.c | 2 +-
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.c | 2 +-
|
|
|
a85faa |
5 files changed, 38 insertions(+), 3 deletions(-)
|
|
|
a85faa |
create mode 100644 src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
|
a85faa |
index c460caf..8d29b19 100644
|
|
|
a85faa |
--- a/src/Makefile.am
|
|
|
a85faa |
+++ b/src/Makefile.am
|
|
|
a85faa |
@@ -335,6 +335,7 @@ libNetworkManager_la_SOURCES = \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-client.c \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-client.h \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-client-logging.h \
|
|
|
a85faa |
+ dhcp-manager/nm-dhcp-helper-api.h \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-utils.c \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-utils.h \
|
|
|
a85faa |
dhcp-manager/nm-dhcp-listener.c \
|
|
|
a85faa |
diff --git a/src/dhcp-manager/Makefile.am b/src/dhcp-manager/Makefile.am
|
|
|
a85faa |
index b4590b4..4295412 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/Makefile.am
|
|
|
a85faa |
+++ b/src/dhcp-manager/Makefile.am
|
|
|
a85faa |
@@ -1,6 +1,9 @@
|
|
|
a85faa |
libexec_PROGRAMS = nm-dhcp-helper
|
|
|
a85faa |
|
|
|
a85faa |
-nm_dhcp_helper_SOURCES = nm-dhcp-helper.c
|
|
|
a85faa |
+nm_dhcp_helper_SOURCES = \
|
|
|
a85faa |
+ nm-dhcp-helper.c \
|
|
|
a85faa |
+ nm-dhcp-helper-api.h \
|
|
|
a85faa |
+ $(NULL)
|
|
|
a85faa |
|
|
|
a85faa |
nm_dhcp_helper_CPPFLAGS = \
|
|
|
a85faa |
$(GLIB_CFLAGS) \
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper-api.h b/src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
new file mode 100644
|
|
|
a85faa |
index 0000000..a6323db
|
|
|
a85faa |
--- /dev/null
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
@@ -0,0 +1,31 @@
|
|
|
a85faa |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
a85faa |
+/* NetworkManager -- Network link manager
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * This library is free software; you can redistribute it and/or
|
|
|
a85faa |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
a85faa |
+ * License as published by the Free Software Foundation; either
|
|
|
a85faa |
+ * version 2 of the License, or (at your option) any later version.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * This library is distributed in the hope that it will be useful,
|
|
|
a85faa |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a85faa |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
a85faa |
+ * Lesser General Public License for more details.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
a85faa |
+ * License along with this library; if not, write to the
|
|
|
a85faa |
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
a85faa |
+ * Boston, MA 02110-1301 USA.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * (C) Copyright 2016 Red Hat, Inc.
|
|
|
a85faa |
+ */
|
|
|
a85faa |
+
|
|
|
a85faa |
+#ifndef __NM_DHCP_HELPER_API_H__
|
|
|
a85faa |
+#define __NM_DHCP_HELPER_API_H__
|
|
|
a85faa |
+
|
|
|
a85faa |
+/******************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
+#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
|
|
|
a85faa |
+
|
|
|
a85faa |
+/******************************************************************************/
|
|
|
a85faa |
+
|
|
|
a85faa |
+#endif /* __NM_DHCP_HELPER_API_H__ */
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
index 383c985..e53fe27 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
@@ -27,7 +27,7 @@
|
|
|
a85faa |
|
|
|
a85faa |
#include "nm-utils/nm-vpn-plugin-macros.h"
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
|
|
|
a85faa |
+#include "nm-dhcp-helper-api.h"
|
|
|
a85faa |
|
|
|
a85faa |
/*****************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
index b09bc20..7e9de49 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
@@ -29,11 +29,11 @@
|
|
|
a85faa |
#include <errno.h>
|
|
|
a85faa |
#include <unistd.h>
|
|
|
a85faa |
|
|
|
a85faa |
+#include "nm-dhcp-helper-api.h"
|
|
|
a85faa |
#include "nm-core-internal.h"
|
|
|
a85faa |
#include "nm-bus-manager.h"
|
|
|
a85faa |
#include "NetworkManagerUtils.h"
|
|
|
a85faa |
|
|
|
a85faa |
-#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
|
|
|
a85faa |
#define PRIV_SOCK_PATH NMRUNDIR "/private-dhcp"
|
|
|
a85faa |
#define PRIV_SOCK_TAG "dhcp"
|
|
|
a85faa |
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|
|
|
a85faa |
|
|
|
a85faa |
From 74ec0731881943cde1c8de30ae708e688c8987aa Mon Sep 17 00:00:00 2001
|
|
|
a85faa |
From: Thomas Haller <thaller@redhat.com>
|
|
|
a85faa |
Date: Mon, 5 Sep 2016 12:32:40 +0200
|
|
|
a85faa |
Subject: [PATCH 11/11] dhcp: call synchronous Notify D-Bus method from
|
|
|
a85faa |
nm-dhcp-helper
|
|
|
a85faa |
|
|
|
a85faa |
A D-Bus signal is asynchronous and it can happen that nm-dhcp-helper
|
|
|
a85faa |
emits the "Event" signal before the server is able to register a handler:
|
|
|
a85faa |
|
|
|
a85faa |
NM_DHCP_HELPER=/usr/libexec/nm-dhcp-helper
|
|
|
a85faa |
nmcli general logging level TRACE
|
|
|
a85faa |
for i in `seq 1 500`; do $NM_DHCP_HELPER & done
|
|
|
a85faa |
journalctl -u NetworkManager --since '1 min ago' | grep "didn't have associated interface" | wc -l
|
|
|
a85faa |
499
|
|
|
a85faa |
|
|
|
a85faa |
Avoid that, by calling the synchronous D-Bus method "Notify".
|
|
|
a85faa |
|
|
|
a85faa |
Interestingly, this race seem to exist since 2007.
|
|
|
a85faa |
|
|
|
a85faa |
Actually, we called g_dbus_connection_signal_subscribe() from inside
|
|
|
a85faa |
GDBusServer:new-connection signal. So it is not clear how such a race
|
|
|
a85faa |
could exist. I was not able to reproduce it by putting a sleep
|
|
|
a85faa |
before g_dbus_connection_signal_subscribe(). On the other hand, there
|
|
|
a85faa |
is bug rh#1372854 and above reproducer which strongly indicates that
|
|
|
a85faa |
events can be lost under certain circumstances.
|
|
|
a85faa |
Now we instead g_dbus_connection_register_object() from the
|
|
|
a85faa |
new-connection signal. According to my tests there was no more race
|
|
|
a85faa |
as also backed by glib's documentation. Still, keep a simple retry-loop
|
|
|
a85faa |
in nm-dhcp-helper just to be sure.
|
|
|
a85faa |
|
|
|
a85faa |
https://bugzilla.redhat.com/show_bug.cgi?id=1372854
|
|
|
a85faa |
https://bugzilla.redhat.com/show_bug.cgi?id=1373276
|
|
|
a85faa |
(cherry picked from commit 2856a658b38df88494187c811415a198a424e1f2)
|
|
|
a85faa |
(cherry picked from commit e678bd29a4e5fdd83b7d99392d54ecb5fcabc287)
|
|
|
a85faa |
---
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper-api.h | 5 ++
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-helper.c | 78 +++++++++++++++++++++++-----
|
|
|
a85faa |
src/dhcp-manager/nm-dhcp-listener.c | 97 ++++++++++++++++++++++++++++-------
|
|
|
a85faa |
src/nm-bus-manager.c | 6 ++-
|
|
|
a85faa |
4 files changed, 153 insertions(+), 33 deletions(-)
|
|
|
a85faa |
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper-api.h b/src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
index a6323db..a3eb171 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper-api.h
|
|
|
a85faa |
@@ -26,6 +26,11 @@
|
|
|
a85faa |
|
|
|
a85faa |
#define NM_DHCP_CLIENT_DBUS_IFACE "org.freedesktop.nm_dhcp_client"
|
|
|
a85faa |
|
|
|
a85faa |
+#define NM_DHCP_HELPER_SERVER_BUS_NAME "org.freedesktop.nm_dhcp_server"
|
|
|
a85faa |
+#define NM_DHCP_HELPER_SERVER_OBJECT_PATH "/org/freedesktop/nm_dhcp_server"
|
|
|
a85faa |
+#define NM_DHCP_HELPER_SERVER_INTERFACE_NAME "org.freedesktop.nm_dhcp_server"
|
|
|
a85faa |
+#define NM_DHCP_HELPER_SERVER_METHOD_NOTIFY "Notify"
|
|
|
a85faa |
+
|
|
|
a85faa |
/******************************************************************************/
|
|
|
a85faa |
|
|
|
a85faa |
#endif /* __NM_DHCP_HELPER_API_H__ */
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-helper.c b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
index e53fe27..9c6f69b 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-helper.c
|
|
|
a85faa |
@@ -105,7 +105,7 @@ build_signal_parameters (void)
|
|
|
a85faa |
g_free (name);
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
- return g_variant_new ("(a{sv})", &builder);
|
|
|
a85faa |
+ return g_variant_ref_sink (g_variant_new ("(a{sv})", &builder));
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
@@ -128,7 +128,11 @@ main (int argc, char *argv[])
|
|
|
a85faa |
{
|
|
|
a85faa |
gs_unref_object GDBusConnection *connection = NULL;
|
|
|
a85faa |
gs_free_error GError *error = NULL;
|
|
|
a85faa |
+ gs_unref_variant GVariant *parameters = NULL;
|
|
|
a85faa |
+ gs_unref_variant GVariant *result = NULL;
|
|
|
a85faa |
gboolean success = FALSE;
|
|
|
a85faa |
+ guint try_count = 0;
|
|
|
a85faa |
+ gint64 time_end;
|
|
|
a85faa |
|
|
|
a85faa |
nm_g_type_init ();
|
|
|
a85faa |
|
|
|
a85faa |
@@ -142,25 +146,73 @@ main (int argc, char *argv[])
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
- if (!g_dbus_connection_emit_signal (connection,
|
|
|
a85faa |
- NULL,
|
|
|
a85faa |
- "/",
|
|
|
a85faa |
- NM_DHCP_CLIENT_DBUS_IFACE,
|
|
|
a85faa |
- "Event",
|
|
|
a85faa |
- build_signal_parameters (),
|
|
|
a85faa |
- &error)) {
|
|
|
a85faa |
- g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
- _LOGE ("could not send DHCP Event signal: %s", error->message);
|
|
|
a85faa |
- goto out;
|
|
|
a85faa |
- }
|
|
|
a85faa |
+ parameters = build_signal_parameters ();
|
|
|
a85faa |
+
|
|
|
a85faa |
+ time_end = g_get_monotonic_time () + (200 * 1000L); /* retry for at most 200 milliseconds */
|
|
|
a85faa |
+
|
|
|
a85faa |
+do_notify:
|
|
|
a85faa |
+ try_count++;
|
|
|
a85faa |
+ result = g_dbus_connection_call_sync (connection,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ NM_DHCP_HELPER_SERVER_OBJECT_PATH,
|
|
|
a85faa |
+ NM_DHCP_HELPER_SERVER_INTERFACE_NAME,
|
|
|
a85faa |
+ NM_DHCP_HELPER_SERVER_METHOD_NOTIFY,
|
|
|
a85faa |
+ parameters,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ G_DBUS_CALL_FLAGS_NONE,
|
|
|
a85faa |
+ 1000,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ &error);
|
|
|
a85faa |
+
|
|
|
a85faa |
+ if (!result) {
|
|
|
a85faa |
+ gs_free char *s_err = NULL;
|
|
|
a85faa |
+
|
|
|
a85faa |
+ s_err = g_dbus_error_get_remote_error (error);
|
|
|
a85faa |
+ if (NM_IN_STRSET (s_err, "org.freedesktop.DBus.Error.UnknownMethod")) {
|
|
|
a85faa |
+ gint64 remaining_time = time_end - g_get_monotonic_time ();
|
|
|
a85faa |
+
|
|
|
a85faa |
+ /* I am not sure that a race can actually happen, as we register the object
|
|
|
a85faa |
+ * on the server side during GDBusServer:new-connection signal.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * However, there was also a race for subscribing to an event, so let's just
|
|
|
a85faa |
+ * do some retry. */
|
|
|
a85faa |
+ if (remaining_time > 0) {
|
|
|
a85faa |
+ _LOGi ("failure to call notify: %s (retry %u)", error->message, try_count);
|
|
|
a85faa |
+ g_usleep (NM_MIN (NM_CLAMP ((gint64) (100L * (1L << try_count)), 5000, 25000), remaining_time));
|
|
|
a85faa |
+ g_clear_error (&error);
|
|
|
a85faa |
+ goto do_notify;
|
|
|
a85faa |
+ }
|
|
|
a85faa |
+ }
|
|
|
a85faa |
+ _LOGW ("failure to call notify: %s (try signal via Event)", error->message);
|
|
|
a85faa |
+ g_clear_error (&error);
|
|
|
a85faa |
+
|
|
|
a85faa |
+ /* for backward compatibilty, try to emit the signal. There is no stable
|
|
|
a85faa |
+ * API between the dhcp-helper and NetworkManager. However, while upgrading
|
|
|
a85faa |
+ * the NetworkManager package, a newer helper might want to notify an
|
|
|
a85faa |
+ * older server, which still uses the "Event". */
|
|
|
a85faa |
+ if (!g_dbus_connection_emit_signal (connection,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ "/",
|
|
|
a85faa |
+ NM_DHCP_CLIENT_DBUS_IFACE,
|
|
|
a85faa |
+ "Event",
|
|
|
a85faa |
+ parameters,
|
|
|
a85faa |
+ &error)) {
|
|
|
a85faa |
+ g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
+ _LOGE ("could not send DHCP Event signal: %s", error->message);
|
|
|
a85faa |
+ goto out;
|
|
|
a85faa |
+ }
|
|
|
a85faa |
+ /* We were able to send the asynchronous Event. Consider that a success. */
|
|
|
a85faa |
+ success = TRUE;
|
|
|
a85faa |
+ } else
|
|
|
a85faa |
+ success = TRUE;
|
|
|
a85faa |
|
|
|
a85faa |
if (!g_dbus_connection_flush_sync (connection, NULL, &error)) {
|
|
|
a85faa |
g_dbus_error_strip_remote_error (error);
|
|
|
a85faa |
_LOGE ("could not flush D-Bus connection: %s", error->message);
|
|
|
a85faa |
+ success = FALSE;
|
|
|
a85faa |
goto out;
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
- success = TRUE;
|
|
|
a85faa |
out:
|
|
|
a85faa |
if (!success)
|
|
|
a85faa |
kill_pid ();
|
|
|
a85faa |
diff --git a/src/dhcp-manager/nm-dhcp-listener.c b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
index 7e9de49..0df4197 100644
|
|
|
a85faa |
--- a/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
+++ b/src/dhcp-manager/nm-dhcp-listener.c
|
|
|
a85faa |
@@ -119,13 +119,14 @@ get_option (GVariant *options, const char *key)
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
-handle_event (GDBusConnection *connection,
|
|
|
a85faa |
- const char *sender_name,
|
|
|
a85faa |
- const char *object_path,
|
|
|
a85faa |
- const char *interface_name,
|
|
|
a85faa |
- const char *signal_name,
|
|
|
a85faa |
- GVariant *parameters,
|
|
|
a85faa |
- gpointer user_data)
|
|
|
a85faa |
+_method_call (GDBusConnection *connection,
|
|
|
a85faa |
+ const char *sender,
|
|
|
a85faa |
+ const char *object_path,
|
|
|
a85faa |
+ const char *interface_name,
|
|
|
a85faa |
+ const char *method_name,
|
|
|
a85faa |
+ GVariant *parameters,
|
|
|
a85faa |
+ GDBusMethodInvocation *invocation,
|
|
|
a85faa |
+ gpointer user_data)
|
|
|
a85faa |
{
|
|
|
a85faa |
NMDhcpListener *self = NM_DHCP_LISTENER (user_data);
|
|
|
a85faa |
char *iface = NULL;
|
|
|
a85faa |
@@ -135,8 +136,12 @@ handle_event (GDBusConnection *connection,
|
|
|
a85faa |
gboolean handled = FALSE;
|
|
|
a85faa |
GVariant *options;
|
|
|
a85faa |
|
|
|
a85faa |
+ if (!nm_streq0 (interface_name, NM_DHCP_HELPER_SERVER_INTERFACE_NAME))
|
|
|
a85faa |
+ g_return_if_reached ();
|
|
|
a85faa |
+ if (!nm_streq0 (method_name, NM_DHCP_HELPER_SERVER_METHOD_NOTIFY))
|
|
|
a85faa |
+ g_return_if_reached ();
|
|
|
a85faa |
if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})")))
|
|
|
a85faa |
- return;
|
|
|
a85faa |
+ g_return_if_reached ();
|
|
|
a85faa |
|
|
|
a85faa |
g_variant_get (parameters, "(@a{sv})", &options);
|
|
|
a85faa |
|
|
|
a85faa |
@@ -173,6 +178,57 @@ out:
|
|
|
a85faa |
g_free (pid_str);
|
|
|
a85faa |
g_free (reason);
|
|
|
a85faa |
g_variant_unref (options);
|
|
|
a85faa |
+ g_dbus_method_invocation_return_value (invocation, NULL);
|
|
|
a85faa |
+}
|
|
|
a85faa |
+
|
|
|
a85faa |
+static guint
|
|
|
a85faa |
+_dbus_connection_register_object (NMDhcpListener *self,
|
|
|
a85faa |
+ GDBusConnection *connection,
|
|
|
a85faa |
+ GError **error)
|
|
|
a85faa |
+{
|
|
|
a85faa |
+ static GDBusArgInfo arg_info_notify_in = {
|
|
|
a85faa |
+ .ref_count = -1,
|
|
|
a85faa |
+ .name = "data",
|
|
|
a85faa |
+ .signature = "a{sv}",
|
|
|
a85faa |
+ .annotations = NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+ static GDBusArgInfo *arg_infos_notify[] = {
|
|
|
a85faa |
+ &arg_info_notify_in,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+ static GDBusMethodInfo method_info_notify = {
|
|
|
a85faa |
+ .ref_count = -1,
|
|
|
a85faa |
+ .name = NM_DHCP_HELPER_SERVER_METHOD_NOTIFY,
|
|
|
a85faa |
+ .in_args = arg_infos_notify,
|
|
|
a85faa |
+ .out_args = NULL,
|
|
|
a85faa |
+ .annotations = NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+ static GDBusMethodInfo *method_infos[] = {
|
|
|
a85faa |
+ &method_info_notify,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+ static GDBusInterfaceInfo interface_info = {
|
|
|
a85faa |
+ .ref_count = -1,
|
|
|
a85faa |
+ .name = NM_DHCP_HELPER_SERVER_INTERFACE_NAME,
|
|
|
a85faa |
+ .methods = method_infos,
|
|
|
a85faa |
+ .signals = NULL,
|
|
|
a85faa |
+ .properties = NULL,
|
|
|
a85faa |
+ .annotations = NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+
|
|
|
a85faa |
+ static GDBusInterfaceVTable interface_vtable = {
|
|
|
a85faa |
+ .method_call = _method_call,
|
|
|
a85faa |
+ .get_property = NULL,
|
|
|
a85faa |
+ .set_property = NULL,
|
|
|
a85faa |
+ };
|
|
|
a85faa |
+
|
|
|
a85faa |
+ return g_dbus_connection_register_object (connection,
|
|
|
a85faa |
+ NM_DHCP_HELPER_SERVER_OBJECT_PATH,
|
|
|
a85faa |
+ &interface_info,
|
|
|
a85faa |
+ &interface_vtable,
|
|
|
a85faa |
+ self,
|
|
|
a85faa |
+ NULL,
|
|
|
a85faa |
+ error);
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
@@ -182,17 +238,20 @@ new_connection_cb (NMBusManager *mgr,
|
|
|
a85faa |
NMDhcpListener *self)
|
|
|
a85faa |
{
|
|
|
a85faa |
NMDhcpListenerPrivate *priv = NM_DHCP_LISTENER_GET_PRIVATE (self);
|
|
|
a85faa |
- guint id;
|
|
|
a85faa |
+ guint registration_id;
|
|
|
a85faa |
+ GError *error = NULL;
|
|
|
a85faa |
+
|
|
|
a85faa |
+ /* it is important to register the object during the new-connection signal,
|
|
|
a85faa |
+ * as this avoids races with the connecting object. */
|
|
|
a85faa |
+ registration_id = _dbus_connection_register_object (self, connection, &error);
|
|
|
a85faa |
+ if (!registration_id) {
|
|
|
a85faa |
+ _LOGE ("failure to register %s for connection %p: %s",
|
|
|
a85faa |
+ NM_DHCP_HELPER_SERVER_OBJECT_PATH, connection, error->message);
|
|
|
a85faa |
+ g_error_free (error);
|
|
|
a85faa |
+ return;
|
|
|
a85faa |
+ }
|
|
|
a85faa |
|
|
|
a85faa |
- id = g_dbus_connection_signal_subscribe (connection,
|
|
|
a85faa |
- NULL,
|
|
|
a85faa |
- NM_DHCP_CLIENT_DBUS_IFACE,
|
|
|
a85faa |
- "Event",
|
|
|
a85faa |
- NULL,
|
|
|
a85faa |
- NULL,
|
|
|
a85faa |
- G_DBUS_SIGNAL_FLAGS_NONE,
|
|
|
a85faa |
- handle_event, self, NULL);
|
|
|
a85faa |
- g_hash_table_insert (priv->connections, connection, GUINT_TO_POINTER (id));
|
|
|
a85faa |
+ g_hash_table_insert (priv->connections, connection, GUINT_TO_POINTER (registration_id));
|
|
|
a85faa |
}
|
|
|
a85faa |
|
|
|
a85faa |
static void
|
|
|
a85faa |
@@ -205,7 +264,7 @@ dis_connection_cb (NMBusManager *mgr,
|
|
|
a85faa |
|
|
|
a85faa |
id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->connections, connection));
|
|
|
a85faa |
if (id) {
|
|
|
a85faa |
- g_dbus_connection_signal_unsubscribe (connection, id);
|
|
|
a85faa |
+ g_dbus_connection_unregister_object (connection, id);
|
|
|
a85faa |
g_hash_table_remove (priv->connections, connection);
|
|
|
a85faa |
}
|
|
|
a85faa |
}
|
|
|
a85faa |
diff --git a/src/nm-bus-manager.c b/src/nm-bus-manager.c
|
|
|
a85faa |
index 449de4e..270792e 100644
|
|
|
a85faa |
--- a/src/nm-bus-manager.c
|
|
|
a85faa |
+++ b/src/nm-bus-manager.c
|
|
|
a85faa |
@@ -221,7 +221,11 @@ private_server_new_connection (GDBusServer *server,
|
|
|
a85faa |
|
|
|
a85faa |
_LOGD ("(%s) accepted connection %p on private socket", s->tag, conn);
|
|
|
a85faa |
|
|
|
a85faa |
- /* Emit this for the manager */
|
|
|
a85faa |
+ /* Emit this for the manager.
|
|
|
a85faa |
+ *
|
|
|
a85faa |
+ * It is essential to do this from the "new-connection" signal handler, as
|
|
|
a85faa |
+ * at that point no messages from the connection are yet processed
|
|
|
a85faa |
+ * (which avoids races with registering objects). */
|
|
|
a85faa |
g_signal_emit (s->manager,
|
|
|
a85faa |
signals[PRIVATE_CONNECTION_NEW],
|
|
|
a85faa |
s->detail,
|
|
|
a85faa |
--
|
|
|
a85faa |
2.7.4
|
|
|
a85faa |
|