From 846e8078c36d888bdf63071b3955d67ca564b661 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 19 Feb 2013 18:18:24 +0000 Subject: [PATCH 2/5] logind: start a systemd for each logged-in user Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61129 --- src/login/logind-user.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 411215a..7826364 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -348,11 +348,33 @@ static int user_create_cgroup(User *u) { } static int user_start_service(User *u) { + int r; + const char *mode = "fail"; + assert(u); - /* FIXME: Fill me in later ... */ + if (u->service) { + log_debug("User %s already has a systemd service.", u->name); + return 0; + } - return 0; + if (asprintf(&u->service, "user@%lu.service", (unsigned long) u->uid) < 0) { + return log_oom(); + } + + log_debug("Starting user@%lu.service for user %s.", + (unsigned long) u->uid, u->name); + r = bus_method_call_with_reply(u->manager->bus, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StartUnit", + NULL, + NULL, + DBUS_TYPE_STRING, &u->service, + DBUS_TYPE_STRING, &mode, + DBUS_TYPE_INVALID); + return r; } int user_start(User *u) { @@ -393,12 +415,30 @@ int user_start(User *u) { } static int user_stop_service(User *u) { + int r; + const char *mode = "fail"; + assert(u); if (!u->service) return 0; - return 0; + log_debug("Stopping user@%lu.service for user %s.", + (unsigned long) u->uid, u->name); + r = bus_method_call_with_reply(u->manager->bus, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StopUnit", + NULL, + NULL, + DBUS_TYPE_STRING, &u->service, + DBUS_TYPE_STRING, &mode, + DBUS_TYPE_INVALID); + + free(u->service); + u->service = NULL; + return r; } static int user_shall_kill(User *u) { -- 1.7.10.4