#include "dbus.h"
#include "log.h"
#include "dbus-manager.h"
+#include "strv.h"
#define INTROSPECTION_BEGIN \
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
" <arg nane=\"cleanup\" type=\"b\" direction=\"in\"/>" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>" \
" </method>" \
+ " <method name=\"Reload\"/>" \
+ " <method name=\"Reexecute\"/>" \
+ " <method name=\"Exit\"/>" \
+ " <method name=\"SetEnvironment\">" \
+ " <arg name=\"names\" type=\"as\" direction=\"in\"/>" \
+ " </method>" \
+ " <method name=\"UnsetEnvironment\">" \
+ " <arg name=\"names\" type=\"as\" direction=\"in\"/>" \
+ " </method>" \
" <signal name=\"UnitNew\">" \
" <arg name=\"id\" type=\"s\"/>" \
" <arg name=\"unit\" type=\"o\"/>" \
" <property name=\"Version\" type=\"s\" access=\"read\"/>" \
" <property name=\"RunningAs\" type=\"s\" access=\"read\"/>" \
" <property name=\"BootTimestamp\" type=\"t\" access=\"read\"/>" \
- " <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>" \
- " <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>" \
+ " <property name=\"LogLevel\" type=\"s\" access=\"read\"/>" \
+ " <property name=\"LogTarget\" type=\"s\" access=\"read\"/>" \
+ " <property name=\"NNames\" type=\"u\" access=\"read\"/>" \
+ " <property name=\"NJobs\" type=\"u\" access=\"read\"/>" \
+ " <property name=\"Environment\" type=\"as\" access=\"read\"/>" \
" </interface>" \
BUS_PROPERTIES_INTERFACE \
BUS_INTROSPECTABLE_INTERFACE
return 0;
}
+static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ uint32_t u;
+
+ assert(m);
+ assert(i);
+ assert(property);
+
+ u = hashmap_size(m->units);
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ uint32_t u;
+
+ assert(m);
+ assert(i);
+ assert(property);
+
+ u = hashmap_size(m->jobs);
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
{ "org.freedesktop.systemd1.Manager", "BootTimestamp", bus_property_append_uint64, "t", &m->boot_timestamp },
{ "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", NULL },
{ "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", NULL },
+ { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", NULL },
+ { "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", NULL },
+ { "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
{ NULL, NULL, NULL, NULL, NULL }
};
DBUS_TYPE_INVALID))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "GetJob")) {
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
uint32_t id;
Job *j;
free(introspection);
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
+
+ assert(!m->queued_message);
+
+ /* Instead of sending the reply back right away, we
+ * just remember that we need to and then send it
+ * after the reload is finished. That way the caller
+ * knows when the reload finished. */
+
+ if (!(m->queued_message = dbus_message_new_method_return(message)))
+ goto oom;
+
+ m->exit_code = MANAGER_RELOAD;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ m->exit_code = MANAGER_REEXECUTE;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
+
+ if (m->running_as == MANAGER_INIT)
+ return bus_send_error_reply(m, message, NULL, -ENOTSUP);
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ m->exit_code = MANAGER_EXIT;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
+ char **l = NULL, **e = NULL;
+
+ if ((r = bus_parse_strv(message, &l)) < 0) {
+ if (r == -ENOMEM)
+ goto oom;
+
+ return bus_send_error_reply(m, message, NULL, r);
+ }
+
+ e = strv_env_merge(m->environment, l, NULL);
+ strv_free(l);
+
+ if (!e)
+ goto oom;
+
+ if (!(reply = dbus_message_new_method_return(message))) {
+ strv_free(e);
+ goto oom;
+ }
+
+ strv_free(m->environment);
+ m->environment = e;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
+ char **l = NULL, **e = NULL;
+
+ if ((r = bus_parse_strv(message, &l)) < 0) {
+ if (r == -ENOMEM)
+ goto oom;
+
+ return bus_send_error_reply(m, message, NULL, r);
+ }
+
+ e = strv_env_delete(m->environment, l, NULL);
+ strv_free(l);
+
+ if (!e)
+ goto oom;
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ strv_free(m->environment);
+ m->environment = e;
+
} else
return bus_default_message_handler(m, message, NULL, properties);