chiark / gitweb /
logind: after deserializatio readd systemd units to unit-to-object hashmap correctly
authorLennart Poettering <lennart@poettering.net>
Tue, 2 Jul 2013 15:17:35 +0000 (17:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 2 Jul 2013 15:18:41 +0000 (17:18 +0200)
src/login/logind-session.c
src/login/logind-user.c
src/machine/machine.c

index 6e1bf6d..2892c38 100644 (file)
@@ -455,9 +455,7 @@ done:
 }
 
 static int session_start_scope(Session *s) {
 }
 
 static int session_start_scope(Session *s) {
-        _cleanup_free_ char *description = NULL;
         DBusError error;
         DBusError error;
-        char *job;
         int r;
 
         assert(s);
         int r;
 
         assert(s);
@@ -467,26 +465,32 @@ static int session_start_scope(Session *s) {
         dbus_error_init(&error);
 
         if (!s->scope) {
         dbus_error_init(&error);
 
         if (!s->scope) {
-                s->scope = strjoin("session-", s->id, ".scope", NULL);
-                if (!s->scope)
+                _cleanup_free_ char *description = NULL;
+                char *scope, *job;
+
+                scope = strjoin("session-", s->id, ".scope", NULL);
+                if (!scope)
                         return log_oom();
 
                         return log_oom();
 
-                r = hashmap_put(s->manager->session_units, s->scope, s);
-                if (r < 0)
-                        log_warning("Failed to create mapping between unit and session");
-        }
+                description = strjoin("Session ", s->id, " of user ", s->user->name, NULL);
 
 
-        description = strjoin("Session ", s->id, " of user ", s->user->name, NULL);
+                r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, &error, &job);
+                if (r < 0) {
+                        log_error("Failed to start session scope: %s %s", bus_error(&error, r), error.name);
+                        dbus_error_free(&error);
 
 
-        r = manager_start_scope(s->manager, s->scope, s->leader, s->user->slice, description, &error, &job);
-        if (r < 0) {
-                log_error("Failed to start session scope: %s %s", bus_error(&error, r), error.name);
-                dbus_error_free(&error);
-        } else {
-                free(s->scope_job);
-                s->scope_job = job;
+                        free(scope);
+                } else {
+                        s->scope = scope;
+
+                        free(s->scope_job);
+                        s->scope_job = job;
+                }
         }
 
         }
 
+        if (s->scope)
+                hashmap_put(s->manager->session_units, s->scope, s);
+
         return 0;
 }
 
         return 0;
 }
 
index fb961bf..0a985a5 100644 (file)
@@ -338,27 +338,30 @@ static int user_start_slice(User *u) {
         dbus_error_init(&error);
 
         if (!u->slice) {
         dbus_error_init(&error);
 
         if (!u->slice) {
-                char lu[DECIMAL_STR_MAX(unsigned long) + 1];
+                char lu[DECIMAL_STR_MAX(unsigned long) + 1], *slice;
                 sprintf(lu, "%lu", (unsigned long) u->uid);
 
                 sprintf(lu, "%lu", (unsigned long) u->uid);
 
-                r = build_subslice(SPECIAL_USER_SLICE, lu, &u->slice);
+                r = build_subslice(SPECIAL_USER_SLICE, lu, &slice);
                 if (r < 0)
                         return r;
 
                 if (r < 0)
                         return r;
 
-                r = hashmap_put(u->manager->user_units, u->slice, u);
-                if (r < 0)
-                        log_warning("Failed to create mapping between unit and user");
-        }
+                r = manager_start_unit(u->manager, slice, &error, &job);
+                if (r < 0) {
+                        log_error("Failed to start user slice: %s", bus_error(&error, r));
+                        dbus_error_free(&error);
 
 
-        r = manager_start_unit(u->manager, u->slice, &error, &job);
-        if (r < 0) {
-                log_error("Failed to start user slice: %s", bus_error(&error, r));
-                dbus_error_free(&error);
-        } else {
-                free(u->slice_job);
-                u->slice_job = job;
+                        free(slice);
+                } else {
+                        u->slice = slice;
+
+                        free(u->slice_job);
+                        u->slice_job = job;
+                }
         }
 
         }
 
+        if (u->slice)
+                hashmap_put(u->manager->user_units, u->slice, u);
+
         return 0;
 }
 
         return 0;
 }
 
@@ -372,27 +375,30 @@ static int user_start_service(User *u) {
         dbus_error_init(&error);
 
         if (!u->service) {
         dbus_error_init(&error);
 
         if (!u->service) {
-                char lu[DECIMAL_STR_MAX(unsigned long) + 1];
+                char lu[DECIMAL_STR_MAX(unsigned long) + 1], *service;
                 sprintf(lu, "%lu", (unsigned long) u->uid);
 
                 sprintf(lu, "%lu", (unsigned long) u->uid);
 
-                u->service = unit_name_build("user", lu, ".service");
-                if (!u->service)
+                service = unit_name_build("user", lu, ".service");
+                if (!service)
                         return log_oom();
 
                         return log_oom();
 
-                r = hashmap_put(u->manager->user_units, u->service, u);
-                if (r < 0)
-                        log_warning("Failed to create mapping between service and user");
-        }
+                r = manager_start_unit(u->manager, service, &error, &job);
+                if (r < 0) {
+                        log_error("Failed to start user service: %s", bus_error(&error, r));
+                        dbus_error_free(&error);
 
 
-        r = manager_start_unit(u->manager, u->service, &error, &job);
-        if (r < 0) {
-                log_error("Failed to start user service: %s", bus_error(&error, r));
-                dbus_error_free(&error);
-        } else {
-                free(u->service_job);
-                u->service_job = job;
+                        free(service);
+                } else {
+                        u->service = service;
+
+                        free(u->service_job);
+                        u->service_job = job;
+                }
         }
 
         }
 
+        if (u->service)
+                hashmap_put(u->manager->user_units, u->service, u);
+
         return 0;
 }
 
         return 0;
 }
 
index 7d64abe..8e03ff2 100644 (file)
@@ -228,34 +228,36 @@ static int machine_start_scope(Machine *m) {
         dbus_error_init(&error);
 
         if (!m->scope) {
         dbus_error_init(&error);
 
         if (!m->scope) {
-                char *escaped = NULL;
+                _cleanup_free_ char *escaped = NULL;
+                char *scope;
 
                 escaped = unit_name_escape(m->name);
                 if (!escaped)
                         return log_oom();
 
 
                 escaped = unit_name_escape(m->name);
                 if (!escaped)
                         return log_oom();
 
-                m->scope = strjoin("machine-", escaped, ".scope", NULL);
-                free(escaped);
-
-                if (!m->scope)
+                scope = strjoin("machine-", escaped, ".scope", NULL);
+                if (scope)
                         return log_oom();
 
                         return log_oom();
 
-                r = hashmap_put(m->manager->machine_units, m->scope, m);
-                if (r < 0)
-                        log_warning("Failed to create mapping between unit and machine");
-        }
+                description = strappend(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
 
 
-        description = strappend(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
+                r = manager_start_scope(m->manager, m->scope, m->leader, SPECIAL_MACHINE_SLICE, description, &error, &job);
+                if (r < 0) {
+                        log_error("Failed to start machine scope: %s", bus_error(&error, r));
+                        dbus_error_free(&error);
 
 
-        r = manager_start_scope(m->manager, m->scope, m->leader, SPECIAL_MACHINE_SLICE, description, &error, &job);
-        if (r < 0) {
-                log_error("Failed to start machine scope: %s", bus_error(&error, r));
-                dbus_error_free(&error);
-        } else {
-                free(m->scope_job);
-                m->scope_job = job;
+                        free(scope);
+                } else {
+                        m->scope = scope;
+
+                        free(m->scope_job);
+                        m->scope_job = job;
+                }
         }
 
         }
 
+        if (m->scope)
+                hashmap_put(m->manager->machine_units, m->scope, m);
+
         return r;
 }
 
         return r;
 }