chiark / gitweb /
ca9b5ce8650ebfa72494260d443326f1754714a4
[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 "sd-event.h"
28 #include "sd-bus.h"
29 #include "list.h"
30 #include "hashmap.h"
31 #include "set.h"
32
33 typedef struct Manager Manager;
34
35 #include "logind-device.h"
36 #include "logind-inhibit.h"
37 #include "logind-button.h"
38 #include "logind-action.h"
39
40 struct Manager {
41         sd_event *event;
42         sd_bus *bus;
43
44         Hashmap *devices;
45         Hashmap *seats;
46         Hashmap *sessions;
47         Hashmap *users;
48         Hashmap *inhibitors;
49         Hashmap *buttons;
50
51         Set *busnames;
52
53         LIST_HEAD(Seat, seat_gc_queue);
54         LIST_HEAD(Session, session_gc_queue);
55         LIST_HEAD(User, user_gc_queue);
56
57         struct udev *udev;
58         struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
59
60         sd_event_source *console_active_event_source;
61         sd_event_source *udev_seat_event_source;
62         sd_event_source *udev_device_event_source;
63         sd_event_source *udev_vcsa_event_source;
64         sd_event_source *udev_button_event_source;
65
66         /* Make sure the user cannot accidentally unmount our cgroup
67          * file system */
68         int pin_cgroupfs_fd;
69
70         /* Data specific to the cgroup subsystem */
71         char *cgroup_root;
72
73         int console_active_fd;
74
75         Seat *seat0;
76
77         char **kill_only_users, **kill_exclude_users;
78         bool kill_user_processes;
79
80         unsigned long session_counter;
81         unsigned long inhibit_counter;
82
83         usec_t inhibit_delay_max;
84
85         /* If an action is currently being executed or is delayed,
86          * this is != 0 and encodes what is being done */
87         InhibitWhat action_what;
88
89         /* If a shutdown/suspend was delayed due to a inhibitor this
90            contains the action we are supposed to perform after the
91            delay is over */
92         HandleAction pending_action;
93         sd_event_source *inhibit_timeout_source;
94
95         char *scheduled_shutdown_type;
96         usec_t scheduled_shutdown_timeout;
97         sd_event_source *scheduled_shutdown_timeout_source;
98         uid_t scheduled_shutdown_uid;
99         char *scheduled_shutdown_tty;
100         sd_event_source *nologin_timeout_source;
101         bool unlink_nologin;
102
103         char *wall_message;
104         unsigned enable_wall_messages;
105         sd_event_source *wall_message_timeout_source;
106
107         sd_event_source *idle_action_event_source;
108         usec_t idle_action_usec;
109         usec_t idle_action_not_before_usec;
110         HandleAction idle_action;
111
112         HandleAction handle_power_key;
113         HandleAction handle_suspend_key;
114         HandleAction handle_hibernate_key;
115         HandleAction handle_lid_switch;
116         HandleAction handle_lid_switch_docked;
117
118         bool power_key_ignore_inhibited;
119         bool suspend_key_ignore_inhibited;
120         bool hibernate_key_ignore_inhibited;
121         bool lid_switch_ignore_inhibited;
122
123         bool remove_ipc;
124
125         char **suspend_state, **suspend_mode;
126         char **hibernate_state, **hibernate_mode;
127         char **hybrid_sleep_state, **hybrid_sleep_mode;
128
129         Hashmap *polkit_registry;
130
131         usec_t holdoff_timeout_usec;
132         sd_event_source *lid_switch_ignore_event_source;
133
134         size_t runtime_dir_size;
135 };
136
137 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
138 int manager_add_button(Manager *m, const char *name, Button **_button);
139 int manager_add_seat(Manager *m, const char *id, Seat **_seat);
140 int manager_add_session(Manager *m, const char *id, Session **_session);
141 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
142 int manager_add_user_by_name(Manager *m, const char *name, User **_user);
143 int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
144 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
145
146 int manager_process_seat_device(Manager *m, struct udev_device *d);
147 int manager_process_button_device(Manager *m, struct udev_device *d);
148
149
150 bool manager_shall_kill(Manager *m, const char *user);
151
152 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
153
154 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
155 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
156
157 bool manager_is_docked(Manager *m);
158 int manager_count_displays(Manager *m);
159 bool manager_is_docked_or_multiple_displays(Manager *m);
160
161 extern const sd_bus_vtable manager_vtable[];
162
163 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, InhibitWhat w, sd_bus_error *error);
164 int shutdown_or_sleep(Manager *m, HandleAction action);
165
166 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
167
168
169 /* gperf lookup function */
170 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
171
172 int manager_watch_busname(Manager *manager, const char *name);
173 void manager_drop_busname(Manager *manager, const char *name);
174
175 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
176
177 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);
178
179 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
180 int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);
181 int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret);
182
183 int manager_setup_wall_message_timer(Manager *m);
184 bool logind_wall_tty_filter(const char *tty, void *userdata);