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