]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/login/logind-session.h
logind: rework how we manage the slice and user-runtime-dir@.service unit for each...
[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
90821c93
LP
49struct Session {
50 Manager *manager;
51
f7a5bb28 52 const char *id;
e6494a07 53 unsigned int position;
90821c93 54 SessionType type;
55efac6c 55 SessionClass class;
90821c93
LP
56
57 char *state_file;
58
59 User *user;
60
61 dual_timestamp timestamp;
62
63 char *tty;
64 char *display;
65
66 bool remote;
3f49d45a 67 char *remote_user;
90821c93 68 char *remote_host;
98a28fef 69 char *service;
a4cd87e9 70 char *desktop;
fb6becb4
LP
71
72 char *scope;
73 char *scope_job;
98a28fef 74
90821c93 75 Seat *seat;
92bd5ff3 76 unsigned int vtnr;
90a18413 77 int vtfd;
90821c93
LP
78
79 pid_t leader;
3f49d45a 80 uint32_t audit_id;
90821c93 81
932e3ee7
LP
82 int fifo_fd;
83 char *fifo_path;
90821c93 84
cc377381
LP
85 sd_event_source *fifo_event_source;
86
a185c5aa
LP
87 bool idle_hint;
88 dual_timestamp idle_hint_timestamp;
89
42d35e13
VT
90 bool locked_hint;
91
14c3baca 92 bool in_gc_queue:1;
9418f147 93 bool started:1;
5f41d1f1 94 bool stopping:1;
90821c93 95
aed24c4c
FB
96 bool was_active:1;
97
cc377381 98 sd_bus_message *create_message;
fb6becb4 99
5f41d1f1
LP
100 sd_event_source *timer_event_source;
101
ae5e06bd 102 char *controller;
118ecf32 103 Hashmap *devices;
3cde9e8f 104 sd_bus_track *track;
ae5e06bd 105
90821c93
LP
106 LIST_FIELDS(Session, sessions_by_user);
107 LIST_FIELDS(Session, sessions_by_seat);
14c3baca
LP
108
109 LIST_FIELDS(Session, gc_queue);
90821c93
LP
110};
111
8c29a457
LP
112int session_new(Session **ret, Manager *m, const char *id);
113Session* session_free(Session *s);
114
115DEFINE_TRIVIAL_CLEANUP_FUNC(Session *, session_free);
116
9444b1f2 117void session_set_user(Session *s, User *u);
5c093a23 118bool session_may_gc(Session *s, bool drop_not_started);
14c3baca 119void session_add_to_gc_queue(Session *s);
90821c93
LP
120int session_activate(Session *s);
121bool session_is_active(Session *s);
a185c5aa 122int session_get_idle_hint(Session *s, dual_timestamp *t);
bef422ae 123void session_set_idle_hint(Session *s, bool b);
42d35e13
VT
124int session_get_locked_hint(Session *s);
125void session_set_locked_hint(Session *s, bool b);
932e3ee7 126int session_create_fifo(Session *s);
25a1ab4e 127int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error);
9bb69af4 128int session_stop(Session *s, bool force);
405e0255 129int session_finalize(Session *s);
ad8780c9 130int session_release(Session *s);
90821c93
LP
131int session_save(Session *s);
132int session_load(Session *s);
de07ab16 133int session_kill(Session *s, KillWho who, int signo);
90821c93 134
0604381b
LP
135SessionState session_get_state(Session *u);
136
cc377381 137extern const sd_bus_vtable session_vtable[];
f00c3121
LP
138int session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
139int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
cc377381 140char *session_bus_path(Session *s);
3f49d45a 141
da119395 142int session_send_signal(Session *s, bool new_session);
cc377381 143int session_send_changed(Session *s, const char *properties, ...) _sentinel_;
88e3dc90 144int session_send_lock(Session *s, bool lock);
7ba64386 145int session_send_lock_all(Manager *m, bool lock);
da119395 146
cc377381 147int session_send_create_reply(Session *s, sd_bus_error *error);
fb6becb4 148
44a6b1b6
ZJS
149const char* session_state_to_string(SessionState t) _const_;
150SessionState session_state_from_string(const char *s) _pure_;
0604381b 151
44a6b1b6
ZJS
152const char* session_type_to_string(SessionType t) _const_;
153SessionType session_type_from_string(const char *s) _pure_;
90821c93 154
44a6b1b6
ZJS
155const char* session_class_to_string(SessionClass t) _const_;
156SessionClass session_class_from_string(const char *s) _pure_;
55efac6c 157
44a6b1b6
ZJS
158const char *kill_who_to_string(KillWho k) _const_;
159KillWho kill_who_from_string(const char *s) _pure_;
ae5e06bd 160
baccf3e4 161int session_prepare_vt(Session *s);
90a18413 162void session_restore_vt(Session *s);
2ec3ff66 163void session_leave_vt(Session *s);
90a18413 164
ae5e06bd 165bool session_is_controller(Session *s, const char *sender);
dc6284e9 166int session_set_controller(Session *s, const char *sender, bool force, bool prepare);
ae5e06bd 167void session_drop_controller(Session *s);
c529695e 168
19070062
LP
169int bus_session_method_activate(sd_bus_message *message, void *userdata, sd_bus_error *error);
170int bus_session_method_lock(sd_bus_message *message, void *userdata, sd_bus_error *error);
171int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error);
172int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error);