2019-09-10 11:19:01 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1+
|
2014-07-24 08:53:33 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-17 14:38:54 +02:00
|
|
|
#include "nm-default.h"
|
2016-02-19 14:57:48 +01:00
|
|
|
|
2014-08-19 09:52:41 -04:00
|
|
|
#include "nm-dbus-helpers.h"
|
2016-02-12 14:44:52 +01:00
|
|
|
|
2014-07-05 16:23:30 -04:00
|
|
|
#include "nm-dbus-interface.h"
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2014-09-10 13:51:53 -04:00
|
|
|
static GBusType nm_bus = G_BUS_TYPE_SYSTEM;
|
2014-07-24 08:53:33 -04:00
|
|
|
|
2014-09-10 13:51:53 -04:00
|
|
|
GBusType
|
|
|
|
|
_nm_dbus_bus_type (void)
|
2014-07-24 08:53:33 -04:00
|
|
|
{
|
|
|
|
|
static gsize init_value = 0;
|
|
|
|
|
|
|
|
|
|
if (g_once_init_enter (&init_value)) {
|
2014-09-05 12:55:18 -04:00
|
|
|
if (g_getenv ("LIBNM_USE_SESSION_BUS"))
|
2014-09-10 13:51:53 -04:00
|
|
|
nm_bus = G_BUS_TYPE_SESSION;
|
2014-09-05 12:55:18 -04:00
|
|
|
|
2014-07-24 08:53:33 -04:00
|
|
|
g_once_init_leave (&init_value, 1);
|
|
|
|
|
}
|
2014-09-10 13:51:53 -04:00
|
|
|
|
|
|
|
|
return nm_bus;
|
2014-07-24 08:53:33 -04:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 18:01:52 +01:00
|
|
|
/* D-Bus has an upper limit on number of Match rules and it's rather easy
|
|
|
|
|
* to hit as the proxy likes to add one for each object. Let's remove the Match
|
|
|
|
|
* rule the proxy added and ensure a less granular rule is present instead.
|
|
|
|
|
*
|
|
|
|
|
* Also, don't do this immediately since it has a performance penalty.
|
2018-09-15 07:20:54 -04:00
|
|
|
* Still better than losing the signals altogether.
|
2015-11-27 18:01:52 +01:00
|
|
|
*
|
|
|
|
|
* Ideally, we should be able to tell glib not to hook its rules:
|
|
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=758749
|
|
|
|
|
*/
|
2016-10-18 16:35:07 +02:00
|
|
|
void
|
2015-11-27 18:01:52 +01:00
|
|
|
_nm_dbus_proxy_replace_match (GDBusProxy *proxy)
|
|
|
|
|
{
|
|
|
|
|
GDBusConnection *connection = g_dbus_proxy_get_connection (proxy);
|
|
|
|
|
static unsigned match_counter = 1024;
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
char *match;
|
2015-11-27 18:01:52 +01:00
|
|
|
|
|
|
|
|
if (match_counter == 1) {
|
|
|
|
|
/* If we hit the low matches watermark, install a
|
|
|
|
|
* less granular one. */
|
|
|
|
|
g_dbus_connection_call (connection,
|
|
|
|
|
"org.freedesktop.DBus",
|
|
|
|
|
"/org/freedesktop/DBus",
|
|
|
|
|
"org.freedesktop.DBus",
|
|
|
|
|
"AddMatch",
|
|
|
|
|
g_variant_new ("(s)", "type='signal',sender='" NM_DBUS_SERVICE "'"),
|
|
|
|
|
NULL,
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match_counter)
|
|
|
|
|
match_counter--;
|
|
|
|
|
if (match_counter)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Remove what this proxy added. */
|
|
|
|
|
match = g_strdup_printf ("type='signal',sender='" NM_DBUS_SERVICE "',"
|
|
|
|
|
"interface='%s',path='%s'",
|
|
|
|
|
g_dbus_proxy_get_interface_name (proxy),
|
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
|
g_dbus_connection_call (connection,
|
|
|
|
|
"org.freedesktop.DBus",
|
|
|
|
|
"/org/freedesktop/DBus",
|
|
|
|
|
"org.freedesktop.DBus",
|
|
|
|
|
"RemoveMatch",
|
|
|
|
|
g_variant_new ("(s)", match),
|
|
|
|
|
NULL,
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (match);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-10 13:51:53 -04:00
|
|
|
/* Binds the properties on a generated server-side GDBus object to the
|
|
|
|
|
* corresponding properties on the public object.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_nm_dbus_bind_properties (gpointer object, gpointer skeleton)
|
|
|
|
|
{
|
|
|
|
|
GParamSpec **properties;
|
|
|
|
|
guint n_properties;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (skeleton), &n_properties);
|
|
|
|
|
for (i = 0; i < n_properties; i++) {
|
|
|
|
|
if (g_str_has_prefix (properties[i]->name, "g-"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
g_object_bind_property (object, properties[i]->name,
|
|
|
|
|
skeleton, properties[i]->name,
|
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
|
|
|
}
|
2015-02-08 13:30:54 +01:00
|
|
|
g_free (properties);
|
2014-09-10 13:51:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
signal_name_from_method_name (const char *method_name)
|
|
|
|
|
{
|
|
|
|
|
GString *signal_name;
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
signal_name = g_string_new ("handle");
|
|
|
|
|
for (p = method_name; *p; p++) {
|
|
|
|
|
if (g_ascii_isupper (*p))
|
|
|
|
|
g_string_append_c (signal_name, '-');
|
|
|
|
|
g_string_append_c (signal_name, g_ascii_tolower (*p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_string_free (signal_name, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_nm_dbus_method_meta_marshal (GClosure *closure, GValue *return_value,
|
|
|
|
|
guint n_param_values, const GValue *param_values,
|
|
|
|
|
gpointer invocation_hint, gpointer marshal_data)
|
|
|
|
|
{
|
|
|
|
|
closure->marshal (closure, return_value, n_param_values,
|
|
|
|
|
param_values, invocation_hint,
|
|
|
|
|
((GCClosure *)closure)->callback);
|
|
|
|
|
|
|
|
|
|
g_value_set_boolean (return_value, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Takes (method_name, handler_func) pairs and connects the handlers to the
|
|
|
|
|
* signals on skeleton, with object as the user_data, but swapped so it comes
|
|
|
|
|
* first in the argument list, and handling the return value automatically.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
_nm_dbus_bind_methods (gpointer object, gpointer skeleton, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
const char *method_name;
|
|
|
|
|
char *signal_name;
|
|
|
|
|
GCallback handler;
|
|
|
|
|
GClosure *closure;
|
|
|
|
|
|
|
|
|
|
va_start (ap, skeleton);
|
|
|
|
|
while ( (method_name = va_arg (ap, const char *))
|
|
|
|
|
&& (handler = va_arg (ap, GCallback))) {
|
|
|
|
|
signal_name = signal_name_from_method_name (method_name);
|
|
|
|
|
closure = g_cclosure_new_swap (handler, object, NULL);
|
|
|
|
|
g_closure_set_meta_marshal (closure, NULL, _nm_dbus_method_meta_marshal);
|
|
|
|
|
g_signal_connect_closure (skeleton, signal_name, closure, FALSE);
|
|
|
|
|
g_free (signal_name);
|
|
|
|
|
}
|
|
|
|
|
va_end (ap);
|
2014-09-10 09:29:51 -04:00
|
|
|
}
|