chiark / gitweb /
Prep v230: Apply missing upstream fixes and updates (6/8) src/login.
[elogind.git] / src / login / logind-user.c
index ecc61080a322a6f321f723e6a222113d5bf6f0e1..a89d1bef7838cc834a230eb13b5bac5a23194f7f 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
@@ -122,11 +120,11 @@ User *user_free(User *u) {
 
         hashmap_remove_value(u->manager->users, UID_TO_PTR(u->uid), u);
 
-/// elogind neither supports slice nor service jobs.
-#if 0
+#if 0 /// elogind neither supports slice nor service jobs.
         u->slice_job = mfree(u->slice_job);
         u->service_job = mfree(u->service_job);
 #endif // 0
+
         u->service = mfree(u->service);
         u->slice = mfree(u->slice);
         u->runtime_path = mfree(u->runtime_path);
@@ -165,8 +163,7 @@ static int user_save_internal(User *u) {
         if (u->runtime_path)
                 fprintf(f, "RUNTIME=%s\n", u->runtime_path);
 
-/// elogind neither supports service nor slice jobs
-#if 0
+#if 0 /// elogind neither supports service nor slice jobs
         if (u->service_job)
                 fprintf(f, "SERVICE_JOB=%s\n", u->service_job);
 
@@ -308,8 +305,7 @@ int user_load(User *u) {
         assert(u);
 
         r = parse_env_file(u->state_file, NEWLINE,
-/// elogind neither supports service nor slice jobs
-#if 0
+#if 0 /// elogind neither supports service nor slice jobs
                            "SERVICE_JOB", &u->service_job,
                            "SLICE_JOB",   &u->slice_job,
 #endif // 0
@@ -331,17 +327,10 @@ int user_load(User *u) {
         if (s && s->display && display_is_local(s->display))
                 u->display = s;
 
-        if (realtime) {
-                unsigned long long l;
-                if (sscanf(realtime, "%llu", &l) > 0)
-                        u->timestamp.realtime = l;
-        }
-
-        if (monotonic) {
-                unsigned long long l;
-                if (sscanf(monotonic, "%llu", &l) > 0)
-                        u->timestamp.monotonic = l;
-        }
+        if (realtime)
+                timestamp_deserialize(realtime, &u->timestamp.realtime);
+        if (monotonic)
+                timestamp_deserialize(monotonic, &u->timestamp.monotonic);
 
         return r;
 }
@@ -395,15 +384,14 @@ static int user_mkdir_runtime_path(User *u) {
         return 0;
 
 fail:
-                /* Try to clean up, but ignore errors */
+        /* Try to clean up, but ignore errors */
         (void) rmdir(u->runtime_path);
         return r;
 }
 
 static int user_start_slice(User *u) {
-/// elogind can not ask systemd via dbus to start user services
-#if 0
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+#if 0 /// elogind can not ask systemd via dbus to start user services
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *description;
         char *job;
         int r;
@@ -422,13 +410,12 @@ static int user_start_slice(User *u) {
                         u->manager->user_tasks_max,
                         &error,
                         &job);
-                if (r < 0) {
+        if (r >= 0)
+                u->slice_job = job;
+        else if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS))
                 /* we don't fail due to this, let's try to continue */
-                if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS))
-                        log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", u->slice, bus_error_message(&error, r), error.name);
-                } else {
-                        u->slice_job = job;
-                }
+                log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)",
+                                u->slice, bus_error_message(&error, r), error.name);
 #else
         assert(u);
 
@@ -439,9 +426,8 @@ static int user_start_slice(User *u) {
 }
 
 static int user_start_service(User *u) {
-/// elogind can not ask systemd via dbus to start user services
-#if 0
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+#if 0 /// elogind can not ask systemd via dbus to start user services
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         char *job;
         int r;
 
@@ -454,11 +440,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 {
-                        u->service_job = job;
+        } else {
+                u->service_job = job;
         }
 #else
         assert(u);
@@ -530,10 +516,9 @@ int user_start(User *u) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 static int user_stop_slice(User *u) {
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         char *job;
         int r;
 
@@ -552,7 +537,7 @@ static int user_stop_slice(User *u) {
 }
 
 static int user_stop_service(User *u) {
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         char *job;
         int r;
 
@@ -612,8 +597,7 @@ int user_stop(User *u, bool force) {
         }
 
         /* Kill systemd */
-/// elogind does not support service or slice jobs
-#if 0
+#if 0 /// elogind does not support service or slice jobs
         k = user_stop_service(u);
         if (k < 0)
                 r = k;
@@ -730,8 +714,7 @@ bool user_check_gc(User *u, bool drop_not_started) {
         if (user_check_linger_file(u) > 0)
                 return true;
 
-/// elogind neither supports service nor slice jobs
-#if 0
+#if 0 /// elogind neither supports service nor slice jobs
         if (u->slice_job && manager_job_is_active(u->manager, u->slice_job))
                 return true;
 
@@ -760,8 +743,7 @@ UserState user_get_state(User *u) {
         if (u->stopping)
                 return USER_CLOSING;
 
-/// elogind neither supports service nor slice jobs.
-#if 0
+#if 0 /// elogind neither supports service nor slice jobs.
         if (!u->started || u->slice_job || u->service_job)
 #else
         if (!u->started)
@@ -791,8 +773,7 @@ UserState user_get_state(User *u) {
 }
 
 int user_kill(User *u, int signo) {
-/// Without systemd unit support, elogind has to rely on its session system
-#if 0
+#if 0 /// Without systemd unit support, elogind has to rely on its session system
         assert(u);
 
         return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL);
@@ -920,7 +901,7 @@ int config_parse_tmpfs_size(
 
                 errno = 0;
                 ul = strtoul(rvalue, &f, 10);
-                if (errno != 0 || f != e) {
+                if (errno > 0 || f != e) {
                         log_syntax(unit, LOG_ERR, filename, line, errno, "Failed to parse percentage value, ignoring: %s", rvalue);
                         return 0;
                 }