diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-06-15 15:31:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-06-21 19:29:45 +0200 |
commit | 8d0e38a2b966799af884e78a54fd6a2dffa44788 (patch) | |
tree | 7e5b7aaaebe2342ec4dcbaaedc3991bbe09b94ce /src/dbus-manager.c | |
parent | 48f82119ce55caa7671598fb1bd90df4eb00d150 (diff) |
dbus: introduce UnsetAndSetEnvironment()
Diffstat (limited to 'src/dbus-manager.c')
-rw-r--r-- | src/dbus-manager.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/dbus-manager.c b/src/dbus-manager.c index 797e53d10f..cc2b4d0157 100644 --- a/src/dbus-manager.c +++ b/src/dbus-manager.c @@ -128,6 +128,10 @@ " </method>\n" \ " <method name=\"UnsetEnvironment\">\n" \ " <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \ + " </method>\n" \ + " <method name=\"UnsetAndSetEnvironment\">\n" \ + " <arg name=\"unset\" type=\"as\" direction=\"in\"/>\n" \ + " <arg name=\"set\" type=\"as\" direction=\"in\"/>\n" \ " </method>\n" #define BUS_MANAGER_INTERFACE_SIGNALS \ @@ -1035,6 +1039,58 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, strv_free(m->environment); m->environment = e; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) { + char **l_set = NULL, **l_unset = NULL, **e = NULL, **f = NULL; + DBusMessageIter iter; + + if (!dbus_message_iter_init(message, &iter)) + return bus_send_error_reply(connection, message, NULL, -EINVAL); + + r = bus_parse_strv_iter(&iter, &l_unset); + if (r < 0) { + if (r == -ENOMEM) + goto oom; + + return bus_send_error_reply(connection, message, NULL, r); + } + + if (!dbus_message_iter_next(&iter)) { + strv_free(l_unset); + return bus_send_error_reply(connection, message, NULL, -EINVAL); + } + + r = bus_parse_strv_iter(&iter, &l_set); + if (r < 0) { + strv_free(l_unset); + if (r == -ENOMEM) + goto oom; + + return bus_send_error_reply(connection, message, NULL, r); + } + + e = strv_env_delete(m->environment, 1, l_unset); + strv_free(l_unset); + + if (!e) { + strv_free(l_set); + goto oom; + } + + f = strv_env_merge(2, e, l_set); + strv_free(l_set); + strv_free(e); + + if (!f) + goto oom; + + if (!(reply = dbus_message_new_method_return(message))) { + strv_free(f); + goto oom; + } + + strv_free(m->environment); + m->environment = f; + } else return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties); |