summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/login/logind-user.c52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 292a583103..b9d9d537e2 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -67,6 +67,7 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
u->manager = m;
u->uid = uid;
u->gid = gid;
+ xsprintf(lu, UID_FMT, uid);
u->name = strdup(name);
if (!u->name)
@@ -78,11 +79,14 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
if (asprintf(&u->runtime_path, "/run/user/"UID_FMT, uid) < 0)
return -ENOMEM;
- xsprintf(lu, UID_FMT, uid);
r = slice_build_subslice(SPECIAL_USER_SLICE, lu, &u->slice);
if (r < 0)
return r;
+ r = unit_name_build("user", lu, ".service", &u->service);
+ if (r < 0)
+ return r;
+
r = hashmap_put(m->users, UID_TO_PTR(uid), u);
if (r < 0)
return r;
@@ -91,6 +95,10 @@ int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
if (r < 0)
return r;
+ r = hashmap_put(m->user_units, u->service, u);
+ if (r < 0)
+ return r;
+
*out = u;
u = NULL;
return 0;
@@ -155,8 +163,6 @@ static int user_save_internal(User *u) {
if (u->runtime_path)
fprintf(f, "RUNTIME=%s\n", u->runtime_path);
- if (u->service)
- fprintf(f, "SERVICE=%s\n", u->service);
if (u->service_job)
fprintf(f, "SERVICE_JOB=%s\n", u->service_job);
@@ -297,7 +303,6 @@ int user_load(User *u) {
assert(u);
r = parse_env_file(u->state_file, NEWLINE,
- "SERVICE", &u->service,
"SERVICE_JOB", &u->service_job,
"SLICE_JOB", &u->slice_job,
"DISPLAY", &display,
@@ -425,34 +430,20 @@ static int user_start_service(User *u) {
assert(u);
- if (!u->service) {
- char lu[DECIMAL_STR_MAX(uid_t) + 1], *service;
-
- xsprintf(lu, UID_FMT, u->uid);
- r = unit_name_build("user", lu, ".service", &service);
- if (r < 0)
- return log_error_errno(r, "Failed to build service name: %m");
+ u->service_job = mfree(u->service_job);
- r = manager_start_unit(
- u->manager,
- service,
- &error,
- &job);
- if (r < 0) {
- log_error_errno(r, "Failed to start user service, ignoring: %s", bus_error_message(&error, r));
- free(service);
- /* we don't fail due to this, let's try to continue */
- } else {
- u->service = service;
-
- free(u->service_job);
- u->service_job = job;
- }
+ r = manager_start_unit(
+ u->manager,
+ u->service,
+ &error,
+ &job);
+ if (r < 0) {
+ /* we don't fail due to this, let's try to continue */
+ log_error_errno(r, "Failed to start user service, ignoring: %s", bus_error_message(&error, r));
+ } else {
+ u->service_job = job;
}
- if (u->service)
- (void) hashmap_put(u->manager->user_units, u->service, u);
-
return 0;
}
@@ -526,9 +517,6 @@ static int user_stop_service(User *u) {
assert(u);
- if (!u->service)
- return 0;
-
r = manager_stop_unit(u->manager, u->service, &error, &job);
if (r < 0) {
log_error("Failed to stop user service: %s", bus_error_message(&error, r));