chiark / gitweb /
logind: order all scopes after both systemd-logind.service and
[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 <inttypes.h>
26 #include <libudev.h>
27
28 #include "sd-event.h"
29 #include "sd-bus.h"
30 #include "util.h"
31 #include "list.h"
32 #include "hashmap.h"
33 #include "set.h"
34
35 typedef struct Manager Manager;
36
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"
44
45 struct Manager {
46         sd_event *event;
47         sd_bus *bus;
48
49         Hashmap *devices;
50         Hashmap *seats;
51         Hashmap *sessions;
52         Hashmap *users;
53         Hashmap *inhibitors;
54         Hashmap *buttons;
55
56         Set *busnames;
57
58         LIST_HEAD(Seat, seat_gc_queue);
59         LIST_HEAD(Session, session_gc_queue);
60         LIST_HEAD(User, user_gc_queue);
61
62         struct udev *udev;
63         struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
64
65         sd_event_source *console_active_event_source;
66         sd_event_source *udev_seat_event_source;
67         sd_event_source *udev_device_event_source;
68         sd_event_source *udev_vcsa_event_source;
69         sd_event_source *udev_button_event_source;
70
71         int console_active_fd;
72
73         unsigned n_autovts;
74
75         unsigned reserve_vt;
76         int reserve_vt_fd;
77
78         Seat *seat0;
79
80         char **kill_only_users, **kill_exclude_users;
81         bool kill_user_processes;
82
83         unsigned long session_counter;
84         unsigned long inhibit_counter;
85
86         Hashmap *session_units;
87         Hashmap *user_units;
88
89         usec_t inhibit_delay_max;
90
91         /* If an action is currently being executed or is delayed,
92          * this is != 0 and encodes what is being done */
93         InhibitWhat action_what;
94
95         /* If a shutdown/suspend was delayed due to a inhibitor this
96            contains the unit name we are supposed to start after the
97            delay is over */
98         const char *action_unit;
99
100         /* If a shutdown/suspend is currently executed, then this is
101          * the job of it */
102         char *action_job;
103         usec_t action_timestamp;
104
105         sd_event_source *idle_action_event_source;
106         usec_t idle_action_usec;
107         usec_t idle_action_not_before_usec;
108         HandleAction idle_action;
109
110         HandleAction handle_power_key;
111         HandleAction handle_suspend_key;
112         HandleAction handle_hibernate_key;
113         HandleAction handle_lid_switch;
114
115         bool power_key_ignore_inhibited;
116         bool suspend_key_ignore_inhibited;
117         bool hibernate_key_ignore_inhibited;
118         bool lid_switch_ignore_inhibited;
119
120         Hashmap *polkit_registry;
121 };
122
123 Manager *manager_new(void);
124 void manager_free(Manager *m);
125
126 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
127 int manager_add_button(Manager *m, const char *name, Button **_button);
128 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
129 int manager_add_session(Manager *m, const char *id, Session **_session);
130 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
131 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
132 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
133 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
134
135 int manager_process_seat_device(Manager *m, struct udev_device *d);
136 int manager_process_button_device(Manager *m, struct udev_device *d);
137
138 int manager_startup(Manager *m);
139 int manager_run(Manager *m);
140 int manager_spawn_autovt(Manager *m, unsigned int vtnr);
141
142 void manager_gc(Manager *m, bool drop_not_started);
143
144 bool manager_shall_kill(Manager *m, const char *user);
145
146 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
147
148 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
149 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
150
151 extern const sd_bus_vtable manager_vtable[];
152
153 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
154 int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
155 int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
156 int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
157 int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
158
159 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
160
161 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
162
163 int manager_dispatch_delayed(Manager *manager);
164
165 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);
166 int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
167 int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
168 int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
169 int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
170 int manager_unit_is_active(Manager *manager, const char *unit);
171 int manager_job_is_active(Manager *manager, const char *path);
172
173 /* gperf lookup function */
174 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
175
176 int manager_watch_busname(Manager *manager, const char *name);
177 void manager_drop_busname(Manager *manager, const char *name);