| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "list.h" |
| 5 |
#include "logind-forward.h" |
| 6 |
#include "time-util.h" |
| 7 |
|
| 8 |
typedef enum UserState { |
| 9 |
USER_OFFLINE, /* Not logged in at all */ |
| 10 |
USER_OPENING, /* Is logging in */ |
| 11 |
USER_LINGERING, /* Lingering has been enabled by the admin for this user */ |
| 12 |
USER_ONLINE, /* User logged in */ |
| 13 |
USER_ACTIVE, /* User logged in and has a session in the fg */ |
| 14 |
USER_CLOSING, /* User logged out, but processes still remain and lingering is not enabled */ |
| 15 |
_USER_STATE_MAX, |
| 16 |
_USER_STATE_INVALID = -EINVAL, |
| 17 |
} UserState; |
| 18 |
|
| 19 |
typedef enum UserGCMode { |
| 20 |
USER_GC_BY_ANY, /* any session pins this user */ |
| 21 |
USER_GC_BY_PIN, /* only sessions with an explicitly pinning class pin this user */ |
| 22 |
_USER_GC_MODE_MAX, |
| 23 |
_USER_GC_MODE_INVALID = -EINVAL, |
| 24 |
} UserGCMode; |
| 25 |
|
| 26 |
typedef struct User { |
| 27 |
Manager *manager; |
| 28 |
|
| 29 |
UserRecord *user_record; |
| 30 |
|
| 31 |
char *state_file; |
| 32 |
char *runtime_path; |
| 33 |
|
| 34 |
/* user-UID.slice */ |
| 35 |
char *slice; |
| 36 |
|
| 37 |
/* [email protected] */ |
| 38 |
char *runtime_dir_unit; |
| 39 |
char *runtime_dir_job; |
| 40 |
|
| 41 |
/* [email protected] */ |
| 42 |
bool service_manager_started; |
| 43 |
char *service_manager_unit; |
| 44 |
char *service_manager_job; |
| 45 |
|
| 46 |
/* [email protected] — measures the user record into the 'login' NvPCR on first login. |
| 47 |
* Unlike the units above, logind starts this but never stops it: it must run exactly once per boot, |
| 48 |
* so it lives in system.slice, stays active until reboot, and is intentionally absent from |
| 49 |
* user_stop_service(). */ |
| 50 |
char *measure_unit; |
| 51 |
char *measure_job; |
| 52 |
|
| 53 |
Session *display; |
| 54 |
|
| 55 |
dual_timestamp timestamp; /* When this User object was 'started' the first time */ |
| 56 |
usec_t last_session_timestamp; /* When the number of sessions of this user went from 1 to 0 the last time */ |
| 57 |
|
| 58 |
/* Set up when the last session of the user logs out */ |
| 59 |
sd_event_source *timer_event_source; |
| 60 |
|
| 61 |
UserGCMode gc_mode; |
| 62 |
bool in_gc_queue:1; |
| 63 |
|
| 64 |
bool started:1; /* Whenever the user being started, has been started or is being stopped again |
| 65 |
(tracked through [email protected]) */ |
| 66 |
bool stopping:1; /* Whenever the user is being stopped or has been stopped. */ |
| 67 |
|
| 68 |
LIST_HEAD(Session, sessions); |
| 69 |
LIST_FIELDS(User, gc_queue); |
| 70 |
} User; |
| 71 |
|
| 72 |
int user_new(Manager *m, UserRecord *ur, User **ret); |
| 73 |
User *user_free(User *u); |
| 74 |
|
| 75 |
DEFINE_TRIVIAL_CLEANUP_FUNC(User*, user_free); |
| 76 |
|
| 77 |
int user_start_service_manager(User *u); |
| 78 |
int user_start(User *u); |
| 79 |
|
| 80 |
bool user_may_gc(User *u, bool drop_not_started); |
| 81 |
void user_add_to_gc_queue(User *u); |
| 82 |
int user_stop(User *u, bool force); |
| 83 |
int user_finalize(User *u); |
| 84 |
UserState user_get_state(User *u); |
| 85 |
bool user_get_idle_hint(User *u, dual_timestamp *ret_timestamp); |
| 86 |
int user_save(User *u); |
| 87 |
int user_load(User *u); |
| 88 |
int user_kill(User *u, int signo); |
| 89 |
int user_check_linger_file(const User *u); |
| 90 |
void user_elect_display(User *u); |
| 91 |
void user_update_last_session_timer(User *u); |
| 92 |
|
| 93 |
int user_build_json(User *u, sd_json_variant **ret); |
| 94 |
|
| 95 |
DECLARE_STRING_TABLE_LOOKUP(user_state, UserState); |
| 96 |
|
| 97 |
DECLARE_STRING_TABLE_LOOKUP(user_gc_mode, UserGCMode); |
| 98 |
|
| 99 |
CONFIG_PARSER_PROTOTYPE(config_parse_compat_user_tasks_max); |