Commit graph

80 commits

Author SHA1 Message Date
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
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
Dan Winship 6265398b6e all: use g_error_matches()
Use g_error_matches() where we're testing error codes. In particular,
use it rather than looking at only ->code and not also ->domain, which
is just wrong.

[thaller@redhat.com: rebase and modify original patch]
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 19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship ee707ba95a libnm-glib: drop private bus support
Anything that actually *needs* private bus support will be built
against libnm these days anyway.
2015-07-24 13:25:47 -04: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 dd0e198955 include: add nm-dbus-compat.h
Add a file containing the defines like DBUS_INTERFACE_DBUS from
dbus-shared.h, and use it from the gdbus-using files.

Also, convert a bunch of other places that were previously hardcoding
the string values to use the defines instead, and fix the ifcfg-rh
plugin to properly namespace its own D-Bus-related defines.
2015-07-24 13:25:47 -04:00
Thomas Haller c157e3233d libnm-glib: avoid coverity warning
5. NetworkManager-1.0.3/libnm-glib/nm-remote-settings.c:493: var_compare_op: Comparing "error" to null implies that "error" might be null.
  8. NetworkManager-1.0.3/libnm-glib/nm-remote-settings.c:508: var_deref_op: Dereferencing null pointer "error".
  #   506|   			g_hash_table_remove (priv->pending, path);
  #   507|
  #   508|-> 		if (print_once && error->code == DBUS_GERROR_LIMITS_EXCEEDED) {
  #   509|   			g_printerr ("Warning: libnm-glib:%s(): a D-Bus limit exceeded: %s. The application might not work properly.\n"
  #   510|   			            "Consider increasing max_replies_per_connection limit in /etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf "
2015-06-25 18:17:19 +02:00
Jiří Klimeš 91a5f4ceb9 libnm-glib: print a bold warning about reaching a D-Bus limit
This causes incorrect application behaviour, so libnm-glib should warn
at least.
2015-05-29 08:04:26 +02:00
Dan Winship b454267761 libnm-glib: crash when NMRemoteSettings is quickly destroyed (bgo #742138)
NMRemoteSettings queues a bunch of async NMRemoteConnection creations,
but wasn't doing anything to ensure that it was still alive when they
completed. Pointed out by Cosimo Cecchi.

https://bugzilla.gnome.org/show_bug.cgi?id=742138
2015-01-05 15:35:57 -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
Florian Müllner 261a3924d3 remote-settings: Mark service as running when using private bus
When using a private bus connection, the service is never marked
as running when settings are initialized asynchronously. Successfully
opening a socket in NM's runtime directory should already imply
a running service, so just mark it as such (as we already do in
the synchronous path).
2014-10-17 09:44:39 -04:00
Dan Winship dafe51e881 libnm-glib: document some properties
Some libnm-glib object properties were only documented in the
GParamSpec strings, not via gtk-doc comments, so they became
undocumented when the paramspec strings went away. Fix that.

(Also fix incorrect gtk-doc syntax with several NMClient properties.)
2014-07-25 09:49:58 -04:00
Dan Winship 2570c5a17c libnm-util, libnm-glib: whitespace fixes
Fix indentation, kill trailing whitespace, split some long lines.
2014-07-15 09:44:55 -04:00
Dan Winship cb7e1893e7 libnm-util, libnm-glib: standardize copyright/license headers
- Remove list of authors from files that had them; these serve no
  purpose except to quickly get out of date (and were only used in
  libnm-util and not libnm-glib anyway).

- Just say "Copyright", not "(C) Copyright" or "Copyright (C)"

- Put copyright statement after the license, not before

- Remove "NetworkManager - Network link manager" from the few files
  that contained it, and "libnm_glib -- Access network status &
  information from glib applications" from the many files that
  contained it.

- Remove vim modeline from nm-device-olpc-mesh.[ch], add emacs modeline
  to files that were missing it.
2014-07-15 09:44:54 -04:00
Dan Winship 4223fa47e4 libnm-util, libnm-glib: tweak (element-type) annotations in docs
g-i allows you to specify types in annotations using either their
fully-qualified introspected names (eg, "NMClient.Device") or their
plain C names ("NMDevice"). Switch from the former to the latter (so
that they'll still be correct when migrated to libnm later).
2014-07-15 09:44:54 -04:00
Dan Winship aa1dce6da2 all: remove remaining GParamSpec name/blurb strings
Remove all remaining GParamSpec name and blurb strings (and fix
indentation while we're there), and add G_PARAM_STATIC_STRINGS to all
paramspecs that were lacking it.
2014-06-19 17:45:03 -04:00
Dan Williams 2200687b0f libnm-glib: add documentation for NMRemoteSettings and connection addition 2014-04-10 10:51:29 -05:00
Jiří Klimeš c2a1cb1a44 docs: use %TRUE, %FALSE macros instead of plain TRUE, FALSE values for gtkdoc 2014-02-24 17:00:39 +01:00
Thomas Haller f76934de15 libnm-glib: add function nm_remote_settings_get_connection_by_id()
Utility function, to search the list of connections for a connection
with a matching id/name. Returns the first match.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-27 15:39:51 -05:00
Dan Winship e9fe63cdaa trivial: annotate/adjust some code to appease Coverity 2014-01-16 14:23:45 -05:00
Jiří Klimeš de36db0af1 libnm-glib: fix return value in nm_remote_settings_load_connections()
when g_return_val_if_fail() fails.
2013-11-18 09:06:23 +01:00
Dan Winship a52ebc74b5 libnm-glib: add nm_remote_settings_load_connections()
https://bugzilla.gnome.org/show_bug.cgi?id=709830
2013-11-15 13:38:48 -05:00
Yuri Chornoivan 61de24ba35 Fix typos
https://bugzilla.gnome.org/show_bug.cgi?id=710505
2013-10-19 11:49:18 -04:00
Dan Winship 1f81851017 core: add monitor-connection-files=false and ReloadConnections
Add a "monitor-connection-files" config option, which can be set to
"false" to disable automatic reloading of connections on file change.

To go with this, add a new ReloadConnections method on
o.fd.NM.Settings that can be used to manually reload connections, and
add an nm-cli command to call it.
2013-06-14 12:57:47 -03:00
Dan Williams c41bd34570 libnm-glib: add support for new connection unsaved functionality 2013-05-28 12:26:56 -05:00
Dan Winship d529580cbb libnm-glib, core: use g_cclosure_marshal_generic
Since we depend on new glib now, we can just use the generic
marshaller rather than generating our own.
2013-05-08 14:59:29 -04:00
Martin Pitt 57a9fb3c89 Use %NULL macro in doc strings
Mass-converted "NULL" to "%NULL" in docstrings with

  find -name '*.c'| xargs sed -i '/^ \*.*[^%]NULL/ s/NULL\b/%NULL/g'
2013-04-19 10:08:17 -04:00
Dan Williams 110a40358d libnm-glib: never call NM D-Bus methods if NM isn't running
Though the client shouldn't be calling anything when NM isn't running
(because clients have nm_client_get_manager_running()), make sure
that NMClient never calls a NetworkManager method when NM isn't
on the bus.

Next, ensure NMObject doesn't try to refresh properties when NM isn't
running.  Creating an NMClient may trigger a property refresh request,
but if NM isn't running, defer that until NM starts, to ensure that
we don't D-Bus autostart NM.

Third, ensure NMRemoteSettings doesn't attempt to list connections
unless NM is running.

This prevents service activation of NetworkManager in lieu of dbus-glib
learning about DBUS_HEADER_FLAG_NO_AUTO_START.
2013-04-08 11:30:32 -05:00
Dan Williams a87b5a15df libnm-glib: use private connection before trying the system bus
Use the D-Bus connection helper whenever we need a connection to
NM, which by default tries to use a private connection instead of
the shared bus connection whenever the user is root.  Doing this
by default will not change the behavior of libnm-glib, and allows
tools like nmcli and libnm-glib-using clients to work in minimal
environments (those without a bus daemon) by default.
2013-04-08 11:30:32 -05:00
Dan Williams 661d09852d libnm-glib: use helpers to create dbus proxies
When using a private connection, we need to use dbus_g_proxy_new_for_peer()
because the bus isn't involved.  Since many parts of libnm-glib create a
proxy for their corresponding remote object, consolidate the proxy creation
logic.

A later patch will add logic to use a private connection versus a bus-based
one.
2013-04-08 11:30:32 -05:00
Dan Winship 6f44b7f3c6 all: remove redundant return-if-fail checks
NM_IS_FOO(x) returns FALSE if x is NULL, so we don't need a separate
(x != NULL) check before it.
2013-03-07 07:32:27 -05:00
Giovanni Campagna 246633a854 NMRemoteSettings: fix async initialization
If async GetProperties completed before the GetConnections, init_left would
be 0 and thus we never connected to connections-read, causing us to terminate
initialization before connections were actually read.

https://bugzilla.gnome.org/show_bug.cgi?id=686226
2012-10-16 14:31:38 -04:00
Dan Williams 30db13ae5a libnm-glib: don't try to query for connections synchronously when NM isn't running (bgo #685345)
And ensure we clear out properties when NM quits, and that we request them
when NM starts up again.
2012-10-05 08:54:35 -05:00
Dan Winship 320464490e libnm-glib: fix GAsyncInitable implementations
If a class implements init_async, it should implement init_finish too,
rather than assuming the default implementation will do the right
thing (which it briefly didn't in glib 2.33).
2012-07-17 09:43:15 -04:00
Dan Winship be18dd06cd libnm-glib: NULL out priv fields on dispose()
In some situations, objects might get used after being disposed, so
clear out their various priv fields so we don't try to access unreffed
objects, freed strings, etc.

https://bugzilla.gnome.org/show_bug.cgi?id=674473
2012-04-23 16:09:58 -04:00
Dan Williams 494f0a2e20 libnm-glib: ensure NMRemoteConnection signals are disconnected (bgo #674484) (lp:949743)
If a client keeps the connection around after NMRemoteSettings is done
with it (and has emitted 'removed' for that connection) then the
RemoteSettings object was still registered to receive signals for
that connection.  To prevent clients from being able to screw up
the RemoteSettings, disconnect any signals it may be listening for
when the connection is removed.  (it should be doing that anyway)
2012-04-23 13:40:43 -05:00
Jiří Klimeš 8bb2789444 libnm-glib: initialize GError, else invalid free() crash can occur (rh #809123) 2012-04-02 16:37:55 +02:00
Jiří Klimeš 2b879e3a33 Revert "libnm-glib: initialize NMRemoteSettings in nm_remote_settings_new() (rh #806664)"
This reverts commit dd0460697c.

The commit dd0460697c make nm_remote_settings_new()
create the NMRemoteSettings object synchronously. It fixed getting properties,
but undid the previous ability to initialize the object asynchronously.
It can be reverted now, because a4f450aa0b commit
ensure initialization in get_property() calls.
2012-04-02 12:58:19 +02:00
Dan Winship a4f450aa0b libnm-glib: more ensure_inited() fixing
We need to do _nm_object_ensure_inited() /
_nm_remote_settings_ensure_inited() from the get_property()
implementations; in most cases, get_property() just calls another
accessor method (which will call _nm_object_ensure_inited()), but in a
few places, it reads priv->whatever directly, so we need to make sure
that it's valid.
2012-03-28 09:06:12 -04:00
Jiří Klimeš dd0460697c libnm-glib: initialize NMRemoteSettings in nm_remote_settings_new() (rh #806664)
The object was not initialized after creation in nm_remote_settings_new(). This
was a regression caused by 762df85234.
2012-03-27 22:36:55 +02:00
Dan Williams 762df85234 libnm-glib: ensure bindings-created objects work as expected (rh #802536)
Bindings (like GObject Introspection) almost always create objects
using g_object_new() by default and don't use our helper functions
like nm_client_new().  Thus we need to make sure that if the
object is created in that way, any property accesses or functions
that return properties ensure that the object is fully initialized,
which is what the _new() functions were supposed to do.  In one
case in NMClient that was missing (getting active connections)
and wasn't happening at all in NMRemoteSettings, which are our two
entry points into libnm-glib.

This allows this python+GI sequence to return the expected active
connection list:

from gi.repository import NMClient
nmclient = NMClient.Client(dbus_path='/org/freedesktop/NetworkManager')
active = nmclient.get_active_connections()
print(active)

where previously it returned an empty list because the NMClient
wasn't fully initialized by the time nm_client_get_active_connections()
was called.
2012-03-21 12:37:39 -05:00
Dan Winship 839eab5564 Use glib-mkenums to generate enum types
Rather than generating enum classes by hand (and complaining in each
file that "this should really be standard"), use glib-mkenums.

Unfortunately, we need a very new version of glib-mkenums in order to
deal with NM's naming conventions and to fix a few other bugs, so just
import that into the source tree temporarily.

Also, to simplify the use of glib-mkenums, import Makefile.glib from
https://bugzilla.gnome.org/654395.

To avoid having to run glib-mkenums for every subdirectory of src/,
add a new "generated" directory, and put the generated enums files
there.

Finally, use Makefile.glib for marshallers too, and generate separate
ones for libnm-glib and NetworkManager.
2012-02-15 11:42:15 -05:00
Dan Winship 410ac72325 libnm-glib: fix to not depend on newer glib 2012-02-06 17:29:49 -06:00
Dan Winship c619365ee3 libnm-glib: asyncify NMRemoteSettings
Add nm_remote_settings_new_async/_finish, and misc other fixes
2012-02-03 10:33:44 -06:00
Dan Winship 9fd98ef91b libnm-glib: implement GInitable/GAsyncInitable in NMObject
Implement GInitable and GAsyncInitable in NMObject, with
implementations that synchronously or asynchonously load all
properties, and change _nm_object_ensure_inited() to run
g_initable_init().

Update the object/object-array property handling to initialize the
objects after creating them (synchronously or asynchronously,
according to the situation), so that they will have all of their
properties preloaded before they are ever visible to the caller.

Move the non-blocking/non-failable parts of various objects'
constructor() methods to constructed(), and move the blocking/failable
parts to init(), and implement init_async() methods with non-blocking
versions of the blocking methods.

Make nm_device_new() and nm_client_new() call
_nm_object_ensure_inited(), to preserve the behaviour formerly
enforced by their construct() methods, that properties are guaranteed
to be initialized before any signals involving them are emitted.
2012-02-03 10:33:43 -06:00
Dan Winship 8ad3ff24ad libnm-glib: don't use client-side generated dbus-glib bindings
Most of the code was using dbus_g_proxy_call() directly, but there
were some leftover uses of the generated bindings. Make things more
consistent by using dbus_g_proxy_call() everywhere, and stop building
the -bindings.h files.
2012-02-02 12:30:44 -06:00
Dan Williams 8b1de024ba libnm-glib: fix allow-none introspection annotations (rh #747302) 2011-10-26 10:53:47 -05:00
Dan Williams a7f7e80839 libnm-glib: fix introspection annotations for callbacks and user_data (rh #747302)
user_data arguments should be annotated with (closure) and callbacks
should be marked (allow none) where it's safe to pass NULL.
2011-10-26 10:33:38 -05:00