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