]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-session.h
hibernate-resume: add resumeflags= kernel option
[thirdparty/systemd.git] / src / login / logind-session.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 typedef struct Session Session;
5 typedef enum KillWho KillWho;
6
7 #include "list.h"
8 #include "login-util.h"
9 #include "logind-user.h"
10
11 typedef enum SessionState {
12 SESSION_OPENING, /* Session scope is being created */
13 SESSION_ONLINE, /* Logged in */
14 SESSION_ACTIVE, /* Logged in and in the fg */
15 SESSION_CLOSING, /* Logged out, but scope is still there */
16 _SESSION_STATE_MAX,
17 _SESSION_STATE_INVALID = -1
18 } SessionState;
19
20 typedef enum SessionClass {
21 SESSION_USER,
22 SESSION_GREETER,
23 SESSION_LOCK_SCREEN,
24 SESSION_BACKGROUND,
25 _SESSION_CLASS_MAX,
26 _SESSION_CLASS_INVALID = -1
27 } SessionClass;
28
29 typedef enum SessionType {
30 SESSION_UNSPECIFIED,
31 SESSION_TTY,
32 SESSION_X11,
33 SESSION_WAYLAND,
34 SESSION_MIR,
35 SESSION_WEB,
36 _SESSION_TYPE_MAX,
37 _SESSION_TYPE_INVALID = -1
38 } SessionType;
39
40 #define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
41
42 enum KillWho {
43 KILL_LEADER,
44 KILL_ALL,
45 _KILL_WHO_MAX,
46 _KILL_WHO_INVALID = -1
47 };
48
49 typedef enum TTYValidity {
50 TTY_FROM_PAM,
51 TTY_FROM_UTMP,
52 TTY_UTMP_INCONSISTENT, /* may happen on ssh sessions with multiplexed TTYs */
53 _TTY_VALIDITY_MAX,
54 _TTY_VALIDITY_INVALID = -1,
55 } TTYValidity;
56
57 struct Session {
58 Manager *manager;
59
60 const char *id;
61 unsigned position;
62 SessionType type;
63 SessionClass class;
64
65 char *state_file;
66
67 User *user;
68
69 dual_timestamp timestamp;
70
71 char *display;
72 char *tty;
73 TTYValidity tty_validity;
74
75 bool remote;
76 char *remote_user;
77 char *remote_host;
78 char *service;
79 char *desktop;
80
81 char *scope;
82 char *scope_job;
83
84 Seat *seat;
85 unsigned vtnr;
86 int vtfd;
87
88 pid_t leader;
89 uint32_t audit_id;
90
91 int fifo_fd;
92 char *fifo_path;
93
94 sd_event_source *fifo_event_source;
95
96 bool idle_hint;
97 dual_timestamp idle_hint_timestamp;
98
99 bool locked_hint;
100
101 bool in_gc_queue:1;
102 bool started:1;
103 bool stopping:1;
104
105 bool was_active:1;
106
107 sd_bus_message *create_message;
108
109 /* Set up when a client requested to release the session via the bus */
110 sd_event_source *timer_event_source;
111
112 char *controller;
113 Hashmap *devices;
114 sd_bus_track *track;
115
116 LIST_FIELDS(Session, sessions_by_user);
117 LIST_FIELDS(Session, sessions_by_seat);
118
119 LIST_FIELDS(Session, gc_queue);
120 };
121
122 int session_new(Session **ret, Manager *m, const char *id);
123 Session* session_free(Session *s);
124
125 DEFINE_TRIVIAL_CLEANUP_FUNC(Session *, session_free);
126
127 void session_set_user(Session *s, User *u);
128 int session_set_leader(Session *s, pid_t pid);
129 bool session_may_gc(Session *s, bool drop_not_started);
130 void session_add_to_gc_queue(Session *s);
131 int session_activate(Session *s);
132 bool session_is_active(Session *s);
133 int session_get_idle_hint(Session *s, dual_timestamp *t);
134 void session_set_idle_hint(Session *s, bool b);
135 int session_get_locked_hint(Session *s);
136 void session_set_locked_hint(Session *s, bool b);
137 int session_create_fifo(Session *s);
138 int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error);
139 int session_stop(Session *s, bool force);
140 int session_finalize(Session *s);
141 int session_release(Session *s);
142 int session_save(Session *s);
143 int session_load(Session *s);
144 int session_kill(Session *s, KillWho who, int signo);
145
146 SessionState session_get_state(Session *u);
147
148 extern const sd_bus_vtable session_vtable[];
149 int session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
150 int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
151 char *session_bus_path(Session *s);
152
153 int session_send_signal(Session *s, bool new_session);
154 int session_send_changed(Session *s, const char *properties, ...) _sentinel_;
155 int session_send_lock(Session *s, bool lock);
156 int session_send_lock_all(Manager *m, bool lock);
157
158 int session_send_create_reply(Session *s, sd_bus_error *error);
159
160 const char* session_state_to_string(SessionState t) _const_;
161 SessionState session_state_from_string(const char *s) _pure_;
162
163 const char* session_type_to_string(SessionType t) _const_;
164 SessionType session_type_from_string(const char *s) _pure_;
165
166 const char* session_class_to_string(SessionClass t) _const_;
167 SessionClass session_class_from_string(const char *s) _pure_;
168
169 const char *kill_who_to_string(KillWho k) _const_;
170 KillWho kill_who_from_string(const char *s) _pure_;
171
172 const char* tty_validity_to_string(TTYValidity t) _const_;
173 TTYValidity tty_validity_from_string(const char *s) _pure_;
174
175 int session_prepare_vt(Session *s);
176 void session_leave_vt(Session *s);
177
178 bool session_is_controller(Session *s, const char *sender);
179 int session_set_controller(Session *s, const char *sender, bool force, bool prepare);
180 void session_drop_controller(Session *s);
181
182 int bus_session_method_activate(sd_bus_message *message, void *userdata, sd_bus_error *error);
183 int bus_session_method_lock(sd_bus_message *message, void *userdata, sd_bus_error *error);
184 int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error);
185 int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error);