Commit Graph

24 Commits

Author SHA1 Message Date
Thomas Haller
e4af0f6767 libnm: fix clearing real-devices in NMManager's free_devices()
Found by coverity.
2016-03-04 08:56:38 +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
Dan Williams
4db851f852 libnm/libnm-glib: add NMClient.get_all_devices() method and AllDevices property
Mirror new NetworkManager API to return both real devices and
device placeholders.
2015-12-04 12:16:41 +01:00
Thomas Haller
204fcd33d8 macros: add nm_clear_g_cancellable() utility 2015-11-01 17:28:07 +01: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
Beniamino Galvani
04d5804dd5 nm-manager: add 'metered' property
This introduces a global metered property which makes easier for
clients to obtain the metered status of the current primary
connection.
2015-06-09 18:23:19 +02:00
Lubomir Rintel
fd41aa451b libnm,core: don't mix up enum types
Touches a weak spot on clang's soul.
2015-03-19 11:48:49 +01:00
Dan Winship
3b86cc047e libnm: remove nm_utils_init() from the public API
Remove nm_utils_init() from the public API, and just do it as a
constructor instead.
2014-12-04 08:39:54 -05:00
Lubomir Rintel
75f767ca23 libnm: Don't expect VPN connections to attach to the device 2014-11-19 19:51:44 +01:00
Lubomir Rintel
ba2722004a libnm: Watch for AC removal in case of AddAndActivateConnection() as well
This does the very same thing as 42b9e8283 does for plain ActivateConnection().
2014-11-14 16:46:40 -06: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
Lubomir Rintel
42b9e82839 libnm: Complete activation when ActiveConnection abruptly disappears
A NMActiveConnection may disappear before a match with NMDevice is found. In
such case recheck_pending_activations() would never call the activation
callback and the client would hang indefinitely:

libnm-Message: PC: (0x95bf088) NMManager:active-connections => '['/org/freedesktop/NetworkManager/ActiveConnection/225']' (ao / NMActiveConnection)
libnm-Message: PC: (0x95bf088) NMManager:activating-connection => ''/'' (o / NMActiveConnection)
libnm-Message: PC: (0x95d0a28) NMActiveConnection:state => '4' (u)
libnm-Message: PC: (0x95d0a28) NMActiveConnection:devices => '[]' (ao / NMDevice)
libnm-Message: PC: (0x95bf088) NMManager:active-connections => '[]' (ao / NMActiveConnection)
*hang*

Let's listen for active-connection-removed and tear down the activation with
an error if the removed connection is one we're activating.
2014-11-07 14:26:41 +01:00
Lubomir Rintel
b4fe3b7cd9 libnm: Drop a wrong assert
An active connection object could disappear from the bus before its removal
from NMManager:active-connections is signalled -- don't assert it's gone from
there already.

Here /o/fd/NM/ActiveConnection/81 disappears shortly after it's added:

libnm-Message: PC: (0x9ebd088) NMManager:active-connections => '['/org/freedesktop/NetworkManager/ActiveConnection/81', '/org/freedesktop/NetworkManager/ActiveConnection/80']' (ao / NMActiveConnection)
libnm-Message: PC: (0x9ebd088) NMManager:activating-connection => ''/'' (o / NMActiveConnection)
libnm-Message: PC: (0x9ed1458) NMDeviceTeam:state => '110' (u)
libnm-Message: PC: (0x9ed1458) NMDeviceTeam:state-reason => '(110, 0)' ((uu))
libnm-Message: PC: (0x9ece9a0) NMActiveConnection:state => '3' (u)
libnm-Message: PC: (0x9ebd088) NMManager:state => '20' (u)
libnm-Message: PC: (0x9ebd088) NMManager:devices => '['/org/freedesktop/NetworkManager/Devices/0', '/org/freedesktop/NetworkManager/Devices/2', '/org/freedesktop/NetworkManager/Devices/3']' (ao / NMDevice)
libnm-Message: PC: (0x9ebd088) NMManager:active-connections => '['/org/freedesktop/NetworkManager/ActiveConnection/81', '/org/freedesktop/NetworkManager/ActiveConnection/80']' (ao / NMActiveConnection)
libnm-Message: PC: (0x9ece9a0) NMActiveConnection:state => '4' (u)
libnm-Message: PC: (0x9ece9a0) NMActiveConnection:devices => '[]' (ao / NMDevice)
libnm-Message: Could not create object for /org/freedesktop/NetworkManager/ActiveConnection/81: Method "GetAll" with signature "s" on interface "org.freedesktop.DBus.Properties" doesn't exist

(process:18042): libnm-CRITICAL **: object_creation_failed: assertion 'find_active_connection_by_path (self, failed_path) == NULL' failed
2014-11-07 14:26:41 +01: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
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
d78ea27d36 libnm: postpone activation callback until all objects are ready
In some cases, the nm_client_activate_connection() callback could be
invoked when either the NMActiveConnection or the NMDevice had not
been initialized yet. Fix it to wait for both of them to be fully
initialized before invoking the callback.
2014-10-19 09:26:50 -04:00
Dan Winship
a9e906fcbd libnm: add -added and -removed signals for ACs to NMManager 2014-10-19 09:26:49 -04:00
Dan Winship
ab878f7479 libnm: further NULL-vs-empty-array fixes
In some cases, code may look at the value of an array-valued property
during object initialization, before NMObject has set it to its actual
initial value. So ensure that we initialize all such properties to an
empty array, rather than leaving them NULL.

Also fix another bug in NMClient that could result in
priv->active_connections being NULL during certain signal emissions,
and fix nm_client_get_active_connections() to not return NULL when NM
was not running.
2014-10-19 09:26:49 -04:00
Dan Winship
90f66ff456 libnm: split "NMManager" out of NMClient
Clone NMClient as NMManager, and make NMClient just be a wrapper
around that new class.
2014-10-10 12:40:14 -04:00