]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/login/logind-session.h
Merge pull request #12753 from jrouleau/fix/hibernate-resume-timeout
[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"
3b92c086 10#include "string-util.h"
90821c93 11
0604381b 12typedef enum SessionState {
fb6becb4 13 SESSION_OPENING, /* Session scope is being created */
0604381b
LP
14 SESSION_ONLINE, /* Logged in */
15 SESSION_ACTIVE, /* Logged in and in the fg */
fb6becb4 16 SESSION_CLOSING, /* Logged out, but scope is still there */
0604381b
LP
17 _SESSION_STATE_MAX,
18 _SESSION_STATE_INVALID = -1
19} SessionState;
20
55efac6c
LP
21typedef enum SessionClass {
22 SESSION_USER,
23 SESSION_GREETER,
24 SESSION_LOCK_SCREEN,
e2acb67b 25 SESSION_BACKGROUND,
55efac6c
LP
26 _SESSION_CLASS_MAX,
27 _SESSION_CLASS_INVALID = -1
28} SessionClass;
29
e2acb67b
LP
30typedef enum SessionType {
31 SESSION_UNSPECIFIED,
32 SESSION_TTY,
33 SESSION_X11,
d9eb81f9 34 SESSION_WAYLAND,
9541666b 35 SESSION_MIR,
e9e74f28 36 SESSION_WEB,
e2acb67b
LP
37 _SESSION_TYPE_MAX,
38 _SESSION_TYPE_INVALID = -1
39} SessionType;
40
952d3260
LP
41#define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
42
9444b1f2 43enum KillWho {
de07ab16
LP
44 KILL_LEADER,
45 KILL_ALL,
46 _KILL_WHO_MAX,
47 _KILL_WHO_INVALID = -1
9444b1f2 48};
de07ab16 49
3d0ef5c7
LP
50typedef enum TTYValidity {
51 TTY_FROM_PAM,
52 TTY_FROM_UTMP,
53 TTY_UTMP_INCONSISTENT, /* may happen on ssh sessions with multiplexed TTYs */
54 _TTY_VALIDITY_MAX,
55 _TTY_VALIDITY_INVALID = -1,
56} TTYValidity;
57
90821c93
LP
58struct Session {
59 Manager *manager;
60
f7a5bb28 61 const char *id;
14cb109d 62 unsigned position;
90821c93 63 SessionType type;
55efac6c 64 SessionClass class;
90821c93
LP
65
66 char *state_file;
67
68 User *user;
69
70 dual_timestamp timestamp;
71
90821c93 72 char *display;
3d0ef5c7
LP
73 char *tty;
74 TTYValidity tty_validity;
90821c93
LP
75
76 bool remote;
3f49d45a 77 char *remote_user;
90821c93 78 char *remote_host;
98a28fef 79 char *service;
a4cd87e9 80 char *desktop;
fb6becb4
LP
81
82 char *scope;
83 char *scope_job;
98a28fef 84
90821c93 85 Seat *seat;
14cb109d 86 unsigned vtnr;
90a18413 87 int vtfd;
90821c93
LP
88
89 pid_t leader;
3f49d45a 90 uint32_t audit_id;
90821c93 91
932e3ee7
LP
92 int fifo_fd;
93 char *fifo_path;
90821c93 94
cc377381
LP
95 sd_event_source *fifo_event_source;
96
a185c5aa
LP
97 bool idle_hint;
98 dual_timestamp idle_hint_timestamp;
99
42d35e13
VT
100 bool locked_hint;
101
14c3baca 102 bool in_gc_queue:1;
9418f147 103 bool started:1;
5f41d1f1 104 bool stopping:1;
90821c93 105
aed24c4c
FB
106 bool was_active:1;
107
cc377381 108 sd_bus_message *create_message;
fb6becb4 109
061c6607 110 /* Set up when a client requested to release the session via the bus */
5f41d1f1
LP
111 sd_event_source *timer_event_source;
112
ae5e06bd 113 char *controller;
118ecf32 114 Hashmap *devices;
3cde9e8f 115 sd_bus_track *track;
ae5e06bd 116
90821c93
LP
117 LIST_FIELDS(Session, sessions_by_user);
118 LIST_FIELDS(Session, sessions_by_seat);
14c3baca
LP
119
120 LIST_FIELDS(Session, gc_queue);
90821c93
LP
121};
122
8c29a457
LP
123int session_new(Session **ret, Manager *m, const char *id);
124Session* session_free(Session *s);
125
126DEFINE_TRIVIAL_CLEANUP_FUNC(Session *, session_free);
127
9444b1f2 128void session_set_user(Session *s, User *u);
238794b1 129int session_set_leader(Session *s, pid_t pid);
5c093a23 130bool session_may_gc(Session *s, bool drop_not_started);
14c3baca 131void session_add_to_gc_queue(Session *s);
90821c93
LP
132int session_activate(Session *s);
133bool session_is_active(Session *s);
a185c5aa 134int session_get_idle_hint(Session *s, dual_timestamp *t);
bef422ae 135void session_set_idle_hint(Session *s, bool b);
42d35e13
VT
136int session_get_locked_hint(Session *s);
137void session_set_locked_hint(Session *s, bool b);
932e3ee7 138int session_create_fifo(Session *s);
25a1ab4e 139int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error);
9bb69af4 140int session_stop(Session *s, bool force);
405e0255 141int session_finalize(Session *s);
ad8780c9 142int session_release(Session *s);
90821c93
LP
143int session_save(Session *s);
144int session_load(Session *s);
de07ab16 145int session_kill(Session *s, KillWho who, int signo);
90821c93 146
0604381b
LP
147SessionState session_get_state(Session *u);
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
3d0ef5c7
LP
161const char* tty_validity_to_string(TTYValidity t) _const_;
162TTYValidity tty_validity_from_string(const char *s) _pure_;
163
baccf3e4 164int session_prepare_vt(Session *s);
2ec3ff66 165void session_leave_vt(Session *s);
90a18413 166
ae5e06bd 167bool session_is_controller(Session *s, const char *sender);
dc6284e9 168int session_set_controller(Session *s, const char *sender, bool force, bool prepare);
ae5e06bd 169void session_drop_controller(Session *s);
c529695e 170
3b92c086
LP
171static inline bool SESSION_IS_SELF(const char *name) {
172 return isempty(name) || streq(name, "self");
173}
174
175static inline bool SESSION_IS_AUTO(const char *name) {
176 return streq_ptr(name, "auto");
177}