Commit Graph

64 Commits

Author SHA1 Message Date
Lubomir Rintel
ad8251e3a4 nm-object: delay object property completion until the objects are initialized
We don't want to update the properties until the objects referred are complete.
Otherwise the clients get confused. Very confused:

https://bugzilla.redhat.com/show_bug.cgi?id=1313866

We already delay the notification signals. Let's replace that with delaying the
actual ObjectCreatedData processing instead.
2016-03-14 16:32:44 +01:00
Lubomir Rintel
bb35883235 nm-object: don't leak the properties on changed signals
https://bugzilla.redhat.com/show_bug.cgi?id=1314976
2016-03-08 16:02:27 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Beniamino Galvani
fbd3286955 core,libnm: use nm_clear_g_source() where possible
Replacement was done with commands:

spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir src
spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir libnm

where nm_clear_g_source.cocci contains:

@@
expression e;
@@
- if (e) {
-    g_source_remove (e);
-    e = 0;
- }
+ nm_clear_g_source (&e);
2016-01-06 21:25:55 +01:00
Lubomir Rintel
45c5e7626a libnm,nm-object: only send "notify" signal when the object property actually changed 2015-12-05 12:05:17 +01:00
Lubomir Rintel
8c9b791768 libnm: avoid notifying for objects until they're async-inited
Otherwise the uninitializeded objects could be prematurely signalled if their
paths are seen twice in quick succession. This happens when you have ethernet
hardware and add an ethernet connection -- it's immediatelly added to
AvialableConnections and the property reload signals the object addition
before the NMRemoteSettings's GetSettings() finishes:

  # nmcli c add type ethernet autoconnect no ifname '*'
  (process:4610): libnm-CRITICAL **: nm_connection_get_id: assertion 's_con != NULL' failed
  Connection '(null)' ((null)) successfully added.
  #

https://bugzilla.gnome.org/show_bug.cgi?id=754794
2015-10-06 14:10:55 +02:00
Thomas Haller
6b40108418 libnm: use nm_clear_g_source() in nm-object.c 2015-10-03 18:12:11 +02:00
Thomas Haller
0e5af7fa46 Revert "libnm: don't add objects to cache until they're async-inited"
Reverting, because patch breaks tests for "libnm/tests".

This reverts commit 88f0d646d5.
2015-09-15 23:11:47 +02:00
Lubomir Rintel
88f0d646d5 libnm: don't add objects to cache until they're async-inited
Otherwise the uninitializeded objects could be prematurely signalled if their
paths are seen twice in quick succession. This happens when you have ethernet
hardware and add an ethernet connection -- it's immediatelly added to
AvialableConnections and the property reload signals the object addition
before the NMRemoteSettings's GetSettings() finishes:

  # nmcli c add type ethernet autoconnect no ifname '*'
  (process:4610): libnm-CRITICAL **: nm_connection_get_id: assertion 's_con != NULL' failed
  Connection '(null)' ((null)) successfully added.
  #

https://bugzilla.gnome.org/show_bug.cgi?id=754794
2015-09-15 16:53:26 +02:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Dan Winship
9926ba376a libnm, core: use typechecked proxy_call methods 2015-04-03 16:58:40 -04:00
Dan Winship
1a0bc83c39 libnm, core: use _nm_dbus_signal_connect() 2015-04-03 16:58:40 -04:00
Thomas Haller
2e86c37dd3 trivial: do an assignment before the conditional instead of in both branches
[lkundrak@v3.sk: An improvement suggested in bugzilla, but I failed to apply
it to the commit.]

https://bugzilla.redhat.com/show_bug.cgi?id=1079353
2015-03-16 15:44:14 +01:00
Lubomir Rintel
dba4e8ece8 libnm,nm-object: fix tracing of object removal
When a new connection is activated and presently active connection goes away,
the active-connection-removed signal is not emitted for the old connection.
This is what happens:

1.) Initially, nm-manager::active-connections = [ActiveConnection/old]

2.) First PropertyChange is signalled for the new connection addition:
nm-manager::active-connections = [ActiveConnection/old,ActiveConnection/new]

This triggers load of ActiveConnection/new object.

3.) Another PropertyChange is signalled for the old connection removal:
nm-manager::active-connections = [ActiveConnection/new]

This removes the ActiveConnection/old object from
nm-manager::active-connections and enqueues active-connection-removed
signal. The signal is not emmitted as there's a reload from 2.) in progress.

4.) ActiveConnection/new reload finished

object_property_complete() compares
[ActiveConnection/old,ActiveConnection/new] from its odata to current
nm-manager::active-connections and incorrectly concludes that
ActiveConnection/old was just added and removes the enqueued
active-connection-removed signal.

This patch fixes the issue by remembering the original
nm-manager::active-connections property value at 2.).

[thaller@redhat.com: fixed an integer overflow and odata->array unreffing]

https://bugzilla.redhat.com/show_bug.cgi?id=1079353
2015-03-16 10:54:57 +01:00
Jiří Klimeš
b11416de6a libnm: check pspec before accessing it in handle_property_changed()
Fixes: 1f8ec6122e

Coverity:
libnm/nm-object.c:926: var_deref_op: Dereferencing null pointer "pspec".
libnm/nm-object.c:924: var_deref_op: Dereferencing null pointer "pspec".
2014-12-05 09:38:40 +01:00
Dan Winship
53f5e9afa4 libnm*: fix library gettext usage
Libraries need to include <gi18n-lib.h>, not <gi18n.h>, so that _()
will get defined to "dgettext (GETTEXT_DOMAIN, string)" rather than
"gettext (string)" (which will use the program's default domain, which
works fine for programs in the NetworkManager tree, but not for
external users). Likewise, we need to call bindtextdomain() so that
gettext can find the translations if the library is installed in a
different prefix from the program using it (and
bind_textdomain_codeset(), so it will know the translations are in
UTF-8 even if the locale isn't).

(The fact that no one noticed this was broken before is because the
libraries didn't really start returning useful translated strings much
until 0.9.10, and none of the out-of-tree clients have been updated to
actually show those strings to users yet.)
2014-11-13 17:18:42 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Dan Williams
14537c71d8 libnm-core: emit added/removed signals before property change notifications
Because internal objects do some processing/setup in the various
_added class signal handlers, they need to be emitted before
property change notifications.  Otherwise it leads to situations
where external objects that listen to NMClient property changes
will be called before internal processing has been completed.

Specifically, NMRemoteSettings uses connection_added() to check
connection visibility and assign the new connection to one of
two internal arrays.  If a client got a property notification
for NMClient::connections before NMRemoteSettings can process
the new connection, then nm_client_get_connections() will
return an empty array because NMRemoteSettings hasn't had the
chance to add the new connection to priv->visible yet, which
is done in NMRemoteSettings::connection_added().

Fixes:Beaker:NetworkManager_Test240_nmtui_general_realtime_refresh_edit_screen
2014-11-07 16:58:43 -06:00
Dan Williams
e5827729d6 trivial: make _nm_object_reload_properties() private to nm-object.c 2014-11-06 20:51:58 -06:00
Dan Williams
52ae28f6e5 libnm: queue added/removed signals and suppress uninitialized notifications
Property notifications are queued during object initialization and
reloading, but the added/removed signals were emitted immediately
even before the object was fully initialized.

Additionally, depending on how long asynchronous initialization took,
the notifications could have been emitted before the object was
fully initialized as deferred_notify_cb() wasn't being suppressed
until all the properties were complete.

For synchronous intialization, signals could be emitted at various
times during initialization and not all of the object's properties
may be read.  Furthermore property notifications were queued in an
idle handler, which breaks users that may not use a mainloop.  All
signals and notifications should be emitted immediately after
initialization is complete for synchronous initialization.

To make things consistent and ensure that all signals and notifications
are emitted only when initialization is complete, queue signals for
deferred emission and only run notifications/signals when all the
object's properties have been read.  For synchronous initialization,
emit all notifications and signals immediately after initialization
and not from an idle handler.
2014-11-06 20:51:58 -06:00
Dan Williams
0a0f9a3b4e trivial: re-arrange NMObject class methods
Move class-related and initialization interface related methods to
the bottom.
2014-11-06 20:51:58 -06:00
Dan Williams
648270d469 libnm: cancel NMRemoteSettings/NMManager property reload when NM quits
If the operation isn't canceled it returns an error, printing this:

/libnm/client-nm-running:
(/home/dcbw/Development/fdo/NetworkManager/libnm/tests/.libs/lt-test-nm-client:17983): libnm-WARNING **: updated_properties: error reading NMRemoteSettings properties: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)
/bin/sh: line 5: 17983 Trace/breakpoint trap   ./libnm-test-launch.sh ${dir}$tst
FAIL: test-nm-client

which screws up testcases because they don't expect this message.
And in this case, since libnm knows that NM is exiting and will
just clear out the properties anyway, it's useless to print the message.
2014-11-06 20:51:58 -06:00
Lubomir Rintel
48b4f6f830 Merge branch 'lr/rpm-make-check'
https://bugzilla.gnome.org/show_bug.cgi?id=739127
2014-10-30 14:40:47 +01:00
Lubomir Rintel
5aefbe5658 libnm-core: Don't warn on missing properties
It might simply mean that the object disappeared (which is perfectly fine):

(process:7680): libnm-WARNING **: Could not fetch property 'Vpn' of interface 'org.freedesktop.NetworkManager.Connection.Active' on /org/freedesktop/NetworkManager/ActiveConnection/151: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "Get" with signature "ss" on interface "org.freedesktop.DBus.Properties" doesn't exist

https://bugzilla.gnome.org/show_bug.cgi?id=739255
2014-10-29 10:04:52 +01:00
Lubomir Rintel
4496b69e47 libnm: Ignore NoReply errors when NM has vanished from the bus
This fixes the /libnm/client-nm-running test failure when a race condition is hit:

test-nm-client:10350): libnm-WARNING **: updated_properties:
	error reading NMRemoteSettings properties:
	GDBus.Error:org.freedesktop.DBus.Error.NoReply:
	Message did not receive a reply (timeout by message bus)

What actually happens is that nm_running_changed_cb() calls GetAll() for a
NMRemoteSettings object when NM appears on the bus. If it disappears shortly
afterwards, another nm_running_changed_cb() is called which suppresses further
object updates, but the original GetAll() might not have finished yet and DBus
will generate a NoReply() response for it. We ought to ignore it.
2014-10-24 19:24:32 +02:00
Jiří Klimeš
d51976843d libnm-core: fix a leak in process_properties_changed() 2014-10-23 09:15:58 +02:00
Jiří Klimeš
6354a0e450 all: fix g_dbus_proxy_get_name_owner() leaks 2014-10-23 09:15:58 +02:00
Dan Winship
388a0c5e78 libnm: consolidate NMClientError and NMObjectError
Consolidate NMClientError and NMObjectError (such that there is now
only one libnm-API-specific error domain). In particular, merge
NM_CONNECTION_ERROR_CONNECTION_REMOVED with
NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE as the new
NM_CONNECTION_ERROR_OBJECT_CREATION_FAILED.

Also make object_creation_failed() be a plain method rather than a
signal, since there's no reason for anyone to be connecting to it on
another object. And remove its GError argument because the subclass
can just create its own more-specific error.
2014-10-22 08:29:10 -04:00
Dan Winship
2ff4a7d4b0 libnm: strip GDBus gunk from GErrors
Call g_dbus_error_strip_remote_error() on all errors returned from
gdbus calls. (Blah!)
2014-10-22 08:29:10 -04:00
Dan Winship
1f8ec6122e libnm: fix NMActiveConnection:specific-object-path
NMActiveConnection:specific-object was renamed to
NMActiveConnection:specific-object-path in 677314c5, but it didn't
actually work, because of assumptions NMObject makes. Fix that.
2014-10-21 09:45:20 -04:00
Dan Winship
2ac83c0e8b libnm: fix async property circular reference handling
3e5b3833 changed various libnm methods to return 0-length arrays
rather than NULL, and changed various other places to assume this
behavior. The guarantee that they didn't return NULL relied on the
assumption that all D-Bus properties would get initialized by NMObject
code before anyone could call their get methods.

However, this assumption was violated in the case where two objects
circularly referenced each other (eg, NMDevice and
NMActiveConnection). f9f9d297 attempted to fix this by slightly
changing the ordering of NMObjectCache operations, but it actually
ended up breaking things and causing infinite loops of object creation
in some cases.

There's no way to guarantee we never return partially-initialized
objects without heavily rewriting the object-creation code, so this
reverts most of f9f9d297 (leaving only the new comment in
_nm_object_create()). The crashes introduced by 3e5b3833 will no
longer happen because we've now fixed the classes to have initialized
their object arrays to non-NULL values even before they get the real
values.
2014-10-19 09:26:49 -04:00
Dan Winship
fcfb4b40ba libnm: make use of GParamSpecFlags and GParamSpecEnum
Make enum- and flags-valued properties use GParamSpecEnum and
GParamSpecFlags, for better introspectability/bindability.

This requires no changes outside libnm-core/libnm since the expected
data size is still the same with g_object_get()/g_object_set(), and
GLib will internally convert between int/uint and enum/flags GValues
when using g_object_get_property()/g_object_set_property().
2014-10-03 09:36:28 -04:00
Dan Winship
ad25e5c970 libnm: reorganize demarshal_generic(), make unrecognized type a warning
Redo the HANDLE_TYPE macro in demarshal_generic() in a more
syntactically-sane way (both to help the editor with indentation and
to make it not look so weird).

Also, if demarshal_generic() is asked to handle a property of a type
that it doesn't know how to handle, that's a programmer error, so do a
g_warning() in that case (as opposed to being asked to demarshal a
value of the wrong D-Bus type, which could just be a bug in the peer
that sent the data, so that stays as a debug message).
2014-10-03 09:36:28 -04:00
Dan Winship
5c2d2eed30 libnm: fix properties-changed debug logging
The code was mistakenly still using G_VALUE_TYPE_NAME() instead of
g_variant_get_type_string().

Also, refer to the properties with standard gtk-doc punctuation:
"TypeName:property-name".
2014-10-03 09:36:27 -04:00
Thomas Haller
df57b6b4d1 libnm: add NMObject:dbus-connection property to inject DBUS connection
Commit b732380d1e removed the gobject
property "NMObject:connection". However, this property is still needed
to inject the DBUS connection when creating new proxy objects. Without it,
we call _nm_dbus_new_connection() in the constructor for every proxy NMObject.

In case of non-private connections, g_bus_get_sync() already returns the same
connection. However for private connections, g_dbus_connection_new_for_address_sync()
would create a separate DBUS connection.

https://bugzilla.gnome.org/show_bug.cgi?id=737725

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:17 +02:00
Thomas Haller
284a14d62f libnm: assert for interface name in _nm_object_class_add_interface()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:17 +02:00
Thomas Haller
94331184d8 libnm: remove unused variable NMObjectPrivate:private_connection
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:17 +02:00
Thomas Haller
351cf9b328 libnm: fix warning about returning zero instead of %NULL in _nm_object_create()
clang warns:
    make[4]: Entering directory `./NetworkManager/libnm'
      CC       nm-object.lo
    nm-object.c:640:11: error: expression which evaluates to zero treated as a null pointer constant of type 'GObject *' (aka 'struct _GObject *') [-Werror,-Wnon-literal-null-conversion]
                            return G_TYPE_INVALID;
                                   ^~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:57:26: note: expanded from macro 'G_TYPE_INVALID'
    #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:221:36: note: expanded from macro 'G_TYPE_MAKE_FUNDAMENTAL'
    #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    nm-object.c:655:11: error: expression which evaluates to zero treated as a null pointer constant of type 'GObject *' (aka 'struct _GObject *') [-Werror,-Wnon-literal-null-conversion]
                            return G_TYPE_INVALID;
                                   ^~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:57:26: note: expanded from macro 'G_TYPE_INVALID'
    #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:221:36: note: expanded from macro 'G_TYPE_MAKE_FUNDAMENTAL'
    #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 errors generated.

Fixes: b3c4917b0f
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:32:01 +02:00
Dan Winship
6793a32a8c libnm: port to GDBus
Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
2014-09-18 11:51:09 -04:00
Dan Winship
4750559548 libnm: rename nm-dbus-helpers-private.h to nm-dbus-helpers.h
The .h file should have the same name as the .c file.
2014-09-18 11:51:08 -04:00
Dan Winship
acf4b5a572 libnm: split nm-dbus-helpers utils into sync/async versions
dbus-glib's functions to get a DBusGConnection or a DBusGProxy return
right away, but gdbus's corresponding functions do some initial setup
and communication as part of initialization, and so either block or
run async. So split _nm_dbus_new_connection() and
_nm_dbus_new_proxy_for_connection() into sync and async versions now,
and update NMObject to use the correct one depending on whether it is
working synchronously or asynchronously.
2014-09-18 11:51:08 -04:00
Dan Winship
b3c4917b0f libnm: move most of the subclass-type-deciding code into NMObject
NMObject has a system that lets devices and active connections get
created as the correct subtypes (NMDeviceFoo / NMActiveConnection vs
NMVpnConnection). But it was much more generic than it needed to be,
because NMDevice and NMActiveConnection both did the same thing (fetch
a D-Bus property and then look at its value). So move the
property-fetching part into NMObject, and only use the callback for
converting the property value to a GType.
2014-09-18 11:51:08 -04:00
Dan Winship
b728d1fb70 libnm: let NMObject create all D-Bus proxies
Add _nm_object_class_add_interface(), for declaring that a class
implements a particular interface, and then have NMObject create the
corresponding proxies itself. (The subclass can get a copy with
_nm_object_get_proxy() if it needs it for something).

(In GDBus, creating a proxy is a heavier operation than in dbus-glib,
so we'll need to create the proxies asynchronously. Moving the
creation to NMObject makes that easier since we can do it as part
of the existing init/init_async.)
2014-09-18 11:51:08 -04:00
Dan Winship
aa18b88a4f libnm: don't hardcode things like "org.freedesktop.DBus.Properties"
Use the #defines provided by libdbus instead.
2014-09-18 11:51:08 -04:00
Dan Winship
f9f9d297f8 libnm: fix race conditions when creating the same object twice
If two code paths try to asynchronously create the same object at the
same time (eg, because it shows up in two different properties), we
are supposed to deal with that. But at some point a race condition
appeared where we could end up returning a partially-initialized
object for one of the properties in the async case. Fix that.

Also add comments to both the sync and async cases explaining why they
work the way they do.
2014-09-17 08:21:22 -04:00
Dan Winship
f3c02058d4 libnm: drop two unnecessary NM_IS_OBJECT() checks
Now that NMRemoteConnection is an NMObject, the code only creates
NMObjects, so we don't need that check.
2014-09-17 08:21:22 -04:00