diff options
author | Lukas Märdian <slyon@ubuntu.com> | 2021-05-05 11:15:12 +0200 |
---|---|---|
committer | Lukas Märdian <slyon@ubuntu.com> | 2021-08-04 13:39:20 +0200 |
commit | b264b1ee2c608637faa25cbc240ee2391b9b0d37 (patch) | |
tree | 13677ca11a41b092f4630fd4440b527c4678b8b6 /src | |
parent | d13d8f7f2703a1125eb0deac916e7cf5233ad9eb (diff) |
dbus:cli: implement io.netplan.Netplan.Generate() (#208)
Proxy the 'netplan generate' CLI via DBus, if called from within a snap,
to work around the strict AppArmor confinement.
see: snapcore/snapd#10212
COMMITS:
* dbus:cli: implement io.netplan.Netplan.Generate()
Proxy the 'netplan generate' CLI via DBus, if called from within a snap,
to work around the strict AppArmor confinement.
see: https://github.com/snapcore/snapd/pull/10212
* doc: mention Netplan.Generate() DBus method
Diffstat (limited to 'src')
-rw-r--r-- | src/dbus.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -239,6 +239,35 @@ method_apply(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) } static int +method_generate(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) +{ + g_autoptr(GError) err = NULL; + g_autofree gchar *stdout = NULL; + g_autofree gchar *stderr = NULL; + gint exit_status = 0; + + gchar *argv[] = {SBINDIR "/" "netplan", "generate", NULL}; + + // for tests only: allow changing what netplan to run + if (getenv("DBUS_TEST_NETPLAN_CMD") != 0) + argv[0] = getenv("DBUS_TEST_NETPLAN_CMD"); + + g_spawn_sync("/", argv, NULL, 0, NULL, NULL, &stdout, &stderr, &exit_status, &err); + // LCOV_EXCL_START + if (err != NULL) + return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED, + "cannot run netplan generate: %s", err->message); + g_spawn_check_exit_status(exit_status, &err); + if (err != NULL) + return sd_bus_error_setf(ret_error, SD_BUS_ERROR_FAILED, + "netplan generate failed: %s\nstdout: '%s'\nstderr: '%s'", + err->message, stdout, stderr); + // LCOV_EXCL_STOP + + return sd_bus_reply_method_return(m, "b", true); +} + +static int method_info(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { sd_bus_message *reply = NULL; @@ -663,6 +692,7 @@ method_config(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) static const sd_bus_vtable netplan_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_METHOD("Apply", "", "b", method_apply, 0), + SD_BUS_METHOD("Generate", "", "b", method_generate, 0), SD_BUS_METHOD("Info", "", "a(sv)", method_info, 0), SD_BUS_METHOD("Config", "", "o", method_config, 0), SD_BUS_VTABLE_END |