Watchdog petting using snpd-glib API does not work

Issue: Petting watchdog periodically using snapd-glib API does not have effect and reboots device.


core18 20200427 1754 latest/beta canonical✓ base
snapd 2.45~pre1+git1579.g5da30cb 7526 latest/beta canonical✓ snapd
hw-wtdog 25 latest/beta <XYZ> -

snap name: hw-wtdog (from brand store and with snapd-control plug)

snap declaration: From store

snapcraft.yaml (related snippet):
setpet: (this binary is executed by another simple daemon app every 1 minute)
command: bin/setpet
plugs: [snapd-control]

snapd-control hw-wtdog:snapd-control :snapd-control -

Code (related snippet):
g_autoptr(SnapdClient) client = snapd_client_new();
args = g_strsplit ("set;watchdog.runtime-timeout=3m", ";", -1);
result = snapd_client_run_snapctl_sync (client, ctx, args, &stdout_output, &stderr_output, NULL, &error);
g_assert_no_error (error);
g_assert_true (result);

dev@dhcppc4:~$ sudo snap get core watchdog

The snapd_client_run_snapctl_sync method is equivalent to the snapctl tool, which allows a normal confined snap (i.e. no snapd-control plug) to get and set its own configuration. If you run snap get hw-wtdog, you’ll probably see the configuration you set.

Instead, it looks like you want the equivalent of snap set to set the configuration of another snap, which is snapd_client_set_snap_conf_sync. I think something like the following:

g_autoptr(SnapdClient) client = snapd_client_new();
g_autoptr(GHashTable) key_values = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_variant_unref);
g_autoptr(GError) error = NULL;
g_hash_table_insert(key_values, "watchdog.runtime-timeout", g_variant_new_string("3m"));
if (!snapd_client_set_snap_conf_sync(client, "system", key_values, NULL, &error)) {
    /* handle error here */

Hopefully that’s enough to get you unblocked.

Thanks, @jamesh
snapd_client_set_snap_conf_sync works as expected.


1 Like