]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/login/logind-user.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / login / logind-user.c
index 2dc5fa76658272d283985a93cc378ae63737585d..43a9f58adcd15c5557b3849de8dfef874eb5c418 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -32,7 +33,7 @@
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
 #include "label.h"
@@ -141,7 +142,7 @@ static int user_save_internal(User *u) {
         assert(u);
         assert(u->state_file);
 
-        r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0);
+        r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0, false);
         if (r < 0)
                 goto fail;
 
@@ -182,18 +183,18 @@ static int user_save_internal(User *u) {
                 Session *i;
                 bool first;
 
-                fputs("SESSIONS=", f);
+                fputs_unlocked("SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->id, f);
+                        fputs_unlocked(i->id, f);
                 }
 
-                fputs("\nSEATS=", f);
+                fputs_unlocked("\nSEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!i->seat)
@@ -202,12 +203,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->seat->id, f);
+                        fputs_unlocked(i->seat->id, f);
                 }
 
-                fputs("\nACTIVE_SESSIONS=", f);
+                fputs_unlocked("\nACTIVE_SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!session_is_active(i))
@@ -216,12 +217,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->id, f);
+                        fputs_unlocked(i->id, f);
                 }
 
-                fputs("\nONLINE_SESSIONS=", f);
+                fputs_unlocked("\nONLINE_SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (session_get_state(i) == SESSION_CLOSING)
@@ -230,12 +231,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->id, f);
+                        fputs_unlocked(i->id, f);
                 }
 
-                fputs("\nACTIVE_SEATS=", f);
+                fputs_unlocked("\nACTIVE_SEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!session_is_active(i) || !i->seat)
@@ -244,12 +245,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->seat->id, f);
+                        fputs_unlocked(i->seat->id, f);
                 }
 
-                fputs("\nONLINE_SEATS=", f);
+                fputs_unlocked("\nONLINE_SEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (session_get_state(i) == SESSION_CLOSING || !i->seat)
@@ -258,11 +259,11 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc(' ', f);
+                                fputc_unlocked(' ', f);
 
-                        fputs(i->seat->id, f);
+                        fputs_unlocked(i->seat->id, f);
                 }
-                fputc('\n', f);
+                fputc_unlocked('\n', f);
         }
 
         r = fflush_and_check(f);
@@ -334,11 +335,11 @@ static int user_mkdir_runtime_path(User *u) {
 
         assert(u);
 
-        r = mkdir_safe_label("/run/user", 0755, 0, 0);
+        r = mkdir_safe_label("/run/user", 0755, 0, 0, false);
         if (r < 0)
                 return log_error_errno(r, "Failed to create /run/user: %m");
 
-        if (path_is_mount_point(u->runtime_path, 0) <= 0) {
+        if (path_is_mount_point(u->runtime_path, NULL, 0) <= 0) {
                 _cleanup_free_ char *t = NULL;
 
                 (void) mkdir_label(u->runtime_path, 0700);
@@ -354,7 +355,7 @@ static int user_mkdir_runtime_path(User *u) {
 
                 r = mount("tmpfs", u->runtime_path, "tmpfs", MS_NODEV|MS_NOSUID, t);
                 if (r < 0) {
-                        if (errno != EPERM && errno != EACCES) {
+                        if (!IN_SET(errno, EPERM, EACCES)) {
                                 r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", u->runtime_path);
                                 goto fail;
                         }
@@ -425,12 +426,11 @@ static int user_start_service(User *u) {
                         u->service,
                         &error,
                         &job);
-        if (r < 0) {
+        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 {
+        else
                 u->service_job = job;
-        }
 
         return 0;
 }
@@ -541,18 +541,18 @@ static int user_remove_runtime_path(User *u) {
 
         r = rm_rf(u->runtime_path, 0);
         if (r < 0)
-                log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
+                log_error_errno(r, "Failed to remove runtime directory %s (before unmounting): %m", u->runtime_path);
 
         /* Ignore cases where the directory isn't mounted, as that's
          * quite possible, if we lacked the permissions to mount
          * something */
         r = umount2(u->runtime_path, MNT_DETACH);
-        if (r < 0 && errno != EINVAL && errno != ENOENT)
+        if (r < 0 && !IN_SET(errno, EINVAL, ENOENT))
                 log_error_errno(errno, "Failed to unmount user runtime directory %s: %m", u->runtime_path);
 
         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);
+                log_error_errno(r, "Failed to remove runtime directory %s (after unmounting): %m", u->runtime_path);
 
         return r;
 }