X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind-user.c;h=987244e27ec1f2cfd5e55e699ca0376dce8ae0a9;hp=c0d0b967ae4c7e52fb5ddb1b9c50aac0b5ad945d;hb=1b99ea27bc3ffa1fc6f7cfe89563d891a9aed4c5;hpb=b1d35da9e405abaab2ff540baf2e54087f92e881 diff --git a/src/login/logind-user.c b/src/login/logind-user.c index c0d0b967a..987244e27 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -26,6 +26,7 @@ #include "util.h" #include "mkdir.h" +#include "rm-rf.h" #include "hashmap.h" #include "fileio.h" #include "path-util.h" @@ -37,6 +38,7 @@ #include "clean-ipc.h" #include "logind-user.h" #include "smack-util.h" +#include "formats-util.h" User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) { User *u; @@ -116,11 +118,11 @@ int user_save(User *u) { r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(u->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -241,19 +243,24 @@ int user_save(User *u) { fputc('\n', f); } - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, u->state_file) < 0) { + if (rename(temp_path, u->state_file) < 0) { r = -errno; - unlink(u->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save user data %s: %m", u->state_file); + return 0; - return r; +fail: + (void) unlink(u->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save user data %s: %m", u->state_file); } int user_load(User *u) { @@ -376,7 +383,7 @@ static int user_start_slice(User *u) { char lu[DECIMAL_STR_MAX(uid_t) + 1], *slice; sprintf(lu, UID_FMT, u->uid); - r = build_subslice(SPECIAL_USER_SLICE, lu, &slice); + r = slice_build_subslice(SPECIAL_USER_SLICE, lu, &slice); if (r < 0) return r; @@ -409,9 +416,9 @@ static int user_start_service(User *u) { char lu[DECIMAL_STR_MAX(uid_t) + 1], *service; sprintf(lu, UID_FMT, u->uid); - service = unit_name_build("user", lu, ".service"); - if (!service) - return log_oom(); + r = unit_name_build("user", lu, ".service", &service); + if (r < 0) + return log_error_errno(r, "Failed to build service name: %m"); r = manager_start_unit(u->manager, service, &error, &job); if (r < 0) { @@ -446,7 +453,6 @@ int user_start(User *u) { if (r < 0) return r; -#if 0 /* Create cgroup */ r = user_start_slice(u); if (r < 0) @@ -456,7 +462,6 @@ int user_start(User *u) { r = user_start_service(u); if (r < 0) return r; -#endif if (!dual_timestamp_is_set(&u->timestamp)) dual_timestamp_get(&u->timestamp); @@ -523,7 +528,7 @@ static int user_remove_runtime_path(User *u) { if (!u->runtime_path) return 0; - r = rm_rf(u->runtime_path, false, false, false); + r = rm_rf(u->runtime_path, 0); if (r < 0) log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path); @@ -534,7 +539,7 @@ static int user_remove_runtime_path(User *u) { if (r < 0 && errno != EINVAL && errno != ENOENT) log_error_errno(errno, "Failed to unmount user runtime directory %s: %m", u->runtime_path); - r = rm_rf(u->runtime_path, false, true, false); + r = rm_rf(u->runtime_path, REMOVE_ROOT); if (r < 0) log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);