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