Re: signal for (De)ActivateConnection?

On Thu, 2017-12-07 at 22:44 +0100, Michael Hirmke wrote:
Hi Thomas,

thx for your answer.


And update of NM shouldn't change behavior for you. Can you detail
causes the breaking?

I'm not sure, I just noticed a few days ago, that my script doesn't
any more and that I don't get a DeviceAdd signal any more.

To answer your last question about what I want to achieve:
I want to run certain GUI programs depending on certain network
connections coming up or going down. So I wrote a perl script around
Net::DBus module. This script gets started via KDE autostart and
for signals telling it what is going on regarding network


/org/freedesktop/NetworkManager/Devices/* is different from
/org/freedesktop/NetworkManager/ActiveConnection/* is different

I know, but I don't know how to bring the bits and pieces together.
When I started scripting, I thought that I'd need the DeviceAdd and
DeviceRemoved signals to achieve my goal, but in the meantime I begin
understand, that I have to wait for connections coming up.
I didn't find an appropriate example, though.

An ActiveConnection connects the connection profile with the
device, while the profile is activated on a device..
DeviceAdded/DeviceRemove notifies you about devices. A
signal for property ActiveConnections, notifies you about a change
the list of all active connections (which is add or removal).

So how do I find out, that the PropertyChanged signal comes from a
network connection coming up or going down?

VPN connections for NetworkManager are a bit wired. VPN connections
a subclass of active connections.
If you have a tun/tap based VPN (like OpenVPN), then the VPN's
is not the tun/tap device, but instead the device with the default
route. As you see with `nmcli device`.

No, there isn't a device, though I'm quite sure it was in earlier
versions of NetworkManager (or perhaps strongswan).

You don't say what you want to do, but usually you need to look at
or more D-Bus objects and their state.
You would look at the presence and state of the active-connection
VPN connection), in addition to the state of the device. However,
said, in case of VPNs, the device is not what you might expect it

Do I need to check for devices at all?

See the D-Bus API documentation:

Yes, this is my main source, but I don't understand everything
there 8-<


sounds a bit like you want to perform some action when a particular
connection profile activates/deactivates.

First, you need to know which a connection profile you care about, that
is, you need its /org/freedesktop/NetworkManager/Settings/* path.
You need to call GetSettings() on each of the profiles, to match what
you are looking for (for example, matching the

When a connection is activated, it has an active-connection that
references it. Usually there is at most one such active-connection,
but while re-activating a connection there can be multiple once (one
that is about to deactivate, and once that is about to activate).

Anyway, you need to monitor these active connections for whether they
reference the profile you care about. The Manager's PropertyChanged
event for ActiveConnections notifies you when active-connection come to
be and cease to exist.

The ActiveConnection basically ties the profile to the networking

and as said, an active VPN connection is a bit odd, they are active-
connections too (with an additional
org.freedesktop.NetworkManager.VPN.Connection interface).

I would inspect the state with the "d-feet" GUI.

You could also use libnm via GObject introspection (e.g. from Perl or
Python). That might be more convenient to use, then a plain D-Bus
library (the latter works of course too). We don't have any perl
examples, only Python:


Attachment: signature.asc
Description: This is a digitally signed message part

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]