1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "alloc-util.h"
7 #include "bus-common-errors.h"
9 #include "bus-locator.h"
11 #include "cgroup-util.h"
12 #include "clean-ipc.h"
17 #include "format-util.h"
20 #include "label-util.h"
21 #include "limits-util.h"
22 #include "logind-dbus.h"
23 #include "logind-user-dbus.h"
24 #include "logind-user.h"
25 #include "mkdir-label.h"
26 #include "parse-util.h"
27 #include "path-util.h"
28 #include "percent-util.h"
30 #include "serialize.h"
32 #include "stdio-util.h"
33 #include "string-table.h"
35 #include "tmpfile-util.h"
36 #include "uid-classification.h"
37 #include "unit-name.h"
38 #include "user-util.h"
40 int user_new(Manager
*m
, UserRecord
*ur
, User
**ret
) {
41 _cleanup_(user_freep
) User
*u
= NULL
;
42 char lu
[DECIMAL_STR_MAX(uid_t
) + 1];
52 if (!uid_is_valid(ur
->uid
))
61 .user_record
= user_record_ref(ur
),
62 .last_session_timestamp
= USEC_INFINITY
,
63 .gc_mode
= USER_GC_BY_ANY
,
66 if (asprintf(&u
->state_file
, "/run/systemd/users/" UID_FMT
, ur
->uid
) < 0)
69 if (asprintf(&u
->runtime_path
, "/run/user/" UID_FMT
, ur
->uid
) < 0)
72 xsprintf(lu
, UID_FMT
, ur
->uid
);
73 r
= slice_build_subslice(SPECIAL_USER_SLICE
, lu
, &u
->slice
);
77 r
= unit_name_build("user-runtime-dir", lu
, ".service", &u
->runtime_dir_unit
);
81 r
= unit_name_build("user", lu
, ".service", &u
->service_manager_unit
);
85 r
= hashmap_put(m
->users
, UID_TO_PTR(ur
->uid
), u
);
89 r
= hashmap_put(m
->user_units
, u
->slice
, u
);
93 r
= hashmap_put(m
->user_units
, u
->runtime_dir_unit
, u
);
97 r
= hashmap_put(m
->user_units
, u
->service_manager_unit
, u
);
105 User
*user_free(User
*u
) {
110 LIST_REMOVE(gc_queue
, u
->manager
->user_gc_queue
, u
);
113 session_free(u
->sessions
);
115 sd_event_source_unref(u
->timer_event_source
);
117 if (u
->service_manager_unit
) {
118 (void) hashmap_remove_value(u
->manager
->user_units
, u
->service_manager_unit
, u
);
119 free(u
->service_manager_job
);
120 free(u
->service_manager_unit
);
123 if (u
->runtime_dir_unit
) {
124 (void) hashmap_remove_value(u
->manager
->user_units
, u
->runtime_dir_unit
, u
);
125 free(u
->runtime_dir_job
);
126 free(u
->runtime_dir_unit
);
130 (void) hashmap_remove_value(u
->manager
->user_units
, u
->slice
, u
);
134 (void) hashmap_remove_value(u
->manager
->users
, UID_TO_PTR(u
->user_record
->uid
), u
);
136 free(u
->runtime_path
);
139 user_record_unref(u
->user_record
);
144 static int user_save_internal(User
*u
) {
145 _cleanup_(unlink_and_freep
) char *temp_path
= NULL
;
146 _cleanup_fclose_
FILE *f
= NULL
;
150 assert(u
->state_file
);
152 r
= mkdir_safe_label("/run/systemd/users", 0755, 0, 0, MKDIR_WARN_MODE
);
156 r
= fopen_temporary(u
->state_file
, &f
, &temp_path
);
160 (void) fchmod(fileno(f
), 0644);
163 "# This is private data. Do not parse.\n"
165 "STATE=%s\n" /* friendly user-facing state */
166 "STOPPING=%s\n" /* low-level state */
168 u
->user_record
->user_name
,
169 user_state_to_string(user_get_state(u
)),
171 user_gc_mode_to_string(u
->gc_mode
));
173 /* LEGACY: no-one reads RUNTIME= anymore, drop it at some point */
175 fprintf(f
, "RUNTIME=%s\n", u
->runtime_path
);
177 if (u
->runtime_dir_job
)
178 fprintf(f
, "RUNTIME_DIR_JOB=%s\n", u
->runtime_dir_job
);
180 if (u
->service_manager_job
)
181 fprintf(f
, "SERVICE_JOB=%s\n", u
->service_manager_job
);
184 fprintf(f
, "DISPLAY=%s\n", u
->display
->id
);
186 if (dual_timestamp_is_set(&u
->timestamp
))
188 "REALTIME="USEC_FMT
"\n"
189 "MONOTONIC="USEC_FMT
"\n",
190 u
->timestamp
.realtime
,
191 u
->timestamp
.monotonic
);
193 if (u
->last_session_timestamp
!= USEC_INFINITY
)
194 fprintf(f
, "LAST_SESSION_TIMESTAMP=" USEC_FMT
"\n",
195 u
->last_session_timestamp
);
200 fputs("SESSIONS=", f
);
202 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
211 fputs("\nSEATS=", f
);
213 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
222 fputs(i
->seat
->id
, f
);
225 fputs("\nACTIVE_SESSIONS=", f
);
227 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
228 if (!session_is_active(i
))
239 fputs("\nONLINE_SESSIONS=", f
);
241 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
242 if (session_get_state(i
) == SESSION_CLOSING
)
253 fputs("\nACTIVE_SEATS=", f
);
255 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
256 if (!session_is_active(i
) || !i
->seat
)
264 fputs(i
->seat
->id
, f
);
267 fputs("\nONLINE_SEATS=", f
);
269 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
270 if (session_get_state(i
) == SESSION_CLOSING
|| !i
->seat
)
278 fputs(i
->seat
->id
, f
);
283 r
= fflush_and_check(f
);
287 if (rename(temp_path
, u
->state_file
) < 0) {
292 temp_path
= mfree(temp_path
);
296 (void) unlink(u
->state_file
);
298 return log_error_errno(r
, "Failed to save user data %s: %m", u
->state_file
);
301 int user_save(User
*u
) {
307 return user_save_internal(u
);
310 int user_load(User
*u
) {
311 _cleanup_free_
char *realtime
= NULL
, *monotonic
= NULL
, *stopping
= NULL
, *last_session_timestamp
= NULL
, *gc_mode
= NULL
;
316 r
= parse_env_file(NULL
, u
->state_file
,
317 "RUNTIME_DIR_JOB", &u
->runtime_dir_job
,
318 "SERVICE_JOB", &u
->service_manager_job
,
319 "STOPPING", &stopping
,
320 "REALTIME", &realtime
,
321 "MONOTONIC", &monotonic
,
322 "LAST_SESSION_TIMESTAMP", &last_session_timestamp
,
323 "GC_MODE", &gc_mode
);
327 return log_error_errno(r
, "Failed to read %s: %m", u
->state_file
);
330 r
= parse_boolean(stopping
);
332 log_debug_errno(r
, "Failed to parse 'STOPPING' boolean: %s", stopping
);
335 if (u
->stopping
&& !u
->runtime_dir_job
)
336 log_debug("User '%s' is stopping, but no job is being tracked.", u
->user_record
->user_name
);
341 (void) deserialize_usec(realtime
, &u
->timestamp
.realtime
);
343 (void) deserialize_usec(monotonic
, &u
->timestamp
.monotonic
);
344 if (last_session_timestamp
)
345 (void) deserialize_usec(last_session_timestamp
, &u
->last_session_timestamp
);
347 u
->gc_mode
= user_gc_mode_from_string(gc_mode
);
349 u
->gc_mode
= USER_GC_BY_PIN
;
354 static int user_start_runtime_dir(User
*u
) {
355 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
359 assert(!u
->stopping
);
361 assert(u
->runtime_dir_unit
);
363 u
->runtime_dir_job
= mfree(u
->runtime_dir_job
);
365 r
= manager_start_unit(u
->manager
, u
->runtime_dir_unit
, &error
, &u
->runtime_dir_job
);
367 return log_full_errno(sd_bus_error_has_name(&error
, BUS_ERROR_UNIT_MASKED
) ? LOG_DEBUG
: LOG_ERR
,
368 r
, "Failed to start user service '%s': %s",
369 u
->runtime_dir_unit
, bus_error_message(&error
, r
));
374 static bool user_wants_service_manager(User
*u
) {
377 LIST_FOREACH(sessions_by_user
, s
, u
->sessions
)
378 if (SESSION_CLASS_WANTS_SERVICE_MANAGER(s
->class))
384 int user_start_service_manager(User
*u
) {
385 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
389 assert(!u
->stopping
);
391 assert(u
->service_manager_unit
);
393 if (u
->service_manager_started
)
396 /* Only start user service manager if there's at least one session which wants it */
397 if (!user_wants_service_manager(u
))
400 u
->service_manager_job
= mfree(u
->service_manager_job
);
402 r
= manager_start_unit(u
->manager
, u
->service_manager_unit
, &error
, &u
->service_manager_job
);
404 if (sd_bus_error_has_name(&error
, BUS_ERROR_UNIT_MASKED
))
407 return log_error_errno(r
, "Failed to start user service '%s': %s",
408 u
->service_manager_unit
, bus_error_message(&error
, r
));
411 return (u
->service_manager_started
= true);
414 static int update_slice_callback(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
415 _cleanup_(user_record_unrefp
) UserRecord
*ur
= ASSERT_PTR(userdata
);
416 const sd_bus_error
*e
;
421 e
= sd_bus_message_get_error(m
);
423 r
= sd_bus_error_get_errno(e
);
425 "Failed to update slice of %s, ignoring: %s",
427 bus_error_message(e
, r
));
432 log_debug("Successfully set slice parameters of %s.", ur
->user_name
);
436 static int user_update_slice(User
*u
) {
437 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
442 if (u
->user_record
->tasks_max
== UINT64_MAX
&&
443 u
->user_record
->memory_high
== UINT64_MAX
&&
444 u
->user_record
->memory_max
== UINT64_MAX
&&
445 u
->user_record
->cpu_weight
== UINT64_MAX
&&
446 u
->user_record
->io_weight
== UINT64_MAX
)
449 r
= bus_message_new_method_call(u
->manager
->bus
, &m
, bus_systemd_mgr
, "SetUnitProperties");
451 return bus_log_create_error(r
);
453 r
= sd_bus_message_append(m
, "sb", u
->slice
, true);
455 return bus_log_create_error(r
);
457 r
= sd_bus_message_open_container(m
, 'a', "(sv)");
459 return bus_log_create_error(r
);
465 { "TasksMax", u
->user_record
->tasks_max
},
466 { "MemoryMax", u
->user_record
->memory_max
},
467 { "MemoryHigh", u
->user_record
->memory_high
},
468 { "CPUWeight", u
->user_record
->cpu_weight
},
469 { "IOWeight", u
->user_record
->io_weight
},
472 FOREACH_ELEMENT(st
, settings
) {
473 if (st
->value
== UINT64_MAX
)
476 r
= sd_bus_message_append(m
, "(sv)", st
->name
, "t", st
->value
);
478 return bus_log_create_error(r
);
481 r
= sd_bus_message_close_container(m
);
483 return bus_log_create_error(r
);
485 r
= sd_bus_call_async(u
->manager
->bus
, NULL
, m
, update_slice_callback
, u
->user_record
, 0);
487 return log_error_errno(r
, "Failed to change user slice properties: %m");
489 /* Ref the user record pointer, so that the slot keeps it pinned */
490 user_record_ref(u
->user_record
);
495 int user_start(User
*u
) {
500 if (u
->service_manager_started
) {
501 /* Everything is up. No action needed. */
502 assert(u
->started
&& !u
->stopping
);
506 if (!u
->started
|| u
->stopping
) {
507 /* If u->stopping is set, the user is marked for removal and service stop-jobs are queued.
508 * We have to clear that flag before queueing the start-jobs again. If they succeed, the
509 * user object can be re-used just fine (pid1 takes care of job-ordering and proper restart),
510 * but if they fail, we want to force another user_stop() so possibly pending units are
515 log_debug("Tracking new user %s.", u
->user_record
->user_name
);
517 /* Save the user data so far, because pam_systemd will read the XDG_RUNTIME_DIR out of it
518 * while starting up systemd --user. We need to do user_save_internal() because we have not
519 * "officially" started yet. */
520 user_save_internal(u
);
522 /* Set slice parameters */
523 (void) user_update_slice(u
);
525 (void) user_start_runtime_dir(u
);
528 /* Start user@UID.service if needed. */
529 r
= user_start_service_manager(u
);
534 if (!dual_timestamp_is_set(&u
->timestamp
))
535 dual_timestamp_now(&u
->timestamp
);
537 user_send_signal(u
, true);
541 /* Save new user data */
547 static void user_stop_service(User
*u
, bool force
) {
548 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
553 assert(u
->runtime_dir_unit
);
555 /* Note that we only stop user-runtime-dir@.service here, and let BindsTo= deal with the user@.service
556 * instance. However, we still need to clear service_manager_job here, so that if the stop is
557 * interrupted, the new sessions won't be confused by leftovers. */
559 u
->service_manager_job
= mfree(u
->service_manager_job
);
560 u
->service_manager_started
= false;
562 u
->runtime_dir_job
= mfree(u
->runtime_dir_job
);
564 r
= manager_stop_unit(u
->manager
, u
->runtime_dir_unit
, force
? "replace" : "fail", &error
, &u
->runtime_dir_job
);
566 log_warning_errno(r
, "Failed to stop user service '%s', ignoring: %s",
567 u
->runtime_dir_unit
, bus_error_message(&error
, r
));
570 int user_stop(User
*u
, bool force
) {
575 /* This is called whenever we begin with tearing down a user record. It's called in two cases: explicit API
576 * request to do so via the bus (in which case 'force' is true) and automatically due to GC, if there's no
577 * session left pinning it (in which case 'force' is false). Note that this just initiates tearing down of the
578 * user, the User object will remain in memory until user_finalize() is called, see below. */
583 if (u
->stopping
) { /* Stop jobs have already been queued */
588 LIST_FOREACH(sessions_by_user
, s
, u
->sessions
)
589 RET_GATHER(r
, session_stop(s
, force
));
591 user_stop_service(u
, force
);
600 int user_finalize(User
*u
) {
605 /* Called when the user is really ready to be freed, i.e. when all unit stop jobs and suchlike for it are
606 * done. This is called as a result of an earlier user_done() when all jobs are completed. */
609 log_debug("User %s exited.", u
->user_record
->user_name
);
611 LIST_FOREACH(sessions_by_user
, s
, u
->sessions
)
612 RET_GATHER(r
, session_finalize(s
));
614 /* Clean SysV + POSIX IPC objects, but only if this is not a system user. Background: in many setups cronjobs
615 * are run in full PAM and thus logind sessions, even if the code run doesn't belong to actual users but to
616 * system components. Since enable RemoveIPC= globally for all users, we need to be a bit careful with such
617 * cases, as we shouldn't accidentally remove a system service's IPC objects while it is running, just because
618 * a cronjob running as the same user just finished. Hence: exclude system users generally from IPC clean-up,
619 * and do it only for normal users. */
620 if (u
->manager
->remove_ipc
&& !uid_is_system(u
->user_record
->uid
))
621 RET_GATHER(r
, clean_ipc_by_uid(u
->user_record
->uid
));
623 (void) unlink(u
->state_file
);
624 user_add_to_gc_queue(u
);
627 user_send_signal(u
, false);
634 int user_get_idle_hint(User
*u
, dual_timestamp
*t
) {
635 bool idle_hint
= true;
636 dual_timestamp ts
= DUAL_TIMESTAMP_NULL
;
640 LIST_FOREACH(sessions_by_user
, s
, u
->sessions
) {
644 if (!SESSION_CLASS_CAN_IDLE(s
->class))
647 ih
= session_get_idle_hint(s
, &k
);
653 if (k
.monotonic
< ts
.monotonic
)
659 } else if (idle_hint
) {
661 if (k
.monotonic
> ts
.monotonic
)
672 int user_check_linger_file(User
*u
) {
673 _cleanup_free_
char *cc
= NULL
;
676 cc
= cescape(u
->user_record
->user_name
);
680 p
= strjoina("/var/lib/systemd/linger/", cc
);
681 if (access(p
, F_OK
) < 0) {
691 static bool user_unit_active(User
*u
) {
695 assert(u
->runtime_dir_unit
);
696 assert(u
->service_manager_unit
);
698 FOREACH_STRING(i
, u
->slice
, u
->runtime_dir_unit
, u
->service_manager_unit
) {
699 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
701 r
= manager_unit_is_active(u
->manager
, i
, &error
);
703 log_debug_errno(r
, "Failed to determine whether unit '%s' is active, ignoring: %s", i
, bus_error_message(&error
, r
));
711 static usec_t
user_get_stop_delay(User
*u
) {
714 if (u
->user_record
->stop_delay_usec
!= UINT64_MAX
)
715 return u
->user_record
->stop_delay_usec
;
717 if (user_record_removable(u
->user_record
) > 0)
718 return 0; /* For removable users lower the stop delay to zero */
720 return u
->manager
->user_stop_delay
;
723 static bool user_pinned_by_sessions(User
*u
) {
726 /* Returns true if at least one session exists that shall keep the user tracking alive. That
727 * generally means one session that isn't the service manager still exists. */
729 switch (u
->gc_mode
) {
735 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
)
736 if (SESSION_CLASS_PIN_USER(i
->class))
742 assert_not_reached();
746 bool user_may_gc(User
*u
, bool drop_not_started
) {
751 if (drop_not_started
&& !u
->started
)
754 if (user_pinned_by_sessions(u
))
757 if (u
->last_session_timestamp
!= USEC_INFINITY
) {
758 usec_t user_stop_delay
;
760 /* All sessions have been closed. Let's see if we shall leave the user record around for a bit */
762 user_stop_delay
= user_get_stop_delay(u
);
764 if (user_stop_delay
== USEC_INFINITY
)
765 return false; /* Leave it around forever! */
766 if (user_stop_delay
> 0 &&
767 now(CLOCK_MONOTONIC
) < usec_add(u
->last_session_timestamp
, user_stop_delay
))
768 return false; /* Leave it around for a bit longer. */
771 /* Is this a user that shall stay around forever ("linger")? Before we say "no" to GC'ing for lingering users, let's check
772 * if any of the three units that we maintain for this user is still around. If none of them is,
773 * there's no need to keep this user around even if lingering is enabled. */
774 if (user_check_linger_file(u
) > 0 && user_unit_active(u
))
777 /* Check if our job is still pending */
779 FOREACH_ARGUMENT(j
, u
->runtime_dir_job
, u
->service_manager_job
) {
780 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
785 r
= manager_job_is_active(u
->manager
, j
, &error
);
787 log_debug_errno(r
, "Failed to determine whether job '%s' is pending, ignoring: %s",
788 j
, bus_error_message(&error
, r
));
793 /* Note that we don't care if the three units we manage for each user object are up or not, as we are
794 * managing their state rather than tracking it. */
799 void user_add_to_gc_queue(User
*u
) {
805 LIST_PREPEND(gc_queue
, u
->manager
->user_gc_queue
, u
);
806 u
->in_gc_queue
= true;
809 UserState
user_get_state(User
*u
) {
815 if (!u
->started
|| u
->runtime_dir_job
)
818 bool any
= false, all_closing
= true;
819 LIST_FOREACH(sessions_by_user
, i
, u
->sessions
) {
822 /* Ignore sessions that don't pin the user, i.e. are not supposed to have an effect on user state */
823 if (!SESSION_CLASS_PIN_USER(i
->class))
826 state
= session_get_state(i
);
827 if (state
== SESSION_ACTIVE
)
829 if (state
!= SESSION_CLOSING
)
836 return all_closing
? USER_CLOSING
: USER_ONLINE
;
838 if (user_check_linger_file(u
) > 0 && user_unit_active(u
))
839 return USER_LINGERING
;
844 int user_kill(User
*u
, int signo
) {
847 return manager_kill_unit(u
->manager
, u
->slice
, KILL_ALL
, signo
, NULL
);
850 static bool elect_display_filter(Session
*s
) {
851 /* Return true if the session is a candidate for the user’s ‘primary session’ or ‘display’. */
854 return SESSION_CLASS_CAN_DISPLAY(s
->class) && s
->started
&& !s
->stopping
;
857 static int elect_display_compare(Session
*s1
, Session
*s2
) {
858 /* Indexed by SessionType. Lower numbers mean more preferred. */
859 static const int type_ranks
[_SESSION_TYPE_MAX
] = {
860 [SESSION_UNSPECIFIED
] = 0,
863 [SESSION_WAYLAND
] = -3,
868 /* Calculate the partial order relationship between s1 and s2,
869 * returning < 0 if s1 is preferred as the user’s ‘primary session’,
870 * 0 if s1 and s2 are equally preferred or incomparable, or > 0 if s2
873 * s1 or s2 may be NULL. */
877 if ((s1
== NULL
) != (s2
== NULL
))
878 return (s1
== NULL
) - (s2
== NULL
);
880 if (s1
->stopping
!= s2
->stopping
)
881 return s1
->stopping
- s2
->stopping
;
883 if ((s1
->class != SESSION_USER
) != (s2
->class != SESSION_USER
))
884 return (s1
->class != SESSION_USER
) - (s2
->class != SESSION_USER
);
886 if ((s1
->class != SESSION_USER_EARLY
) != (s2
->class != SESSION_USER_EARLY
))
887 return (s1
->class != SESSION_USER_EARLY
) - (s2
->class != SESSION_USER_EARLY
);
889 if ((s1
->type
== _SESSION_TYPE_INVALID
) != (s2
->type
== _SESSION_TYPE_INVALID
))
890 return (s1
->type
== _SESSION_TYPE_INVALID
) - (s2
->type
== _SESSION_TYPE_INVALID
);
892 if (s1
->type
!= s2
->type
)
893 return type_ranks
[s1
->type
] - type_ranks
[s2
->type
];
898 void user_elect_display(User
*u
) {
901 /* This elects a primary session for each user, which we call the "display". We try to keep the assignment
902 * stable, but we "upgrade" to better choices. */
903 log_debug("Electing new display for user %s", u
->user_record
->user_name
);
905 LIST_FOREACH(sessions_by_user
, s
, u
->sessions
) {
906 if (!elect_display_filter(s
)) {
907 log_debug("Ignoring session %s", s
->id
);
911 if (elect_display_compare(s
, u
->display
) < 0) {
912 log_debug("Choosing session %s in preference to %s", s
->id
, u
->display
? u
->display
->id
: "-");
918 static int user_stop_timeout_callback(sd_event_source
*es
, uint64_t usec
, void *userdata
) {
919 User
*u
= ASSERT_PTR(userdata
);
921 user_add_to_gc_queue(u
);
926 void user_update_last_session_timer(User
*u
) {
927 usec_t user_stop_delay
;
932 if (user_pinned_by_sessions(u
)) {
933 /* There are sessions, turn off the timer */
934 u
->last_session_timestamp
= USEC_INFINITY
;
935 u
->timer_event_source
= sd_event_source_unref(u
->timer_event_source
);
939 if (u
->last_session_timestamp
!= USEC_INFINITY
)
940 return; /* Timer already started */
942 u
->last_session_timestamp
= now(CLOCK_MONOTONIC
);
944 assert(!u
->timer_event_source
);
946 user_stop_delay
= user_get_stop_delay(u
);
947 if (!timestamp_is_set(user_stop_delay
))
950 if (sd_event_get_state(u
->manager
->event
) == SD_EVENT_FINISHED
) {
951 log_debug("Not allocating user stop timeout, since we are already exiting.");
955 r
= sd_event_add_time(u
->manager
->event
,
956 &u
->timer_event_source
,
958 usec_add(u
->last_session_timestamp
, user_stop_delay
), 0,
959 user_stop_timeout_callback
, u
);
961 log_warning_errno(r
, "Failed to enqueue user stop event source, ignoring: %m");
964 log_debug("Last session of user '%s' logged out, terminating user context in %s.",
965 u
->user_record
->user_name
,
966 FORMAT_TIMESPAN(user_stop_delay
, USEC_PER_MSEC
));
969 static const char* const user_state_table
[_USER_STATE_MAX
] = {
970 [USER_OFFLINE
] = "offline",
971 [USER_OPENING
] = "opening",
972 [USER_LINGERING
] = "lingering",
973 [USER_ONLINE
] = "online",
974 [USER_ACTIVE
] = "active",
975 [USER_CLOSING
] = "closing"
978 DEFINE_STRING_TABLE_LOOKUP(user_state
, UserState
);
980 static const char* const user_gc_mode_table
[_USER_GC_MODE_MAX
] = {
981 [USER_GC_BY_PIN
] = "pin",
982 [USER_GC_BY_ANY
] = "any",
985 DEFINE_STRING_TABLE_LOOKUP(user_gc_mode
, UserGCMode
);
987 int config_parse_tmpfs_size(
989 const char *filename
,
992 unsigned section_line
,
999 uint64_t *sz
= ASSERT_PTR(data
);
1006 /* First, try to parse as percentage */
1007 r
= parse_permyriad(rvalue
);
1009 *sz
= physical_memory_scale(r
, 10000U);
1013 /* If the passed argument was not a percentage, or out of range, parse as byte size */
1015 r
= parse_size(rvalue
, 1024, &k
);
1016 if (r
>= 0 && (k
<= 0 || (uint64_t) (size_t) k
!= k
))
1019 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse size value '%s', ignoring: %m", rvalue
);
1023 *sz
= PAGE_ALIGN((size_t) k
);
1029 int config_parse_compat_user_tasks_max(
1031 const char *filename
,
1033 const char *section
,
1034 unsigned section_line
,
1045 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1046 "Support for option %s= has been removed.",
1048 log_info("Hint: try creating /etc/systemd/system/user-.slice.d/50-limits.conf with:\n"