chiark / gitweb /
Prep v225: Applying various fixes and changes to src/login that got lost during git...
[elogind.git] / src / login / logind-user.c
index 71bff96728fd1b733b1ccd654e729103549b74d2..987244e27ec1f2cfd5e55e699ca0376dce8ae0a9 100644 (file)
@@ -118,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);
 
@@ -243,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) {