chiark / gitweb /
Prep v230: Apply missing upstream fixes and updates (6/8) src/login.
[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 "cgroup-util.h"
33 #include "hashmap.h"
34 #include "list.h"
35 #include "set.h"
36
37 typedef struct Manager Manager;
38
39 #include "logind-action.h"
40 #include "logind-button.h"
41 #include "logind-device.h"
42 #include "logind-inhibit.h"
43 #include "logind-sleep.h"
44
45 struct Manager {
46         sd_event *event;
47         sd_bus *bus;
48
49         Hashmap *devices;
50         Hashmap *seats;
51         Hashmap *sessions;
52         Hashmap *users;
53         Hashmap *inhibitors;
54         Hashmap *buttons;
55
56         LIST_HEAD(Seat, seat_gc_queue);
57         LIST_HEAD(Session, session_gc_queue);
58         LIST_HEAD(User, user_gc_queue);
59
60         struct udev *udev;
61         struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
62
63         sd_event_source *console_active_event_source;
64         sd_event_source *udev_seat_event_source;
65         sd_event_source *udev_device_event_source;
66         sd_event_source *udev_vcsa_event_source;
67         sd_event_source *udev_button_event_source;
68
69 #if 0 /// elogind does not support autospawning of vts
70         int console_active_fd;
71
72         unsigned n_autovts;
73
74         unsigned reserve_vt;
75         int reserve_vt_fd;
76 #else
77         /* Make sure the user cannot accidentally unmount our cgroup
78          * file system */
79         int pin_cgroupfs_fd;
80
81         /* Flags */
82         bool test_run:1;
83
84         /* Data specific to the cgroup subsystem */
85         CGroupMask cgroup_supported;
86         char *cgroup_root;
87
88         int console_active_fd;
89 #endif // 0
90
91         Seat *seat0;
92
93         char **kill_only_users, **kill_exclude_users;
94         bool kill_user_processes;
95
96         unsigned long session_counter;
97         unsigned long inhibit_counter;
98
99         Hashmap *session_units;
100         Hashmap *user_units;
101
102         usec_t inhibit_delay_max;
103
104         /* If an action is currently being executed or is delayed,
105          * this is != 0 and encodes what is being done */
106         InhibitWhat action_what;
107
108 #if 0 /// elogind does all relevant actions on its own. No systemd jobs and units.
109         /* If a shutdown/suspend was delayed due to a inhibitor this
110            contains the unit name we are supposed to start after the
111            delay is over */
112         const char *action_unit;
113
114         /* If a shutdown/suspend is currently executed, then this is
115          * the job of it */
116         char *action_job;
117 #else
118         /* If a shutdown/suspend was delayed due to a inhibitor this
119            contains the action we are supposed to perform after the
120            delay is over */
121         HandleAction pending_action;
122
123         char **suspend_state,      **suspend_mode;
124         char **hibernate_state,    **hibernate_mode;
125         char **hybrid_sleep_state, **hybrid_sleep_mode;
126
127 #endif // 0
128         sd_event_source *inhibit_timeout_source;
129
130         char *scheduled_shutdown_type;
131         usec_t scheduled_shutdown_timeout;
132         sd_event_source *scheduled_shutdown_timeout_source;
133         uid_t scheduled_shutdown_uid;
134         char *scheduled_shutdown_tty;
135         sd_event_source *nologin_timeout_source;
136         bool unlink_nologin;
137
138         char *wall_message;
139         unsigned enable_wall_messages;
140         sd_event_source *wall_message_timeout_source;
141
142         bool shutdown_dry_run;
143
144         sd_event_source *idle_action_event_source;
145         usec_t idle_action_usec;
146         usec_t idle_action_not_before_usec;
147         HandleAction idle_action;
148
149         HandleAction handle_power_key;
150         HandleAction handle_suspend_key;
151         HandleAction handle_hibernate_key;
152         HandleAction handle_lid_switch;
153         HandleAction handle_lid_switch_docked;
154
155         bool power_key_ignore_inhibited;
156         bool suspend_key_ignore_inhibited;
157         bool hibernate_key_ignore_inhibited;
158         bool lid_switch_ignore_inhibited;
159
160         bool remove_ipc;
161
162         Hashmap *polkit_registry;
163
164         usec_t holdoff_timeout_usec;
165         sd_event_source *lid_switch_ignore_event_source;
166
167         size_t runtime_dir_size;
168         uint64_t user_tasks_max;
169         uint64_t sessions_max;
170         uint64_t inhibitors_max;
171 };
172
173 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
174 int manager_add_button(Manager *m, const char *name, Button **_button);
175 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
176 int manager_add_session(Manager *m, const char *id, Session **_session);
177 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
178 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
179 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
180 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
181
182 int manager_process_seat_device(Manager *m, struct udev_device *d);
183 int manager_process_button_device(Manager *m, struct udev_device *d);
184
185 #if 0 /// UNNEEDED by elogind
186 int manager_spawn_autovt(Manager *m, unsigned int vtnr);
187 #endif // 0
188
189 bool manager_shall_kill(Manager *m, const char *user);
190
191 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
192
193 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
194 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
195
196 bool manager_is_docked_or_external_displays(Manager *m);
197
198 extern const sd_bus_vtable manager_vtable[];
199
200 #if 0 /// UNNEEDED by elogind
201 int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
202 int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
203 int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
204 int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error);
205 int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
206
207 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
208 #else
209 /// eloginds own version does the action itself
210 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, InhibitWhat w, sd_bus_error *error);
211 #endif // 0
212
213 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
214
215 #if 0 /// UNNEEDED by elogind
216 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);
217 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);
218 int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
219 int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
220 int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
221 int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
222 int manager_unit_is_active(Manager *manager, const char *unit);
223 int manager_job_is_active(Manager *manager, const char *path);
224 #endif // 0
225
226 /* gperf lookup function */
227 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
228
229 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
230
231 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);
232
233 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
234 int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);
235 int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret);
236
237 #if 0 /// UNNEEDED by elogind
238 int manager_setup_wall_message_timer(Manager *m);
239 bool logind_wall_tty_filter(const char *tty, void *userdata);
240 #endif // 0
241
242 int manager_dispatch_delayed(Manager *manager, bool timeout);