]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind.h
tree-wide: "a" -> "an"
[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 unsigned long session_counter;
63 unsigned long 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 an action is currently being executed or is delayed,
72 * this is != 0 and encodes what is being done */
73 InhibitWhat action_what;
74
75 /* If a shutdown/suspend was delayed due to an inhibitor this
76 contains the unit name we are supposed to start after the
77 delay is over */
78 const char *action_unit;
79
80 /* If a shutdown/suspend is currently executed, then this is
81 * the job of it */
82 char *action_job;
83 sd_event_source *inhibit_timeout_source;
84
85 char *scheduled_shutdown_type;
86 usec_t scheduled_shutdown_timeout;
87 sd_event_source *scheduled_shutdown_timeout_source;
88 uid_t scheduled_shutdown_uid;
89 char *scheduled_shutdown_tty;
90 sd_event_source *nologin_timeout_source;
91 bool unlink_nologin;
92
93 char *wall_message;
94 unsigned enable_wall_messages;
95 sd_event_source *wall_message_timeout_source;
96
97 bool shutdown_dry_run;
98
99 sd_event_source *idle_action_event_source;
100 usec_t idle_action_usec;
101 usec_t idle_action_not_before_usec;
102 HandleAction idle_action;
103
104 HandleAction handle_power_key;
105 HandleAction handle_suspend_key;
106 HandleAction handle_hibernate_key;
107 HandleAction handle_lid_switch;
108 HandleAction handle_lid_switch_ep;
109 HandleAction handle_lid_switch_docked;
110 HandleAction handle_reboot_key;
111
112 bool power_key_ignore_inhibited;
113 bool suspend_key_ignore_inhibited;
114 bool hibernate_key_ignore_inhibited;
115 bool lid_switch_ignore_inhibited;
116 bool reboot_key_ignore_inhibited;
117
118 bool remove_ipc;
119
120 Hashmap *polkit_registry;
121
122 usec_t holdoff_timeout_usec;
123 sd_event_source *lid_switch_ignore_event_source;
124
125 uint64_t runtime_dir_size;
126 uint64_t runtime_dir_inodes;
127 uint64_t sessions_max;
128 uint64_t inhibitors_max;
129
130 char **efi_boot_loader_entries;
131 bool efi_boot_loader_entries_set;
132
133 char *efi_loader_entry_one_shot;
134 struct stat efi_loader_entry_one_shot_stat;
135 };
136
137 void manager_reset_config(Manager *m);
138 int manager_parse_config_file(Manager *m);
139
140 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device);
141 int manager_add_button(Manager *m, const char *name, Button **ret_button);
142 int manager_add_seat(Manager *m, const char *id, Seat **ret_seat);
143 int manager_add_session(Manager *m, const char *id, Session **ret_session);
144 int manager_add_user(Manager *m, UserRecord *ur, User **ret_user);
145 int manager_add_user_by_name(Manager *m, const char *name, User **ret_user);
146 int manager_add_user_by_uid(Manager *m, uid_t uid, User **ret_user);
147 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret_inhibitor);
148
149 int manager_process_seat_device(Manager *m, sd_device *d);
150 int manager_process_button_device(Manager *m, sd_device *d);
151
152 int manager_spawn_autovt(Manager *m, unsigned vtnr);
153
154 bool manager_shall_kill(Manager *m, const char *user);
155
156 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
157
158 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
159 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
160
161 bool manager_is_lid_closed(Manager *m);
162 bool manager_is_docked_or_external_displays(Manager *m);
163 bool manager_is_on_external_power(void);
164 bool manager_all_buttons_ignored(Manager *m);
165
166 int manager_read_utmp(Manager *m);
167 void manager_connect_utmp(Manager *m);
168 void manager_reconnect_utmp(Manager *m);
169
170 /* gperf lookup function */
171 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
172
173 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
174
175 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
176 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
177
178 int manager_setup_wall_message_timer(Manager *m);
179 bool logind_wall_tty_filter(const char *tty, void *userdata);
180
181 int manager_read_efi_boot_loader_entries(Manager *m);