chiark / gitweb /
3ec9d84f96e07f213465f3b7f27c9b8ce845b899
[elogind.git] / src / login / logind-session.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2011 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct Session Session;
25 typedef enum KillWho KillWho;
26
27 #include "list.h"
28 #include "util.h"
29 #include "logind.h"
30 #include "logind-seat.h"
31 #include "logind-session-device.h"
32 #include "logind-user.h"
33 #include "login-shared.h"
34
35 typedef enum SessionState {
36         SESSION_OPENING,  /* Session scope is being created */
37         SESSION_ONLINE,   /* Logged in */
38         SESSION_ACTIVE,   /* Logged in and in the fg */
39         SESSION_CLOSING,  /* Logged out, but scope is still there */
40         _SESSION_STATE_MAX,
41         _SESSION_STATE_INVALID = -1
42 } SessionState;
43
44 typedef enum SessionClass {
45         SESSION_USER,
46         SESSION_GREETER,
47         SESSION_LOCK_SCREEN,
48         SESSION_BACKGROUND,
49         _SESSION_CLASS_MAX,
50         _SESSION_CLASS_INVALID = -1
51 } SessionClass;
52
53 typedef enum SessionType {
54         SESSION_UNSPECIFIED,
55         SESSION_TTY,
56         SESSION_X11,
57         SESSION_WAYLAND,
58         SESSION_MIR,
59         SESSION_WEB,
60         _SESSION_TYPE_MAX,
61         _SESSION_TYPE_INVALID = -1
62 } SessionType;
63
64 #define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
65
66 enum KillWho {
67         KILL_LEADER,
68         KILL_ALL,
69         _KILL_WHO_MAX,
70         _KILL_WHO_INVALID = -1
71 };
72
73 struct Session {
74         Manager *manager;
75
76         const char *id;
77         unsigned int pos;
78         SessionType type;
79         SessionClass class;
80
81         char *state_file;
82
83         User *user;
84
85         dual_timestamp timestamp;
86
87         char *tty;
88         char *display;
89
90         bool remote;
91         char *remote_user;
92         char *remote_host;
93         char *service;
94         char *desktop;
95
96         char *scope;
97         char *scope_job;
98
99         Seat *seat;
100         unsigned int vtnr;
101         int vtfd;
102
103         pid_t leader;
104         uint32_t audit_id;
105
106         int fifo_fd;
107         char *fifo_path;
108
109         sd_event_source *fifo_event_source;
110
111         bool idle_hint;
112         dual_timestamp idle_hint_timestamp;
113
114         bool in_gc_queue:1;
115         bool started:1;
116         bool stopping:1;
117
118         sd_bus_message *create_message;
119
120         sd_event_source *timer_event_source;
121
122         char *controller;
123         Hashmap *devices;
124
125         LIST_FIELDS(Session, sessions_by_user);
126         LIST_FIELDS(Session, sessions_by_seat);
127
128         LIST_FIELDS(Session, gc_queue);
129 };
130
131 Session *session_new(Manager *m, const char *id);
132 void session_free(Session *s);
133 void session_set_user(Session *s, User *u);
134 bool session_check_gc(Session *s, bool drop_not_started);
135 void session_add_to_gc_queue(Session *s);
136 int session_activate(Session *s);
137 bool session_is_active(Session *s);
138 int session_get_idle_hint(Session *s, dual_timestamp *t);
139 void session_set_idle_hint(Session *s, bool b);
140 int session_create_fifo(Session *s);
141 int session_start(Session *s);
142 int session_stop(Session *s, bool force);
143 int session_finalize(Session *s);
144 void session_release(Session *s);
145 int session_save(Session *s);
146 int session_load(Session *s);
147 int session_kill(Session *s, KillWho who, int signo);
148
149 SessionState session_get_state(Session *u);
150
151 extern const sd_bus_vtable session_vtable[];
152 int session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
153 int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
154 char *session_bus_path(Session *s);
155
156 int session_send_signal(Session *s, bool new_session);
157 int session_send_changed(Session *s, const char *properties, ...) _sentinel_;
158 int session_send_lock(Session *s, bool lock);
159 int session_send_lock_all(Manager *m, bool lock);
160
161 int session_send_create_reply(Session *s, sd_bus_error *error);
162
163 const char* session_state_to_string(SessionState t) _const_;
164 SessionState session_state_from_string(const char *s) _pure_;
165
166 const char* session_type_to_string(SessionType t) _const_;
167 SessionType session_type_from_string(const char *s) _pure_;
168
169 const char* session_class_to_string(SessionClass t) _const_;
170 SessionClass session_class_from_string(const char *s) _pure_;
171
172 const char *kill_who_to_string(KillWho k) _const_;
173 KillWho kill_who_from_string(const char *s) _pure_;
174
175 int session_prepare_vt(Session *s);
176 void session_restore_vt(Session *s);
177 void session_leave_vt(Session *s);
178
179 bool session_is_controller(Session *s, const char *sender);
180 int session_set_controller(Session *s, const char *sender, bool force);
181 void session_drop_controller(Session *s);
182
183 int bus_session_method_activate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
184 int bus_session_method_lock(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
185 int bus_session_method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
186 int bus_session_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);