1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2011 Lennart Poettering
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.
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.
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/>.
30 #include "cgroup-util.h"
31 #include "path-lookup.h"
36 typedef struct Manager Manager;
38 #include "logind-device.h"
39 #include "logind-inhibit.h"
40 #include "logind-button.h"
41 #include "logind-action.h"
54 LIST_HEAD(Seat, seat_gc_queue);
55 LIST_HEAD(Session, session_gc_queue);
56 LIST_HEAD(User, user_gc_queue);
59 struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
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;
67 /* Make sure the user cannot accidentally unmount our cgroup
72 ManagerRunningAs running_as;
75 /* Data specific to the cgroup subsystem */
76 CGroupMask cgroup_supported;
79 int console_active_fd;
81 /// elogind does not support autospawning of vts
91 char **kill_only_users, **kill_exclude_users;
92 bool kill_user_processes;
94 unsigned long session_counter;
95 unsigned long inhibit_counter;
97 Hashmap *session_units;
100 usec_t inhibit_delay_max;
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;
106 /* If a shutdown/suspend was delayed due to a inhibitor this
107 contains the unit name we are supposed to start after the
109 const char *action_unit;
111 /* If a shutdown/suspend is currently executed, then this is
114 sd_event_source *inhibit_timeout_source;
116 char *scheduled_shutdown_type;
117 usec_t scheduled_shutdown_timeout;
118 sd_event_source *scheduled_shutdown_timeout_source;
119 uid_t scheduled_shutdown_uid;
120 char *scheduled_shutdown_tty;
121 sd_event_source *nologin_timeout_source;
125 unsigned enable_wall_messages;
126 sd_event_source *wall_message_timeout_source;
128 sd_event_source *idle_action_event_source;
129 usec_t idle_action_usec;
130 usec_t idle_action_not_before_usec;
131 HandleAction idle_action;
133 HandleAction handle_power_key;
134 HandleAction handle_suspend_key;
135 HandleAction handle_hibernate_key;
136 HandleAction handle_lid_switch;
137 HandleAction handle_lid_switch_docked;
139 bool power_key_ignore_inhibited;
140 bool suspend_key_ignore_inhibited;
141 bool hibernate_key_ignore_inhibited;
142 bool lid_switch_ignore_inhibited;
146 Hashmap *polkit_registry;
148 usec_t holdoff_timeout_usec;
149 sd_event_source *lid_switch_ignore_event_source;
151 size_t runtime_dir_size;
154 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
155 int manager_add_button(Manager *m, const char *name, Button **_button);
156 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
157 int manager_add_session(Manager *m, const char *id, Session **_session);
158 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
159 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
160 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
161 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
163 int manager_process_seat_device(Manager *m, struct udev_device *d);
164 int manager_process_button_device(Manager *m, struct udev_device *d);
166 // UNNEEDED int manager_spawn_autovt(Manager *m, unsigned int vtnr);
168 bool manager_shall_kill(Manager *m, const char *user);
170 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
172 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
173 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
175 bool manager_is_docked(Manager *m);
176 int manager_count_displays(Manager *m);
177 bool manager_is_docked_or_multiple_displays(Manager *m);
179 extern const sd_bus_vtable manager_vtable[];
181 int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
182 int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
183 int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
184 int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error);
185 int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
187 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
189 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
191 // 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);
192 // UNNEEDED int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
193 // UNNEEDED int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
194 // UNNEEDED int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
195 // UNNEEDED int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
196 // UNNEEDED int manager_unit_is_active(Manager *manager, const char *unit);
197 // UNNEEDED int manager_job_is_active(Manager *manager, const char *path);
199 /* gperf lookup function */
200 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
202 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
204 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);
206 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
207 int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);
208 int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret);
210 int manager_setup_wall_message_timer(Manager *m);
211 bool logind_wall_tty_filter(const char *tty, void *userdata);