Snapctl is-connected plug|slot

The snapctl command will soon grow a sub-command to query connection status of given plug or slot. This was requested for a long time (e.g. https://bugs.launchpad.net/snapd/+bug/1809708 and Bug #1809708 “Allow snaps to query interface connection status directly from snapd”) and for good reasons as finding out if a plug or slot of the snap is connected from within its hooks or apps was not easily possible and required workarounds (probing of effective permissions, or using interface hooks to track connections etc).

It was internally agreed that the syntax would be as follows:

snapctl is-connected <plug|slot>

Since snapctl is executed from hooks or from apps of a snap, snap name is implied by the running context and the plug or slot name is always referring to that snap. Moreover, since plug and slot names are unique within a snap, there is no ambiguity here.

The proposed semantics (to be confirmed) for the new command is to return zero (non-error) status if the plug or slot is connected, and error status otherwise.

CC @pedronis

5 Likes

Related PR is now up: https://github.com/snapcore/snapd/pull/7771

1 Like

This feature has landed and should become available with snapd 2.43.

2 Likes

Note - that since this is only in 2.43, if as a developer you make use of this, you should add an assumes: 2.43 to your snapcraft.yaml as per Interfaces for Raspberry Pi imager

4 Likes