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/>.
26 #include <dbus/dbus.h>
33 #include "cgroup-util.h"
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"
55 LIST_HEAD(Seat, seat_gc_queue);
56 LIST_HEAD(Session, session_gc_queue);
57 LIST_HEAD(User, user_gc_queue);
60 struct udev_monitor *udev_seat_monitor, *udev_vcsa_monitor, *udev_button_monitor;
66 int console_active_fd;
78 char **controllers, **reset_controllers;
80 char **kill_only_users, **kill_exclude_users;
82 bool kill_user_processes;
84 unsigned long session_counter;
85 unsigned long inhibit_counter;
87 Hashmap *session_cgroups;
88 Hashmap *user_cgroups;
91 Hashmap *inhibitor_fds;
94 usec_t inhibit_delay_max;
96 /* If an action is currently being executed or is delayed,
97 * this is != 0 and encodes what is being done */
98 InhibitWhat action_what;
100 /* If a shutdown/suspend was delayed due to a inhibitor this
101 contains the unit name we are supposed to start after the
103 const char *action_unit;
105 /* If a shutdown/suspend is currently executed, then this is
108 usec_t action_timestamp;
110 int idle_action_fd; /* the timer_fd */
111 usec_t idle_action_usec;
112 usec_t idle_action_not_before_usec;
113 HandleAction idle_action;
115 HandleAction handle_power_key;
116 HandleAction handle_suspend_key;
117 HandleAction handle_hibernate_key;
118 HandleAction handle_lid_switch;
120 bool power_key_ignore_inhibited;
121 bool suspend_key_ignore_inhibited;
122 bool hibernate_key_ignore_inhibited;
123 bool lid_switch_ignore_inhibited;
136 Manager *manager_new(void);
137 void manager_free(Manager *m);
139 int manager_add_device(Manager *m, const char *sysfs, Device **_device);
140 int manager_add_button(Manager *m, const char *name, Button **_button);
141 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
142 int manager_add_session(Manager *m, User *u, const char *id, Session **_session);
143 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
144 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
145 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
146 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
148 int manager_process_seat_device(Manager *m, struct udev_device *d);
149 int manager_process_button_device(Manager *m, struct udev_device *d);
151 int manager_dispatch_seat_udev(Manager *m);
152 int manager_dispatch_vcsa_udev(Manager *m);
153 int manager_dispatch_button_udev(Manager *m);
154 int manager_dispatch_console(Manager *m);
155 int manager_dispatch_idle_action(Manager *m);
157 int manager_enumerate_devices(Manager *m);
158 int manager_enumerate_buttons(Manager *m);
159 int manager_enumerate_seats(Manager *m);
160 int manager_enumerate_sessions(Manager *m);
161 int manager_enumerate_users(Manager *m);
162 int manager_enumerate_inhibitors(Manager *m);
164 int manager_startup(Manager *m);
165 int manager_run(Manager *m);
166 int manager_spawn_autovt(Manager *m, int vtnr);
168 void manager_cgroup_notify_empty(Manager *m, const char *cgroup);
170 void manager_gc(Manager *m, bool drop_not_started);
172 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
174 int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user);
175 int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **session);
176 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
178 extern const DBusObjectPathVTable bus_manager_vtable;
180 DBusHandlerResult bus_message_filter(DBusConnection *c, DBusMessage *message, void *userdata);
182 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, DBusError *error);
184 int manager_send_changed(Manager *manager, const char *properties);
186 int manager_dispatch_delayed(Manager *manager);
188 /* gperf lookup function */
189 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);