1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 typedef struct Session Session
;
5 typedef enum KillWho KillWho
;
8 #include "login-util.h"
9 #include "logind-user.h"
10 #include "string-util.h"
12 typedef enum SessionState
{
13 SESSION_OPENING
, /* Session scope is being created */
14 SESSION_ONLINE
, /* Logged in */
15 SESSION_ACTIVE
, /* Logged in and in the fg */
16 SESSION_CLOSING
, /* Logged out, but scope is still there */
18 _SESSION_STATE_INVALID
= -1
21 typedef enum SessionClass
{
27 _SESSION_CLASS_INVALID
= -1
30 typedef enum SessionType
{
38 _SESSION_TYPE_INVALID
= -1
41 #define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
47 _KILL_WHO_INVALID
= -1
50 typedef enum TTYValidity
{
53 TTY_UTMP_INCONSISTENT
, /* may happen on ssh sessions with multiplexed TTYs */
55 _TTY_VALIDITY_INVALID
= -1,
70 dual_timestamp timestamp
;
74 TTYValidity tty_validity
;
95 sd_event_source
*fifo_event_source
;
98 dual_timestamp idle_hint_timestamp
;
108 sd_bus_message
*create_message
;
110 /* Set up when a client requested to release the session via the bus */
111 sd_event_source
*timer_event_source
;
117 LIST_FIELDS(Session
, sessions_by_user
);
118 LIST_FIELDS(Session
, sessions_by_seat
);
120 LIST_FIELDS(Session
, gc_queue
);
123 int session_new(Session
**ret
, Manager
*m
, const char *id
);
124 Session
* session_free(Session
*s
);
126 DEFINE_TRIVIAL_CLEANUP_FUNC(Session
*, session_free
);
128 void session_set_user(Session
*s
, User
*u
);
129 int session_set_leader(Session
*s
, pid_t pid
);
130 bool session_may_gc(Session
*s
, bool drop_not_started
);
131 void session_add_to_gc_queue(Session
*s
);
132 int session_activate(Session
*s
);
133 bool session_is_active(Session
*s
);
134 int session_get_idle_hint(Session
*s
, dual_timestamp
*t
);
135 void session_set_idle_hint(Session
*s
, bool b
);
136 int session_get_locked_hint(Session
*s
);
137 void session_set_locked_hint(Session
*s
, bool b
);
138 int session_create_fifo(Session
*s
);
139 int session_start(Session
*s
, sd_bus_message
*properties
, sd_bus_error
*error
);
140 int session_stop(Session
*s
, bool force
);
141 int session_finalize(Session
*s
);
142 int session_release(Session
*s
);
143 int session_save(Session
*s
);
144 int session_load(Session
*s
);
145 int session_kill(Session
*s
, KillWho who
, int signo
);
147 SessionState
session_get_state(Session
*u
);
149 extern const sd_bus_vtable session_vtable
[];
150 int session_node_enumerator(sd_bus
*bus
, const char *path
,void *userdata
, char ***nodes
, sd_bus_error
*error
);
151 int session_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
);
152 char *session_bus_path(Session
*s
);
154 int session_send_signal(Session
*s
, bool new_session
);
155 int session_send_changed(Session
*s
, const char *properties
, ...) _sentinel_
;
156 int session_send_lock(Session
*s
, bool lock
);
157 int session_send_lock_all(Manager
*m
, bool lock
);
159 int session_send_create_reply(Session
*s
, sd_bus_error
*error
);
161 const char* session_state_to_string(SessionState t
) _const_
;
162 SessionState
session_state_from_string(const char *s
) _pure_
;
164 const char* session_type_to_string(SessionType t
) _const_
;
165 SessionType
session_type_from_string(const char *s
) _pure_
;
167 const char* session_class_to_string(SessionClass t
) _const_
;
168 SessionClass
session_class_from_string(const char *s
) _pure_
;
170 const char *kill_who_to_string(KillWho k
) _const_
;
171 KillWho
kill_who_from_string(const char *s
) _pure_
;
173 const char* tty_validity_to_string(TTYValidity t
) _const_
;
174 TTYValidity
tty_validity_from_string(const char *s
) _pure_
;
176 int session_prepare_vt(Session
*s
);
177 void session_leave_vt(Session
*s
);
179 bool session_is_controller(Session
*s
, const char *sender
);
180 int session_set_controller(Session
*s
, const char *sender
, bool force
, bool prepare
);
181 void session_drop_controller(Session
*s
);
183 int bus_session_method_activate(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
184 int bus_session_method_lock(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
185 int bus_session_method_terminate(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
186 int bus_session_method_kill(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
188 static inline bool SESSION_IS_SELF(const char *name
) {
189 return isempty(name
) || streq(name
, "self");
192 static inline bool SESSION_IS_AUTO(const char *name
) {
193 return streq_ptr(name
, "auto");