1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 typedef struct User User
;
6 #include "conf-parser.h"
9 #include "user-record.h"
11 typedef enum UserState
{
12 USER_OFFLINE
, /* Not logged in at all */
13 USER_OPENING
, /* Is logging in */
14 USER_LINGERING
, /* Lingering has been enabled by the admin for this user */
15 USER_ONLINE
, /* User logged in */
16 USER_ACTIVE
, /* User logged in and has a session in the fg */
17 USER_CLOSING
, /* User logged out, but processes still remain and lingering is not enabled */
19 _USER_STATE_INVALID
= -EINVAL
,
22 typedef enum UserGCMode
{
23 USER_GC_BY_ANY
, /* any session pins this user */
24 USER_GC_BY_PIN
, /* only sessions with an explicitly pinning class pin this user */
26 _USER_GC_MODE_INVALID
= -EINVAL
,
32 UserRecord
*user_record
;
40 /* user-runtime-dir@UID.service */
41 char *runtime_dir_unit
;
42 char *runtime_dir_job
;
44 /* user@UID.service */
45 bool service_manager_started
;
46 char *service_manager_unit
;
47 char *service_manager_job
;
51 dual_timestamp timestamp
; /* When this User object was 'started' the first time */
52 usec_t last_session_timestamp
; /* When the number of sessions of this user went from 1 to 0 the last time */
54 /* Set up when the last session of the user logs out */
55 sd_event_source
*timer_event_source
;
60 bool started
:1; /* Whenever the user being started, has been started or is being stopped again
61 (tracked through user-runtime-dir@.service) */
62 bool stopping
:1; /* Whenever the user is being stopped or has been stopped. */
64 LIST_HEAD(Session
, sessions
);
65 LIST_FIELDS(User
, gc_queue
);
68 int user_new(Manager
*m
, UserRecord
*ur
, User
**ret
);
69 User
*user_free(User
*u
);
71 DEFINE_TRIVIAL_CLEANUP_FUNC(User
*, user_free
);
73 int user_start_service_manager(User
*u
);
74 int user_start(User
*u
);
76 bool user_may_gc(User
*u
, bool drop_not_started
);
77 void user_add_to_gc_queue(User
*u
);
78 int user_stop(User
*u
, bool force
);
79 int user_finalize(User
*u
);
80 UserState
user_get_state(User
*u
);
81 int user_get_idle_hint(User
*u
, dual_timestamp
*t
);
82 int user_save(User
*u
);
83 int user_load(User
*u
);
84 int user_kill(User
*u
, int signo
);
85 int user_check_linger_file(User
*u
);
86 void user_elect_display(User
*u
);
87 void user_update_last_session_timer(User
*u
);
89 const char* user_state_to_string(UserState s
) _const_
;
90 UserState
user_state_from_string(const char *s
) _pure_
;
92 const char* user_gc_mode_to_string(UserGCMode m
) _const_
;
93 UserGCMode
user_gc_mode_from_string(const char *s
) _pure_
;
95 CONFIG_PARSER_PROTOTYPE(config_parse_compat_user_tasks_max
);