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