Commit Graph

94 Commits

Author SHA1 Message Date
Thomas Haller
1b448aeb30 all: use nm_utils_gbytes_equal_mem() 2018-08-30 11:17:09 +02:00
Thomas Haller
e1c7a2b5d0 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 12:02:06 +02:00
Lubomir Rintel
1c0aa397b3 libnm: correctly demarshall (u)int64 values 2018-06-15 16:23:30 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
19876b4cfe shared: drop duplicate c-list.h header
Use the one from the project just imported.
2018-04-18 15:22:14 +02:00
Benjamin Berg
26c215e22d Add calls to g_simple_async_result_set_check_cancellable
If an operation is cancelled through the GCancellable, then the idiom is
that the operation is always cancelled, even if it has finished
successfully. To ensure this is the case, add calls to
g_simple_async_result_set_check_cancellable everywhere.

Without this, e.g. gnome-control-center will crash when switching away
from the power panel quickly, as the NMClient creation finishes
asynchronously and g-c-c assume that G_IO_ERROR_CANCELLED is returned to
ensure it doesn't access the now invalid user_data parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=794088
2018-03-08 14:52:45 +01:00
Thomas Haller
aed6e28461 trivial: avoid XXX tag and replace by NOTE or FIXME
XXX was used to either raise attention (NOTE) or to indicate
that this is ugly code that should be fixed (FIXME). The usage
was inconsistent.

Let's avoid XXX and use either NOTE or FIXME.
2018-01-23 12:55:33 +01:00
Thomas Haller
b6efac9ec2 c-list: re-import latest version of c-list.h from upstream
Most notably, it renames
  c_list_unlink_init() -> c_list_unlink()
  c_list_unlink() -> c_list_unlink_stale()

  $ sed -e 's/\<c_list_unlink\>/c_list_unlink_old/g' \
        -e 's/\<c_list_unlink_init\>/c_list_unlink/g' \
        -e 's/\<c_list_unlink_old\>/c_list_unlink_stale/g' \
        $(git grep -l c_list_unlink -- ':(exclude)shared/nm-utils/c-list.h') \
        -i
2017-11-28 11:26:39 +01:00
Thomas Haller
a6be2f4aa9 all: use nm_str_hash() instead of g_str_hash()
We also do this for libnm and libnm-core, where it causes visible changes
in behavior. But if somebody would rely on the hashing implementation
for hash tables, it would be seriously flawed.
2017-11-16 11:49:52 +01:00
Beniamino Galvani
cba9614298 libnm: don't invert order in array properties
The order of elements in array properties was inverted when
reconstructing the array. Keep the original order from D-Bus.

(cherry picked from commit c90118ff60)
2017-11-09 10:33:18 +01:00
Thomas Haller
357fd6ba82 libnm: remove property getter for NMObject's "dbus-object" and "dbus-object-manager"
These properties are internal and shall not be publicly accessible.
Remove the getter.

We may later no longer use GDBusObjectManager. It should be an implementation
detail, not exposed in the public API of NMObject.
2017-06-19 17:20:34 +02:00
Thomas Haller
59e31ab6ea libnm: cleanup argument types for init_if() function
We use init_if() as handler for g_list_foreach(). Since we already
cast the function pointer because it doesn't have (GFunc) signature,
we can just as well use the correct types right away.
2017-05-27 11:38:38 +02:00
Thomas Haller
e6744bcb65 libnm: fix type for "notify_id" source id in "nm-object.c" 2017-05-11 18:26:10 +02:00
Thomas Haller
d6c1e565ff libnm: remove unused code reload_results and reload_error from "nm-object.c"
Fixes: 1f5b48a59e
2017-05-11 18:26:10 +02:00
Thomas Haller
65b440c9fa libnm: use CList instead of GSList for pending in "nm-object.c" 2017-05-11 18:26:10 +02:00
Thomas Haller
35f37151df libnm: use CList instead of GSList for notify_items in "nm-object.c" 2017-05-11 18:26:10 +02:00
Lubomir Rintel
c61c16513e fixup! libnm/active-connection: track reason for state changes 2017-03-17 10:21:19 +01:00
Thomas Haller
ab6e370195 all/trivial: unify construct-only property comments
Unify marking GObject properties that are G_PARAM_CONSTRUCT_ONLY
with a comment

    /* construct-only */
2017-03-08 13:47:00 +01:00
Thomas Haller
556b7c3b45 libnm: add assertion to NMObject that a dbus-object is set
The libnm cache types don't have public _new() functions.
However, such types can be easily created using g_object_new()
directly from user code.

Such a usage is not supported. Add an assertion that a valid
dbus-object is present.
2017-03-08 08:16:44 +01:00
Beniamino Galvani
4db7890fae cli: support dummy connections 2017-02-22 21:05:04 +01:00
Beniamino Galvani
5ae3db7515 libnm: disconnect signal from D-Bus proxies on dispose
https://bugzilla.gnome.org/show_bug.cgi?id=778615
2017-02-18 10:24:26 +01:00
Thomas Haller
7d6b8bab70 all: use NM_CACHED_QUARK_FCN() instead of G_DEFINE_QUARK()
I think NM_CACHED_QUARK_FCN() is better because:

- the implementation is in our hand, meaning it is clear that
  putting a "static" before NM_CACHED_QUARK_FCN() is guaranteed to
  work -- without relying on G_DEFINE_QUARK() to be defined in a way
  that this works (in fact, we currently never do that and instead
  make all functions non-static).
- it does not construct function names by appending "_quark".
  Thus you can grep for the entire function name and finding
  the place where it is implemented.
- same with the stings, where the new macro doesn't stringify the
  argument, which is less surpising. Again, now you can grep
  for the string including the double quoting.

(yes, I really use grep to understand the source-code)
2017-02-10 14:33:52 +01:00
Lubomir Rintel
0822cbb032 libnm/object: lower the severity of the dangling object warning
The user can't do much about it and we can recover. This is a temporary
measure to avoid unnecessarily bothering the user.

(cherry picked from commit 7fec0755c9)
2017-01-19 16:15:42 +01:00
Lubomir Rintel
4b7b518958 libnm: avoid leaking the interface proxies
_nm_object_get_proxy()'s semantics changed with the object-manager
branch merge: it now takes a reference.
2016-11-14 20:22:23 +01:00
Lubomir Rintel
32d60ccc6f libnm/nm-object: gracefully skip unknown objects
They indicate a server bug (a dangling path of an object that does not
exist). The best we can do probably is to just ignore them and warn.

Based-on-patch-by: Dan Williams <dcbw@redhat.com>
2016-11-11 17:57:09 +01:00
Lubomir Rintel
1f5b48a59e libnm: use the o.fd.DBus.ObjectManager API for object management
This speeds up the initial object tree load significantly. Also, it
reduces the object management complexity by shifting the duties to
GDBusObjectManager.

The lifetime of all NMObjects is now managed by the NMClient via the
object manager. The NMClient creates the NMObjects for GDBus objects,
triggers the initialization and serves as an object registry (replaces
the nm-cache).

The ObjectManager uses the o.fd.DBus.ObjectManager API to learn of the
object creation, removal and property changes. It takes care of the
property changes so that we don't have to and lets us always see a
consistent object state.  Thus at the time we learn of a new object we
already know its properties.

The NMObject unfortunately can't be made synchronously initializable as
the NMRemoteConnection's settings are not managed with standard
o.fd.DBus Properties and ObjectManager APIs and thus are not known to
the ObjectManager.  Thus most of the asynchronous object property
changing code in nm-object.c is preserved. The objects notify the
properties that reference them of their initialization in from their
init_finish() methods, thus the asynchronously created objects are not
allowed to fail creation (or the dependees would wait forever). Not a
problem -- if a connection can't get its Settings, it's either invisible
or being removed (presumably we'd learn of the removal from the object
manager soon).

The NMObjects can't be created by the object manager itself, since we
can't determine the resulting object type in proxy_type() yet (we can't
tell from the name and can't access the interface list). Therefore the
GDBusObject is coupled with a NMObject later on.

Lastly, now that all the objects are managed by the object manager, the
NMRemoteSettings and NMManager go away when the daemon is stopped. The
complexity of dealing with calls to NMClient that would require any of
the resources that these objects manage (connection or device lists,
etc.) had to be moved to NMClient. The bright side is that his allows
for removal all of the daemon presence tracking from NMObject.
2016-11-10 16:48:48 +01:00
Lubomir Rintel
7007c9853c libnm: order the property updates
Don't let a later property update finish than the sooner one.

This wouldn't happen most of time, apart from a special case when the
latter update of a object array property is to an empty list.
In that case the latter update would complete sooner and when the
earlier update finishes the list would contain objects which are
supposed to be gone already.
2016-11-10 16:48:47 +01:00
Lubomir Rintel
df46c59775 nm-object: initialize the object buffer to zero 2016-11-10 16:48:47 +01:00
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Beniamino Galvani
f4a0ab757f libnm: make waiting objects fail when an object initialization fails
Previously, when the load of an object failed and there were other
objects waiting for it, those objects would remain waiting
forever. Make them fail as well.
2016-09-09 16:40:53 +02:00
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