]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind.h
shutdown: Fix last try detection
[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 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 const HandleActionData *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 HandleAction handle_power_key;
100 HandleAction handle_power_key_long_press;
101 HandleAction handle_reboot_key;
102 HandleAction handle_reboot_key_long_press;
103 HandleAction handle_suspend_key;
104 HandleAction handle_suspend_key_long_press;
105 HandleAction handle_hibernate_key;
106 HandleAction handle_hibernate_key_long_press;
107
108 HandleAction handle_lid_switch;
109 HandleAction handle_lid_switch_ep;
110 HandleAction handle_lid_switch_docked;
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 sd_event_source *power_key_long_press_event_source;
126 sd_event_source *reboot_key_long_press_event_source;
127 sd_event_source *suspend_key_long_press_event_source;
128 sd_event_source *hibernate_key_long_press_event_source;
129
130 uint64_t runtime_dir_size;
131 uint64_t runtime_dir_inodes;
132 uint64_t sessions_max;
133 uint64_t inhibitors_max;
134
135 char **efi_boot_loader_entries;
136 bool efi_boot_loader_entries_set;
137
138 char *efi_loader_entry_one_shot;
139 struct stat efi_loader_entry_one_shot_stat;
140 };
141
142 void manager_reset_config(Manager *m);
143 int manager_parse_config_file(Manager *m);
144
145 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device);
146 int manager_add_button(Manager *m, const char *name, Button **ret_button);
147 int manager_add_seat(Manager *m, const char *id, Seat **ret_seat);
148 int manager_add_session(Manager *m, const char *id, Session **ret_session);
149 int manager_add_user(Manager *m, UserRecord *ur, User **ret_user);
150 int manager_add_user_by_name(Manager *m, const char *name, User **ret_user);
151 int manager_add_user_by_uid(Manager *m, uid_t uid, User **ret_user);
152 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret_inhibitor);
153
154 int manager_process_seat_device(Manager *m, sd_device *d);
155 int manager_process_button_device(Manager *m, sd_device *d);
156
157 int manager_spawn_autovt(Manager *m, unsigned vtnr);
158
159 bool manager_shall_kill(Manager *m, const char *user);
160
161 int manager_get_idle_hint(Manager *m, dual_timestamp *t);
162
163 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
164 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
165
166 bool manager_is_lid_closed(Manager *m);
167 bool manager_is_docked_or_external_displays(Manager *m);
168 bool manager_is_on_external_power(void);
169 bool manager_all_buttons_ignored(Manager *m);
170
171 int manager_read_utmp(Manager *m);
172 void manager_connect_utmp(Manager *m);
173 void manager_reconnect_utmp(Manager *m);
174
175 /* gperf lookup function */
176 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
177
178 int manager_set_lid_switch_ignore(Manager *m, usec_t until);
179
180 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
181 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
182
183 int manager_setup_wall_message_timer(Manager *m);
184 bool logind_wall_tty_filter(const char *tty, bool is_local, void *userdata);
185
186 int manager_read_efi_boot_loader_entries(Manager *m);