From fb6becb4436ae4078337011b2017ce294e7361cf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Jul 2013 01:46:30 +0200 Subject: logind: port over to use scopes+slices for all cgroup stuff In order to prepare things for the single-writer cgroup scheme, let's make logind use systemd's own primitives for cgroup management. Every login user now gets his own private slice unit, in which his sessions live in a scope unit each. Also, add user@$UID.service to the same slice, and implicitly start it on first login. --- src/login/logind-machine-dbus.c | 89 +++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 22 deletions(-) (limited to 'src/login/logind-machine-dbus.c') diff --git a/src/login/logind-machine-dbus.c b/src/login/logind-machine-dbus.c index 7feea2e92a..ae8c5d720a 100644 --- a/src/login/logind-machine-dbus.c +++ b/src/login/logind-machine-dbus.c @@ -37,11 +37,11 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ - " \n" \ + " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " \n" @@ -58,24 +58,6 @@ BUS_GENERIC_INTERFACES_LIST \ "org.freedesktop.login1.Machine\0" -static int bus_machine_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) { - _cleanup_free_ char *t = NULL; - Machine *m = data; - int r; - bool success; - - assert(i); - assert(property); - assert(m); - - r = cg_join_spec(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_path, &t); - if (r < 0) - return r; - - success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t); - return success ? 0 : -ENOMEM; -} - static int bus_machine_append_id(DBusMessageIter *i, const char *property, void *data) { DBusMessageIter sub; Machine *m = data; @@ -100,6 +82,22 @@ static int bus_machine_append_id(DBusMessageIter *i, const char *property, void return 0; } +static int bus_machine_append_state(DBusMessageIter *i, const char *property, void *data) { + Machine *m = data; + const char *state; + + assert(i); + assert(property); + assert(m); + + state = machine_state_to_string(machine_get_state(m)); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state)) + return -ENOMEM; + + return 0; +} + static int get_machine_for_path(Manager *m, const char *path, Machine **_machine) { _cleanup_free_ char *e = NULL; Machine *machine; @@ -130,11 +128,11 @@ static const BusProperty bus_login_machine_properties[] = { { "Id", bus_machine_append_id, "ay", 0 }, { "Timestamp", bus_property_append_usec, "t", offsetof(Machine, timestamp.realtime) }, { "TimestampMonotonic", bus_property_append_usec, "t", offsetof(Machine, timestamp.monotonic) }, - { "DefaultControlGroup", bus_machine_append_default_cgroup, "s", 0 }, { "Service", bus_property_append_string, "s", offsetof(Machine, service), true }, - { "Slice", bus_property_append_string, "s", offsetof(Machine, slice), true }, + { "Scope", bus_property_append_string, "s", offsetof(Machine, scope), true }, { "Leader", bus_property_append_pid, "u", offsetof(Session, leader) }, { "Class", bus_machine_append_class, "s", offsetof(Machine, class) }, + { "State", bus_machine_append_state, "s", 0 }, { "RootDirectory", bus_property_append_string, "s", offsetof(Machine, root_directory), true }, { NULL, } }; @@ -313,3 +311,50 @@ int machine_send_changed(Machine *m, const char *properties) { return 0; } + +int machine_send_create_reply(Machine *m, DBusError *error) { + _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; + + assert(m); + + if (!m->create_message) + return 0; + + if (error) { + DBusError buffer; + + dbus_error_init(&buffer); + + if (!error || !dbus_error_is_set(error)) { + dbus_set_error_const(&buffer, DBUS_ERROR_INVALID_ARGS, "Invalid Arguments"); + error = &buffer; + } + + reply = dbus_message_new_error(m->create_message, error->name, error->message); + dbus_error_free(&buffer); + + if (!reply) + return log_oom(); + } else { + _cleanup_free_ char *p = NULL; + + p = machine_bus_path(m); + if (!p) + return log_oom(); + + reply = dbus_message_new_method_return(m->create_message); + if (!reply) + return log_oom(); + + if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID)) + return log_oom(); + } + + if (!dbus_connection_send(m->manager->bus, reply, NULL)) + return log_oom(); + + dbus_message_unref(m->create_message); + m->create_message = NULL; + + return 0; +} -- cgit v1.2.3-54-g00ecf