diff options
author | Dan Winship <danw@gnome.org> | 2012-06-18 12:07:26 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-04-24 09:15:54 -0400 |
commit | 3893f71f6d430f08aa7083b312a11c877a44507b (patch) | |
tree | 4613c8ef98a7ea8710b32905f5d90ed24bef02e7 | |
parent | 3c4dd1f7e2336b07f6c0bdd24bfe2b3513a26892 (diff) | |
download | NetworkManager-3893f71f6d430f08aa7083b312a11c877a44507b.tar.gz |
ifcfg-rh: port this from dbus-glib to gdbus
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/Makefile.am | 23 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml | 45 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/plugin.c | 210 |
5 files changed, 155 insertions, 133 deletions
diff --git a/.gitignore b/.gitignore index 3b9d587b9d..99f5a2e49b 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ initscript/*/[Nn]etwork[Mm]anager *-glue.h *-bindings.h +*-generated.[ch] callouts/tests/test-dispatcher-envp libnm-glib/libnm-glib-test libnm-glib/nm-glib-marshal.* diff --git a/configure.ac b/configure.ac index 6fa6569973..e80e466a8f 100644 --- a/configure.ac +++ b/configure.ac @@ -234,7 +234,6 @@ dnl G_ENCODE_VERSION(2,34) here rather than GLIB_VERSION_2_34, because dnl GLib 2.32 did not handle future version defines correctly. GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 '-DGLIB_VERSION_MAX_ALLOWED=G_ENCODE_VERSION(2,34)'" - AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) @@ -242,6 +241,14 @@ PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= 165) AC_SUBST(GUDEV_CFLAGS) AC_SUBST(GUDEV_LIBS) +PKG_CHECK_MODULES(GIO, gio-2.0) +AC_SUBST(GIO_CFLAGS) +AC_SUBST(GIO_LIBS) + +PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0) +AC_SUBST(GIO_UNIX_CFLAGS) +AC_SUBST(GIO_UNIX_LIBS) + GOBJECT_INTROSPECTION_CHECK([0.9.6]) # Qt4 diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index 8b1d3947bd..eb544788cf 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -2,11 +2,19 @@ SUBDIRS = . tests @GNOME_CODE_COVERAGE_RULES@ -nm-ifcfg-rh-glue.h: nm-ifcfg-rh.xml - $(AM_V_GEN) dbus-binding-tool --prefix=nm_ifcfg_rh --mode=glib-server --output=$@ $< +# Work around bad generated code +AM_CFLAGS = $(filter-out @AM_CFLAGS@,-Wfloat-equal) + +nm-ifcfg-rh-generated.h nm-ifcfg-rh-generated.c: nm-ifcfg-rh.xml + $(AM_V_GEN) gdbus-codegen \ + --generate-c-code nm-ifcfg-rh-generated \ + --c-namespace=NM \ + --c-generate-object-manager \ + $< BUILT_SOURCES = \ - nm-ifcfg-rh-glue.h + nm-ifcfg-rh-generated.h \ + nm-ifcfg-rh-generated.c pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la @@ -51,12 +59,15 @@ libifcfg_rh_io_la_LIBADD = \ libnm_settings_plugin_ifcfg_rh_la_SOURCES = \ plugin.c \ plugin.h \ + nm-ifcfg-rh-generated.c \ + nm-ifcfg-rh-generated.h \ nm-ifcfg-connection.c \ nm-ifcfg-connection.h libnm_settings_plugin_ifcfg_rh_la_CPPFLAGS = \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ -DSYSCONFDIR=\"$(sysconfdir)\" libnm_settings_plugin_ifcfg_rh_la_LDFLAGS = -module -avoid-version @@ -64,7 +75,9 @@ libnm_settings_plugin_ifcfg_rh_la_LIBADD = \ $(top_builddir)/libnm-util/libnm-util.la \ $(top_builddir)/libnm-glib/libnm-glib.la \ libifcfg-rh-io.la \ - $(GLIB_LIBS) + $(GLIB_LIBS) \ + $(GMODULE_LIBS) \ + $(GIO_UNIX_LIBS) dbusservicedir = $(DBUS_SYS_DIR) dbusservice_DATA = nm-ifcfg-rh.conf diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml b/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml index 5279345297..8e7e585a98 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.xml @@ -1,31 +1,28 @@ <?xml version="1.0" encoding="UTF-8" ?> -<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> - <interface name="com.redhat.ifcfgrh1"> - <tp:docstring> - Utility methods for handling NM integration with standard Red Hat ifcfg files. - </tp:docstring> +<node name="/"> + <!-- + com.redhat.ifcfgrh1: + @short_description: Utility methods for handling NM integration with standard Red Hat + ifcfg files. + --> + <interface name="com.redhat.ifcfgrh1"> + <annotation name="org.gtk.GDBus.C.Name" value="Ifcfg_RH"/> + <!-- + GetIfcfgDetails: + @ifcfg: The full path to an ifcfg file. + @uuid: The UUID of the NM connection backed by this ifcfg file. If the ifcfg + file does not contain a UUID tag, this UUID is generated by NM, otherwise the + UUID from the ifcfg file is used. + @path: The object path of the NM connected backed by this ifcfg file. + + Given an ifcfg file, return various internal information about it. + --> <method name="GetIfcfgDetails"> - <tp:docstring> - Given an ifcfg file, return various internal information about it. - </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ifcfgrh_get_ifcfg_details"/> - <arg name="ifcfg" type="s" direction="in"> - <tp:docstring> - The full path to an ifcfg file. - </tp:docstring> - </arg> - <arg name="uuid" type="s" direction="out"> - <tp:docstring> - The UUID of the NM connection backed by this ifcfg file. If the ifcfg file does not contain a UUID tag, this UUID is generated by NM, otherwise the UUID from the ifcfg file is used. - </tp:docstring> - </arg> - <arg name="path" type="o" direction="out"> - <tp:docstring> - The object path of the NM connected backed by this ifcfg file. - </tp:docstring> - </arg> + <arg name="ifcfg" type="s" direction="in" /> + <arg name="uuid" type="s" direction="out" /> + <arg name="path" type="o" direction="out" /> </method> </interface> </node> diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index 81fff6c801..c61ea72098 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -33,14 +33,9 @@ #include <glib/gi18n.h> #include <gio/gio.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> - #include <nm-setting-connection.h> #include "common.h" -#include "nm-dbus-glib-types.h" #include "plugin.h" #include "nm-system-config-interface.h" #include "nm-settings-error.h" @@ -51,16 +46,10 @@ #include "writer.h" #include "utils.h" -#define DBUS_SERVICE_NAME "com.redhat.ifcfgrh1" -#define DBUS_OBJECT_PATH "/com/redhat/ifcfgrh1" - -static gboolean impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, - const char *in_ifcfg, - const char **out_uuid, - const char **out_path, - GError **error); +#include "nm-ifcfg-rh-generated.h" -#include "nm-ifcfg-rh-glue.h" +#define NM_IFCFG_RH_SERVICE_NAME "com.redhat.ifcfgrh1" +#define NM_IFCFG_RH_OBJECT_PATH "/com/redhat/ifcfgrh1" static void connection_new_or_changed (SCPluginIfcfg *plugin, const char *path, @@ -87,7 +76,8 @@ typedef struct { GFileMonitor *ifcfg_monitor; guint ifcfg_monitor_id; - DBusGConnection *bus; + guint owner_id; + NMIfcfgRH *dbus_ifcfg; } SCPluginIfcfgPrivate; @@ -573,65 +563,63 @@ hostname_changed_cb (GFileMonitor *monitor, } static gboolean -impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, - const char *in_ifcfg, - const char **out_uuid, - const char **out_path, - GError **error) +handle_get_ifcfg_details (NMIfcfgRH *object, + GDBusMethodInvocation *invocation, + const gchar *ifcfg, + gpointer user_data) { + SCPluginIfcfg *plugin = user_data; SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); NMIfcfgConnection *connection; NMSettingConnection *s_con; const char *uuid; const char *path; - if (!g_path_is_absolute (in_ifcfg)) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg path '%s' is not absolute", in_ifcfg); - return FALSE; + if (!g_path_is_absolute (ifcfg)) { + g_dbus_method_invocation_return_error (invocation, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg path '%s' is not absolute", ifcfg); + return TRUE; } - connection = g_hash_table_lookup (priv->connections, in_ifcfg); + connection = g_hash_table_lookup (priv->connections, ifcfg); if (!connection || nm_ifcfg_connection_get_unmanaged_spec (connection)) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INVALID_CONNECTION, - "ifcfg file '%s' unknown", in_ifcfg); - return FALSE; + g_dbus_method_invocation_return_error (invocation, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "ifcfg file '%s' unknown", ifcfg); + return TRUE; } s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); if (!s_con) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, - "unable to retrieve the connection setting"); - return FALSE; + g_dbus_method_invocation_return_error (invocation, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INTERNAL_ERROR, + "unable to retrieve the connection setting"); + return TRUE; } uuid = nm_setting_connection_get_uuid (s_con); if (!uuid) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, - "unable to get the UUID"); - return FALSE; + g_dbus_method_invocation_return_error (invocation, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INTERNAL_ERROR, + "unable to get the UUID"); + return TRUE; } path = nm_connection_get_path (NM_CONNECTION (connection)); if (!path) { - g_set_error (error, - NM_SETTINGS_ERROR, - NM_SETTINGS_ERROR_INTERNAL_ERROR, - "unable to get the connection D-Bus path"); - return FALSE; + g_dbus_method_invocation_return_error (invocation, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INTERNAL_ERROR, + "unable to get the connection D-Bus path"); + return TRUE; } - *out_uuid = g_strdup (uuid); - *out_path = g_strdup (path); - + nm_ifcfg_rh_complete_get_ifcfg_details (object, invocation, uuid, path); return TRUE; } @@ -641,6 +629,47 @@ init (NMSystemConfigInterface *config) } static void +on_bus_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + SCPluginIfcfg *plugin = user_data; + SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); + GError *error = NULL; + + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_ifcfg), + connection, + NM_IFCFG_RH_OBJECT_PATH, &error); + if (error) { + PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Couldn't export NMIfcfgRH object: %s", + error->message); + g_error_free (error); + } +} + +static gboolean ever_acquired_name = FALSE; + +static void +on_name_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Acquired D-Bus name '%s'", NM_IFCFG_RH_SERVICE_NAME); + ever_acquired_name = TRUE; +} + +static void +on_name_lost (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + if (ever_acquired_name) + PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Lost D-Bus name '%s'", NM_IFCFG_RH_SERVICE_NAME); + else + PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Could not acquire D-Bus name '%s'", NM_IFCFG_RH_SERVICE_NAME); +} + +static void sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) { SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); @@ -672,45 +701,17 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) priv->hostname = plugin_get_hostname (plugin); - priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (!priv->bus) { - PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Couldn't connect to D-Bus: %s", - error->message); - g_clear_error (&error); - } else { - DBusConnection *tmp; - DBusGProxy *proxy; - int result; - - tmp = dbus_g_connection_get_connection (priv->bus); - dbus_connection_set_exit_on_disconnect (tmp, FALSE); - - proxy = dbus_g_proxy_new_for_name (priv->bus, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!dbus_g_proxy_call (proxy, "RequestName", &error, - G_TYPE_STRING, DBUS_SERVICE_NAME, - G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { - PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Couldn't acquire D-Bus service: %s", - error->message); - g_clear_error (&error); - } else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Couldn't acquire ifcfgrh1 D-Bus service (already taken)"); - } else - success = TRUE; - } - - if (!success) { - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } - } + priv->dbus_ifcfg = nm_ifcfg_rh_skeleton_new (); + g_signal_connect (priv->dbus_ifcfg, "handle-get-ifcfg-details", + G_CALLBACK (handle_get_ifcfg_details), plugin); + + priv->owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, + NM_IFCFG_RH_SERVICE_NAME, + 0, + on_bus_acquired, + on_name_acquired, + on_name_lost, + plugin, NULL); } static void @@ -720,9 +721,17 @@ dispose (GObject *object) SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); NMInotifyHelper *ih; - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; + if (priv->owner_id) { + g_bus_unown_name (priv->owner_id); + priv->owner_id = 0; + } + + if (priv->dbus_ifcfg) { + g_signal_handlers_disconnect_by_func (priv->dbus_ifcfg, + G_CALLBACK (handle_get_ifcfg_details), + plugin); + g_object_unref (priv->dbus_ifcfg); + priv->dbus_ifcfg = NULL; } if (priv->ih_event_id) { @@ -744,9 +753,12 @@ dispose (GObject *object) } g_free (priv->hostname); + priv->hostname = NULL; - if (priv->connections) + if (priv->connections) { g_hash_table_destroy (priv->connections); + priv->connections = NULL; + } if (priv->ifcfg_monitor) { if (priv->ifcfg_monitor_id) @@ -754,6 +766,7 @@ dispose (GObject *object) g_file_monitor_cancel (priv->ifcfg_monitor); g_object_unref (priv->ifcfg_monitor); + priv->ifcfg_monitor = NULL; } G_OBJECT_CLASS (sc_plugin_ifcfg_parent_class)->dispose (object); @@ -836,9 +849,6 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class) g_object_class_override_property (object_class, NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME, NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (req_class), - &dbus_glib_nm_ifcfg_rh_object_info); } static void @@ -855,16 +865,10 @@ G_MODULE_EXPORT GObject * nm_system_config_factory (void) { static SCPluginIfcfg *singleton = NULL; - SCPluginIfcfgPrivate *priv; if (!singleton) { singleton = SC_PLUGIN_IFCFG (g_object_new (SC_TYPE_PLUGIN_IFCFG, NULL)); - priv = SC_PLUGIN_IFCFG_GET_PRIVATE (singleton); - if (priv->bus) - dbus_g_connection_register_g_object (priv->bus, - DBUS_OBJECT_PATH, - G_OBJECT (singleton)); - PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Acquired D-Bus service %s", DBUS_SERVICE_NAME); + PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Acquired D-Bus service %s", NM_IFCFG_RH_SERVICE_NAME); } else g_object_ref (singleton); |