1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 typedef struct User User;
5 
6 #include "conf-parser.h"
7 #include "list.h"
8 #include "logind.h"
9 #include "user-record.h"
10 
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 */
18         _USER_STATE_MAX,
19         _USER_STATE_INVALID = -EINVAL,
20 } UserState;
21 
22 struct User {
23         Manager *manager;
24 
25         UserRecord *user_record;
26 
27         char *state_file;
28         char *runtime_path;
29 
30         char *slice;                     /* user-UID.slice */
31         char *service;                   /* user@UID.service */
32         char *runtime_dir_service;       /* user-runtime-dir@UID.service */
33 
34         char *service_job;
35 
36         Session *display;
37 
38         dual_timestamp timestamp;      /* When this User object was 'started' the first time */
39         usec_t last_session_timestamp; /* When the number of sessions of this user went from 1 to 0 the last time */
40 
41         /* Set up when the last session of the user logs out */
42         sd_event_source *timer_event_source;
43 
44         bool in_gc_queue:1;
45 
46         bool started:1;       /* Whenever the user being started, has been started or is being stopped again. */
47         bool stopping:1;      /* Whenever the user is being stopped or has been stopped. */
48 
49         LIST_HEAD(Session, sessions);
50         LIST_FIELDS(User, gc_queue);
51 };
52 
53 int user_new(User **out, Manager *m, UserRecord *ur);
54 User *user_free(User *u);
55 
56 DEFINE_TRIVIAL_CLEANUP_FUNC(User *, user_free);
57 
58 bool user_may_gc(User *u, bool drop_not_started);
59 void user_add_to_gc_queue(User *u);
60 int user_start(User *u);
61 int user_stop(User *u, bool force);
62 int user_finalize(User *u);
63 UserState user_get_state(User *u);
64 int user_get_idle_hint(User *u, dual_timestamp *t);
65 int user_save(User *u);
66 int user_load(User *u);
67 int user_kill(User *u, int signo);
68 int user_check_linger_file(User *u);
69 void user_elect_display(User *u);
70 void user_update_last_session_timer(User *u);
71 
72 const char* user_state_to_string(UserState s) _const_;
73 UserState user_state_from_string(const char *s) _pure_;
74 
75 CONFIG_PARSER_PROTOTYPE(config_parse_compat_user_tasks_max);
76