chiark / gitweb /
Prep v229.6: Send wakeup call to suspended processes.
[elogind.git] / src / login / logind.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2011 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdbool.h>
23
24 #if 0 /// elogind needs the systems udev header
25 #include "libudev.h"
26 #else
27 #include <libudev.h>
28 #endif // 0
29 #include "sd-bus.h"
30 #include "sd-event.h"
31
32 #include "hashmap.h"
33 #include "list.h"
34 #include "set.h"
35
36 typedef struct Manager Manager;
37
38 #include "logind-action.h"
39 #include "logind-button.h"
40 #include "logind-device.h"
41 #include "logind-inhibit.h"
42
43 /// Additional includes needed by elogind
44 #include "cgroup-util.h"
45
46 #if 1 /// elogind has to ident itself
47 #define MANAGER_IS_SYSTEM(m) ((m)->is_system)
48 #define MANAGER_IS_USER(m) (!((m)->is_system))
49 #endif // 1
50
51 struct Manager {
52         sd_event *event;
53         sd_bus *bus;
54
55         Hashmap *devices;
56         Hashmap *seats;
57         Hashmap *sessions;
58         Hashmap *users;
59         Hashmap *inhibitors;
60         Hashmap *buttons;
61
62         LIST_HEAD(Seat, seat_gc_queue);
63         LIST_HEAD(Session, session_gc_queue);
64         LIST_HEAD(User, user_gc_queue);
65
66         struct udev *udev;
67         struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
68
69         sd_event_source *console_active_event_source;
70         sd_event_source *udev_seat_event_source;
71         sd_event_source *udev_device_event_source;
72         sd_event_source *udev_vcsa_event_source;
73         sd_event_source *udev_button_event_source;
74
75 #if 0 /// elogind does not support autospawning of vts
76         int console_active_fd;
77
78         unsigned n_autovts;
79
80         unsigned reserve_vt;
81         int reserve_vt_fd;
82 #else
83         /* Make sure the user cannot accidentally unmount our cgroup
84          * file system */
85         int pin_cgroupfs_fd;
86
87         /* fd for handling cgroup socket if elogind is its own cgroups manager */
88         int cgroups_agent_fd;
89         sd_event_source *cgroups_agent_event_source;
90
91         /* Flags */
92         bool test_run:1;
93         bool is_system:1; /* true if elogind is its own cgroups manager */
94
95         /* Data specific to the cgroup subsystem */
96         CGroupMask cgroup_supported;
97         char *cgroup_root;
98
99         int console_active_fd;
100 #endif // 0
101
102         Seat *seat0;
103
104         char **kill_only_users, **kill_exclude_users;
105         bool kill_user_processes;
106
107         unsigned long session_counter;
108         unsigned long inhibit_counter;
109
110         Hashmap *session_units;
111         Hashmap *user_units;
112
113         usec_t inhibit_delay_max;
114
115         /* If an action is currently being executed or is delayed,
116          * this is != 0 and encodes what is being done */
117         InhibitWhat action_what;
118
119 #if 0 /// elogind does all relevant actions on its own. No systemd jobs and units.
120         /* If a shutdown/suspend was delayed due to a inhibitor this
121            contains the unit name we are supposed to start after the
122            delay is over */
123         const char *action_unit;
124
125         /* If a shutdown/suspend is currently executed, then this is
126          * the job of it */
127         char *action_job;
128 #else
129         /* If a shutdown/suspend was delayed due to a inhibitor this
130            contains the action we are supposed to perform after the
131            delay is over */
132         HandleAction pending_action;
133
134         char **suspend_state,      **suspend_mode;
135         char **hibernate_state,    **hibernate_mode;
136         char **hybrid_sleep_state, **hybrid_sleep_mode;
137
138 #endif // 0
139         sd_event_source *inhibit_timeout_source;
140
141         char *scheduled_shutdown_type;
142         usec_t scheduled_shutdown_timeout;
143         sd_event_source *scheduled_shutdown_timeout_source;
144         uid_t scheduled_shutdown_uid;
145         char *scheduled_shutdown_tty;
146         sd_event_source *nologin_timeout_source;
147         bool unlink_nologin;
148
149         char *wall_message;
150         unsigned enable_wall_messages;
151         sd_event_source *wall_message_timeout_source;
152
153         bool shutdown_dry_run;
154
155         sd_event_source *idle_action_event_source;
156         usec_t idle_action_usec;
157         usec_t idle_action_not_before_usec;
158         HandleAction idle_action;
159
160         HandleAction handle_power_key;
161         HandleAction handle_suspend_key;
162         HandleAction handle_hibernate_key;
163         HandleAction handle_lid_switch;
164         HandleAction handle_lid_switch_docked;
165
166         bool power_key_ignore_inhibited;
167         bool suspend_key_ignore_inhibited;
168         bool hibernate_key_ignore_inhibited;
169         bool lid_switch_ignore_inhibited;
170
171         bool remove_ipc;
172
173         Hashmap *polkit_registry;
174
175         usec_t holdoff_timeout_usec;
176         sd_event_source *lid_switch_ignore_event_source;
177
178         size_t runtime_dir_size;
179         uint64_t user_tasks_max;
180         uint64_t sessions_max;
181         uint64_t inhibitors_max;
182 };
183
184 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
185 int manager_add_button(Manager *m, const char *name, Button **_button);
186 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
187 int manager_add_session(Manager *m, const char *id, Session **_session);
188 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
189 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
190 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
191 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
192
193 int manager_process_seat_device(Manager *m, struct udev_device *d);
194 int manager_process_button_device(Manager *m, struct udev_device *d);
195
196 #if 0 /// UNNEEDED by elogind
197 int manager_spawn_autovt(Manager *m, unsigned int vtnr);
198 #endif // 0
199
200 bool manager_shall_kill(Manager *m, const char *user);
201
202 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
203
204 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
205 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
206
207 bool manager_is_docked_or_external_displays(Manager *m);
208
209 extern const sd_bus_vtable manager_vtable[];
210
211 #if 0 /// UNNEEDED by elogind
212 int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
213 int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
214 int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
215 int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error);
216 int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
217
218 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
219 #else
220 /// eloginds own version does the action itself
221 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, InhibitWhat w, sd_bus_error *error);
222 #endif // 0
223
224 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
225
226 #if 0 /// UNNEEDED by elogind
227 int manager_start_slice(Manager *manager, const char *slice, const char *description, const char *after, const char *after2, uint64_t tasks_max, sd_bus_error *error, char **job);
228 int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, uint64_t tasks_max, sd_bus_error *error, char **job);
229 int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
230 int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
231 int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
232 int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
233 int manager_unit_is_active(Manager *manager, const char *unit);
234 int manager_job_is_active(Manager *manager, const char *path);
235 #endif // 0
236
237 /* gperf lookup function */
238 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
239
240 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
241
242 int config_parse_tmpfs_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
243 int config_parse_user_tasks_max(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
244
245 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
246 int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);
247 int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret);
248
249 int manager_setup_wall_message_timer(Manager *m);
250 bool logind_wall_tty_filter(const char *tty, void *userdata);
251
252 int manager_dispatch_delayed(Manager *manager, bool timeout);