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/>.
35 typedef struct Manager Manager;
37 #include "logind-device.h"
38 #include "logind-seat.h"
39 #include "logind-session.h"
40 #include "logind-user.h"
41 #include "logind-inhibit.h"
42 #include "logind-button.h"
43 #include "logind-action.h"
45 #define IGNORE_LID_SWITCH_STARTUP_USEC (3 * USEC_PER_MINUTE)
46 #define IGNORE_LID_SWITCH_SUSPEND_USEC (30 * USEC_PER_SEC)
61 LIST_HEAD(Seat, seat_gc_queue);
62 LIST_HEAD(Session, session_gc_queue);
63 LIST_HEAD(User, user_gc_queue);
66 struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
68 sd_event_source *console_active_event_source;
69 sd_event_source *udev_seat_event_source;
70 sd_event_source *udev_device_event_source;
71 sd_event_source *udev_vcsa_event_source;
72 sd_event_source *udev_button_event_source;
74 int console_active_fd;
83 char **kill_only_users, **kill_exclude_users;
84 bool kill_user_processes;
86 unsigned long session_counter;
87 unsigned long inhibit_counter;
89 Hashmap *session_units;
92 usec_t inhibit_delay_max;
94 /* If an action is currently being executed or is delayed,
95 * this is != 0 and encodes what is being done */
96 InhibitWhat action_what;
98 /* If a shutdown/suspend was delayed due to a inhibitor this
99 contains the unit name we are supposed to start after the
101 const char *action_unit;
103 /* If a shutdown/suspend is currently executed, then this is
106 usec_t action_timestamp;
108 sd_event_source *idle_action_event_source;
109 usec_t idle_action_usec;
110 usec_t idle_action_not_before_usec;
111 HandleAction idle_action;
113 HandleAction handle_power_key;
114 HandleAction handle_suspend_key;
115 HandleAction handle_hibernate_key;
116 HandleAction handle_lid_switch;
118 bool power_key_ignore_inhibited;
119 bool suspend_key_ignore_inhibited;
120 bool hibernate_key_ignore_inhibited;
121 bool lid_switch_ignore_inhibited;
125 Hashmap *polkit_registry;
127 sd_event_source *lid_switch_ignore_event_source;
129 size_t runtime_dir_size;
132 Manager *manager_new(void);
133 void manager_free(Manager *m);
135 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
136 int manager_add_button(Manager *m, const char *name, Button **_button);
137 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
138 int manager_add_session(Manager *m, const char *id, Session **_session);
139 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
140 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
141 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
142 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
144 int manager_process_seat_device(Manager *m, struct udev_device *d);
145 int manager_process_button_device(Manager *m, struct udev_device *d);
147 int manager_startup(Manager *m);
148 int manager_run(Manager *m);
149 int manager_spawn_autovt(Manager *m, unsigned int vtnr);
151 void manager_gc(Manager *m, bool drop_not_started);
153 bool manager_shall_kill(Manager *m, const char *user);
155 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
157 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
158 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
160 bool manager_is_docked(Manager *m);
161 int manager_count_displays(Manager *m);
163 extern const sd_bus_vtable manager_vtable[];
165 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
166 int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
167 int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
168 int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
169 int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
171 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
173 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
175 int manager_dispatch_delayed(Manager *manager);
177 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);
178 int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
179 int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
180 int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
181 int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
182 int manager_unit_is_active(Manager *manager, const char *unit);
183 int manager_job_is_active(Manager *manager, const char *path);
185 /* gperf lookup function */
186 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
188 int manager_watch_busname(Manager *manager, const char *name);
189 void manager_drop_busname(Manager *manager, const char *name);
191 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
193 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);