Commit Graph

133 Commits

Author SHA1 Message Date
Thomas Haller
97935382f4 coverity: fix various warnings detected with Coverity
These are (most likely) only warnings and not severe bugs.
Some of these changes are mostly made to get a clean run of
Coverity without any warnings.

Error found by running Coverity scan

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

Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-13 15:29:24 +01:00
Dan Williams
4ec5f5c8e3 libnm-glib: add support for NULL connections to nm_client_activate_connection()
Pass along to NetworkManager, which picks the best available connection for the
device and activates it.
2013-10-31 15:33:58 -05:00
Thomas Haller
3eb1d5e902 core: cleanup freeing of glib collections of pointers
When freeing one of the collections such as GArray, GPtrArray, GSList,
etc. it is common that the items inside the connections must be
freed/unrefed too.

The previous code often iterated over the collection first with
e.g. g_ptr_array_foreach and passing e.g. g_free as GFunc argument.
For one, this has the problem, that g_free has a different signature
GDestroyNotify then the expected GFunc. Moreover, this can be
simplified either by setting a clear function
(g_ptr_array_set_clear_func) or by passing the destroy function to the
free function (g_slist_free_full).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:53:57 +02:00
Jiří Klimeš
570b9b362d libnm-glib: fix a crash in nm_client_new() (rh #1010288)
We have to check if 'client' is valid when calling _nm_object_ensure_inited().
Creation of NMClient object can fail, because its parent NMObject's
constructor() returns NULL for D-Bus errors.

https://bugzilla.redhat.com/show_bug.cgi?id=1010288
2013-10-14 08:48:06 +02:00
Dan Winship
76cc2bd9df libnm-util, libnm-glib: fix up some gtk-doc comments
gtk-doc recognizes that #NMFoos is the plural of #NMFoo now, so you
don't need to put an empty comment between the type name and the "s"
to make it work. (Unfortunately, it's not smart enough to realize that
"NMIP4Addresses" is the plural of "NMIP4Address".)

Also, add some missing "#"s noticed along the way.
2013-10-11 10:16:14 -04:00
Dan Winship
cbe261caa2 libnm: more valgrinding fixes 2013-10-03 11:04:45 -04:00
Dan Winship
26544f3148 libnm-glib: change "Since: 0.9.10" to "Since: 0.9.8.6" for backported API 2013-09-11 14:10:55 -04:00
Dan Winship
f668423832 libnm-glib: Add NMClient:primary-connection and :activating-connection
https://bugzilla.gnome.org/show_bug.cgi?id=704841
2013-08-28 11:01:43 -04:00
Dan Winship
84919405e1 libnm-glib: support new connectivity property/methods 2013-08-28 10:54:09 -04:00
Dan Winship
4d8063cd78 libnm-glib: add NMClient:startup, nm_client_get_startup()
Expose the new NMManager:startup property on NMClient.
2013-08-16 17:27:34 -04: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
4a21eb08db libnm-glib: clear and recheck permissions on NM restarts 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
Jiří Klimeš
82fb1978a4 all: use G_VALUE_INIT to initialize GValue variables
It makes the initializations more explicit.
G_VALUE_INIT is available since glib 2.30, and NM now require glib >= 2.32
2013-03-25 08:41:18 +01:00
Dan Williams
4f9e13fcb0 libnm-glib: add Since tags to new functions and properties 2013-02-22 08:34:13 -06:00
Jiří Klimeš
0309bdc2e0 libnm-glib: add nm_client_set_logging() for setting debugging level and domains 2013-01-09 16:47:49 +01:00
Jiří Klimeš
4ce355022c libnm-glib: add nm_client_get_logging() function
to get current logging level and domains.
2013-01-09 16:47:49 +01:00
Colin Walters
1b84012762 libnm-glib: clarify documentation of nm_client_get_devices() 2012-12-13 17:12:11 -06: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
Jiří Klimeš
b8958f27ea docs: fix some annotations in libnm-glib 2012-06-29 14:49:18 +02:00
Jiří Klimeš
7c7e8dc692 libnm-glib: add "object-creation-failed" signal to NMObject
The signal is private for libnm-glib and should not be used externally.
It is emitted when there's an error while creating an object.
In addition, this commit makes use of the signal in NMClient to ensure
that the callbacks are always called for nm_client_activate_connection()
and nm_client_add_and_activate_connection().
2012-04-25 16:39:17 +02:00
Dan Williams
48981a6166 libnm-glib: ensure object cache is cleared when NM stops (bgo #674473)
Otherwise if a client holds references to the objects (or in the
JavaScript case, uses deferred garbage collection) they'll still
be in the cache when NM restarts, and the old object may have the
same path as some new object, which isn't good.
2012-04-23 17:10:14 -05:00
Dan Winship
17d5973ef6 libnm-glib: discard devices and active connections when NM goes down
When NMClient changes state to "not running", don't just unref all the
devices and connections: emit notify::active-connections and
device-removed signals too, so the app will drop its copies of them.

https://bugzilla.gnome.org/show_bug.cgi?id=674473
2012-04-23 16:09:58 -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
614c46f87b trivial: fix spacing 2012-04-20 09:57:22 -05: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š
b48dc05b72 libnm-glib: ensure bindings-created NMClient object work (rh #802536)
Most of the stuff was done by 762df85234.
But to allow this piece of code:

from gi.repository import NMClient
nmclient = NMClient.Client()
print nmclient.get_active_connections()

we also need to set "dbus-path" property in NMClient constuctor(),
else parent NMObject is not properly constructed.
2012-03-27 14:53:31 +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 Williams
1138f136f8 libnm-glib: fix leaked NMDevice objects due to circular refcounting
Active Device objects held a reference to their ActiveConnection
which also held a reference  back to the Device.  Ensure that's
broken so everyone can get disposed correctly.
2012-03-12 19:26:34 -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 Williams
7f9fe7601e libnm-glib: better debugging of property accesses and updates
Need to initialize libnm-util to get GValue transforms registered
so the property values print out as strings.  Then actually print
some debugging information about properties.
2012-02-07 12:36:45 -06:00
Dan Winship
410ac72325 libnm-glib: fix to not depend on newer glib 2012-02-06 17:29:49 -06:00
Dan Williams
925d5e016b docs: reference NMRemoteSettings from NMClient creators
It can be a bit confusing that one object doesn't do both
control and configuration.  So throw users a bone and tell
them how.
2012-02-03 10:38:38 -06:00
Dan Winship
7844ead116 libnm-glib: nm_client_new_async, fix up NMClient asynchrony issues 2012-02-03 10:33:43 -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
ad5daa098c libnm-glib: add "pseudoproperties" for things like Client.GetDevices
Add generic handling for "properties" that consist of a "Get" method,
an "Added" signal, and a "Removed" signal, reusing some of the code
for handling object-array-valued properties. And load the values of
pseudo properties from _nm_object_reload/ensure_properties as well.
2012-02-03 10:33:43 -06:00
Dan Winship
cc90f1010e libnm-glib: simplify handling of object and object array properties
Add an "object_type" field to NMPropertiesInfo, and use that with
DBUS_TYPE_G_OBJECT_PATH and DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH
properties so that we don't need custom marshallers for each one.

When creating an NMDevice or NMActiveConnection, we need to fetch an
extra property first to figure out the exact subclass to use, so add a
bit of infrastructure for that as well. Also, do that preprocessing
asynchronously when processing a property change notification, so that
it doesn't block the main loop.
2012-02-03 10:33:43 -06:00
Dan Winship
5afcee4693 libnm-glib: simplify property getter methods
Rather than having every property getter method have code to fetch
that specific property's value, just call the new
_nm_object_ensure_inited() (which makes sure that we've read all the
property values on the object at least once), and then return the
cached value. (After we've read the initial property values, the
PropertiesChanged signal handler will ensure that the values are kept
up to date, so we can always just return cached property values after
that point.)

This then lets us get rid of _nm_object_get_property() and its
wrappers.
2012-02-03 10:33:43 -06:00
Dan Winship
2e48cc092c libnm-glib: simplify and genericize property declaration
Rename _nm_object_handle_properties_changed(), etc, to be about
properties in general, rather than just property changes.

Interpret func==NULL in NMPropertiesInfo as meaning "use
_nm_object_demarshal_generic", and then reorder the fields so that you
can just leave that field out in the declarations when it's NULL.

Add a way to register properties that exist in D-Bus but aren't
tracked by the NMObjects, and use that for NMDevice's D-Bus Ip4Address
property, replacing the existing hack.

Also add a few other missing properties noticed along the way.
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 Winship
efadfd8b17 libnm-glib: pre-emptively avoid some -Wshadow errors
including <gio/gio.h> will drag in some additional system headers that
result in new -Wshadow warnings. Fix those.
2012-02-02 12:30:35 -06:00
Jiří Klimeš
42060fdd89 libnm-glib: get devices and their properties in constructor (NMClient, NMDevice)
NMClient and NMDevice used a 'lazy' approach for getting stuff from D-Bus, i.e.
requesting data from NM when they are asked for. However, for some cases, like
removing devices it is not optimal. libnm-glib will never see a device that was
removed, but not added during NMClient's lifetime.

So let's get devices list in NMClient's constructor and device properties
in NMDevice constructor to have the data from the beginning.
2011-11-24 17:15:36 +01:00
Jiří Klimeš
8d43875cbe libnm-glib: add nm_client_get_device_by_iface() for NMClient 2011-06-15 14:58:04 +02:00
Jiří Klimeš
b4a72d1ad7 libnm-glib: fix crash for AddAndActivateConnection() D-Bus call (bgo #652512)
When a partial connection is passed to nm_client_add_and_activate_connection(),
but it doesn't contain any settings, nm_connection_to_hash() returns NULL and
there's a crash later on the NULL hash.
2011-06-14 19:39:23 +02:00
Dan Williams
df511f74f7 build: use -Wundef and fix up cases where stuff wasn't defined (bgo #647157) 2011-04-14 13:19:12 -05:00
Dan Williams
fdd2727d21 libnm-glib: hook up networking enabled property writes 2011-03-31 17:38:39 -05:00
Dan Williams
0d92803ccc libnm-glib: make property set requests for wifi/wwan/wimax do something
They weren't actually poking NM, just setting internal values.
2011-03-31 17:34:13 -05:00