Commit Graph

25 Commits

Author SHA1 Message Date
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
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
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
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
Lubomir Rintel
604711488d libnm: avoid loosing signals
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.

Ideally, we should be able to tell glib not to hook its rules.
Related: https://bugzilla.gnome.org/show_bug.cgi?id=758749

https://bugzilla.gnome.org/show_bug.cgi?id=758751
2015-12-01 14:51:13 +01:00
Lubomir Rintel
2146c60996 libnm: stop using the private socket 2015-11-18 15:15:04 +01: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
Lubomir Rintel
4a4f703c94 libnm,dbus-helpers: include glib-compat for g_test_initialized() 2015-05-26 14:17:31 +02:00
Lubomir Rintel
02e3d6c286 tests: don't try to connect to the private socket
Even if we're running the tests as root we still want to use the mock
service instead of whatever version of daemon runs on the test host.
2015-05-26 13:51:45 +02:00
Thomas Haller
1567a9f712 libnm: fix memleak in _nm_dbus_bind_properties() 2015-02-09 11:51:05 +01: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 Winship
3adc2b800a libnm: drop _nm_dbus_register_error_domain()
All D-Bus error domains are registered from libnm-core now.
2014-10-22 08:29:10 -04:00
Thomas Haller
97b2c1b0d1 libnm: share private DBUS connection
Cache the private DBUS connection and reuse it. Otherwise we end up
creating several private connnections, as an NMObject instance creates
a new connection (unless it is passed in as NMObject:dbus-connection
property).

We already pass the existing "parent" DBUS connection when creating
the proxy objects. However, when creating two independent objects
(e.g. nm_client_new() and nm_remote_settings_new()), their private
DBUS connections were not shared.

Implement this sharing inside nm-dbus-helpers.c

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:40 +02:00
Dan Winship
f6f79aa433 libnm: simplify private D-Bus connection tracking
dcbw points out that g_dbus_connection_get_unique_name() can be used
to distinguish private from bus connections without us needing to keep
track ourselves.
2014-09-19 10:45:12 -04:00
Dan Winship
8f7b1e87c2 libnm: fix private bus async codepaths
_nm_dbus_new_connection_async() wasn't marking the connection as
private when it was private, causing
_nm_dbus_new_proxy_for_connection*() to pass the wrong args. Fix that.
2014-09-19 10:35:04 -04:00
Lubomir Rintel
5f54ed3a27 libnm: avoid init_async NULL dereference on cancellable=0x0
(gdb) run c add type bond
  Starting program: /usr/bin/nmcli c add type bond
  Got object file from memory but can't read symbols: File truncated.
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib64/libthread_db.so.1".
  [New Thread 0x7ffff39b2700 (LWP 13042)]
  [New Thread 0x7fffec4bc700 (LWP 13043)]

  (process:13038): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed

  Program received signal SIGTRAP, Trace/breakpoint trap.
  g_logv (log_domain=0x7ffff5cda224 "GLib-GObject", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd290) at gmessages.c:1046
  1046              g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
  (gdb) bt
  #0  0x00007ffff59b6c70 in g_logv (log_domain=0x7ffff5cda224 "GLib-GObject", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd290) at gmessages.c:1046
  #1  0x00007ffff59b6eaf in g_log (log_domain=log_domain@entry=0x7ffff5cda224 "GLib-GObject", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff5a25a9d "%s: assertion '%s' failed")
      at gmessages.c:1079
  #2  0x00007ffff59b6ee9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7ffff5cda224 "GLib-GObject", pretty_function=pretty_function@entry=0x7ffff5cdd6b3 <__FUNCTION__.13314> "g_object_ref", expression=expression@entry=0x7ffff5cdc388 "G_IS_OBJECT (object)") at gmessages.c:1088
  #3  0x00007ffff5cb39aa in g_object_ref (_object=_object@entry=0x0) at gobject.c:3041
  #4  0x00007ffff7ad5418 in _nm_dbus_new_connection_async (cancellable=0x0, callback=<optimized out>, user_data=<optimized out>) at nm-dbus-helpers.c:131
  #5  0x00007ffff7ae58f1 in handle_property_changed (synchronously=0, pi=0x5555558a9610, value=0x7fffe40138a0, property_name=<optimized out>, self=0x555555831980 [NMRemoteSettings]) at nm-object.c:1115
  #6  0x00007ffff7ae58f1 in handle_property_changed (self=self@entry=0x555555831980 [NMRemoteSettings], dbus_name=<optimized out>, value=<optimized out>, synchronously=synchronously@entry=0) at nm-object.c:1186
  #7  0x00007ffff7ae59cb in process_properties_changed (self=0x555555831980 [NMRemoteSettings], properties=<optimized out>, synchronously=0) at nm-object.c:1218
  #8  0x00007ffff7ae5a7a in property_proxy_signal (proxy=<optimized out>, sender_name=<optimized out>, signal_name=<optimized out>, parameters=<optimized out>, user_data=0x555555831980) at nm-object.c:1234
  #9  0x00007ffff4d34d60 in ffi_call_unix64 () at ../src/x86/unix64.S:76
  #10 0x00007ffff4d347d1 in ffi_call (cif=cif@entry=0x7fffffffd7e0, fn=<optimized out>, rvalue=0x7fffffffd740, avalue=avalue@entry=0x7fffffffd6c0) at ../src/x86/ffi64.c:525
  #15 0x00007ffff5cca2ef in <emit signal ??? on instance 0x555555881c10 [NMDBusSettingsProxy]> (instance=instance@entry=0x555555881c10, signal_id=<optimized out>, detail=detail@entry=0) at gsignal.c:3365
      #11 0x00007ffff5caf6f4 in g_cclosure_marshal_generic (closure=0x5555558aa400, return_gvalue=0x0, n_param_values=<optimized out>, param_values=<optimized out>, invocation_hint=<optimized out>, marshal_data=0x0) at gclosure.c:1448
      #12 0x00007ffff5caeed5 in g_closure_invoke (closure=0x5555558aa400, return_value=return_value@entry=0x0, n_param_values=4, param_values=param_values@entry=0x7fffffffda10, invocation_hint=invocation_hint@entry=0x7fffffffd9b0) at gclosure.c:768
      #13 0x00007ffff5cc1202 in signal_emit_unlocked_R (node=node@entry=0x555555819270, detail=detail@entry=0, instance=instance@entry=0x555555881c10, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffda10) at gsignal.c:3553
      #14 0x00007ffff5cca0c1 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7fffffffdbd0) at gsignal.c:3309
  #16 0x00007ffff63d8bcc in on_signal_received (connection=<optimized out>, sender_name=0x0, object_path=<optimized out>, interface_name=<optimized out>, signal_name=0x7fffe40195b0 "PropertiesChanged", parameters=0x7fffe4031000, user_data=0x5555558a3f30) at gdbusproxy.c:917
  #17 0x00007ffff63c83b4 in emit_signal_instance_in_idle_cb (data=0x7fffe403a6d0) at gdbusconnection.c:3753
  #18 0x00007ffff59afb6b in g_main_context_dispatch (context=0x5555557eb530) at gmain.c:3064
  #19 0x00007ffff59afb6b in g_main_context_dispatch (context=context@entry=0x5555557eb530) at gmain.c:3663
  #20 0x00007ffff59aff08 in g_main_context_iterate (context=0x5555557eb530, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3734
  #21 0x00007ffff59b0232 in g_main_loop_run (loop=0x5555557e3440) at gmain.c:3928
  #22 0x000055555556fd57 in main (argc=<optimized out>, argv=<optimized out>) at nmcli.c:587
  (gdb)

https://bugzilla.gnome.org/show_bug.cgi?id=736962
2014-09-19 08:33:15 -04: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
b732380d1e libnm: drop NMObject:dbus-connection
The only plausible use case for the NMObject:dbus-connection property
is for using the session bus in test programs. So just drop it and use
an environment variable to decide which bus to use instead.
2014-09-09 12:10:13 -04:00
Dan Winship
a874e0beac libnm: assert that dbus_connection_allocate_data_slot() doesn't fail
dbus_connection_allocate_data_slot() can only fail on ENOMEM, in which
case the immediately-following call to g_set_error() would also get
ENOMEM and abort. So just simplify and assert that the libdbus call
didn't fail.
2014-09-09 12:10:13 -04:00
Dan Winship
3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
2014-08-01 14:34:40 -04:00
Dan Winship
d595f7843e libnm: add libnm/libnm-core (part 1)
This commit begins creating the new "libnm", which will replace
libnm-util and libnm-glib.

The main reason for the libnm-util/libnm-glib split is that the daemon
needs to link to libnm-util (to get NMSettings, NMConnection, etc),
but can't link to libnm-glib (because it uses many of the same type
names as the NetworkManager daemon. eg, NMDevice). So the daemon links
to only libnm-util, but basically all clients link to both.

With libnm, there will be only a single client-visible library, and
NetworkManager will internally link against a private "libnm-core"
containing the parts that used to be in libnm-util.

(The "libnm-core" parts still need to be in their own directory so
that the daemon can see those header files without also seeing the
ones in libnm/ that conflict with its own headers.)

[This commit just copies the source code from libnm-util/ to
libnm-core/, and libnm-glib/ to libnm/:

  mkdir -p libnm-core/tests/
  mkdir -p libnm/tests/
  cp libnm-util/*.[ch] libnm-util/nm-version.h.in libnm-core/
  rm -f libnm-core/nm-version.h libnm-core/nm-setting-template.[ch] libnm-core/nm-utils-enum-types.[ch]
  cp libnm-util/tests/*.[ch] libnm-core/tests/
  cp libnm-glib/*.[ch] libnm/
  rm -f libnm/libnm_glib.[ch] libnm/libnm-glib-test.c libnm/nm-glib-enum-types.[ch]
  cp libnm-glib/tests/*.[ch] libnm/tests/

]
2014-08-01 14:34:04 -04:00