]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind.h
polkit: simplify bus_verify_polkit_async() + drop auth-by-cap dbus feature
[thirdparty/systemd.git] / src / login / logind.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <sys/stat.h>
6
7 #include "sd-bus.h"
8 #include "sd-device.h"
9 #include "sd-event.h"
10
11 #include "conf-parser.h"
12 #include "hashmap.h"
13 #include "list.h"
14 #include "set.h"
15 #include "time-util.h"
16 #include "user-record.h"
17
18 typedef struct Manager Manager;
19
20 #include "logind-action.h"
21 #include "logind-button.h"
22 #include "logind-device.h"
23 #include "logind-inhibit.h"
24
25 struct Manager {
26 sd_event *event;
27 sd_bus *bus;
28
29 Hashmap *devices;
30 Hashmap *seats;
31 Hashmap *sessions;
32 Hashmap *sessions_by_leader;
33 Hashmap *users; /* indexed by UID */
34 Hashmap *inhibitors;
35 Hashmap *buttons;
36 Hashmap *brightness_writers;
37
38 LIST_HEAD(Seat, seat_gc_queue);
39 LIST_HEAD(Session, session_gc_queue);
40 LIST_HEAD(User, user_gc_queue);
41
42 sd_device_monitor *device_seat_monitor, *device_monitor, *device_vcsa_monitor, *device_button_monitor;
43
44 sd_event_source *console_active_event_source;
45
46 #if ENABLE_UTMP
47 sd_event_source *utmp_event_source;
48 #endif
49
50 int console_active_fd;
51
52 unsigned n_autovts;
53
54 unsigned reserve_vt;
55 int reserve_vt_fd;
56
57 Seat *seat0;
58
59 char **kill_only_users, **kill_exclude_users;
60 bool kill_user_processes;
61
62 uint64_t session_counter;
63 uint64_t inhibit_counter;
64
65 Hashmap *session_units;
66 Hashmap *user_units;
67
68 usec_t inhibit_delay_max;
69 usec_t user_stop_delay;
70
71 /* If a shutdown/suspend was delayed due to an inhibitor this contains the action we are supposed to
72 * start after the delay is over */
73 const HandleActionData *delayed_action;
74
75 /* If a shutdown/suspend is currently executed, then this is the job of it */
76 char *action_job;
77 sd_event_source *inhibit_timeout_source;
78
79 HandleAction scheduled_shutdown_action;
80 usec_t scheduled_shutdown_timeout;
81 sd_event_source *scheduled_shutdown_timeout_source;
82 uid_t scheduled_shutdown_uid;
83 char *scheduled_shutdown_tty;
84 sd_event_source *nologin_timeout_source;
85 bool unlink_nologin;
86
87 char *wall_message;
88 bool enable_wall_messages;
89 sd_event_source *wall_message_timeout_source;
90
91 bool shutdown_dry_run;
92
93 sd_event_source *idle_action_event_source;
94 usec_t idle_action_usec;
95 usec_t idle_action_not_before_usec;
96 HandleAction idle_action;
97 bool was_idle;
98
99 usec_t stop_idle_session_usec;
100
101 HandleActionSleepMask handle_action_sleep_mask;
102
103 HandleAction handle_power_key;
104 HandleAction handle_power_key_long_press;
105 HandleAction handle_reboot_key;
106 HandleAction handle_reboot_key_long_press;
107 HandleAction handle_suspend_key;
108 HandleAction handle_suspend_key_long_press;
109 HandleAction handle_hibernate_key;
110 HandleAction handle_hibernate_key_long_press;
111
112 HandleAction handle_lid_switch;
113 HandleAction handle_lid_switch_ep;
114 HandleAction handle_lid_switch_docked;
115
116 bool power_key_ignore_inhibited;
117 bool suspend_key_ignore_inhibited;
118 bool hibernate_key_ignore_inhibited;
119 bool lid_switch_ignore_inhibited;
120 bool reboot_key_ignore_inhibited;
121
122 bool remove_ipc;
123
124 Hashmap *polkit_registry;
125
126 usec_t holdoff_timeout_usec;
127 sd_event_source *lid_switch_ignore_event_source;
128
129 sd_event_source *power_key_long_press_event_source;
130 sd_event_source *reboot_key_long_press_event_source;
131 sd_event_source *suspend_key_long_press_event_source;
132 sd_event_source *hibernate_key_long_press_event_source;
133
134 uint64_t runtime_dir_size;
135 uint64_t runtime_dir_inodes;
136 uint64_t sessions_max;
137 uint64_t inhibitors_max;
138
139 char **efi_boot_loader_entries;
140 bool efi_boot_loader_entries_set;
141
142 char *efi_loader_entry_one_shot;
143 struct stat efi_loader_entry_one_shot_stat;
144 };
145
146 void manager_reset_config(Manager *m);
147 int manager_parse_config_file(Manager *m);
148
149 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device);
150 int manager_add_button(Manager *m, const char *name, Button **ret_button);
151 int manager_add_seat(Manager *m, const char *id, Seat **ret_seat);
152 int manager_add_session(Manager *m, const char *id, Session **ret_session);
153 int manager_add_user(Manager *m, UserRecord *ur, User **ret_user);
154 int manager_add_user_by_name(Manager *m, const char *name, User **ret_user);
155 int manager_add_user_by_uid(Manager *m, uid_t uid, User **ret_user);
156 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret_inhibitor);
157
158 int manager_process_seat_device(Manager *m, sd_device *d);
159 int manager_process_button_device(Manager *m, sd_device *d);
160
161 int manager_spawn_autovt(Manager *m, unsigned vtnr);
162
163 bool manager_shall_kill(Manager *m, const char *user);
164
165 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
166
167 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
168 int manager_get_session_by_pidref(Manager *m, const PidRef *pid, Session **ret);
169
170 bool manager_is_lid_closed(Manager *m);
171 bool manager_is_docked_or_external_displays(Manager *m);
172 bool manager_is_on_external_power(void);
173 bool manager_all_buttons_ignored(Manager *m);
174
175 int manager_read_utmp(Manager *m);
176 void manager_connect_utmp(Manager *m);
177 void manager_reconnect_utmp(Manager *m);
178
179 /* gperf lookup function */
180 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
181
182 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
183
184 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
185 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
186
187 int manager_setup_wall_message_timer(Manager *m);
188 bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata);
189
190 int manager_read_efi_boot_loader_entries(Manager *m);