1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
11 #include "conf-parser.h"
15 #include "time-util.h"
16 #include "user-record.h"
18 typedef struct Manager Manager
;
20 #include "logind-action.h"
21 #include "logind-button.h"
22 #include "logind-device.h"
23 #include "logind-inhibit.h"
32 Hashmap
*sessions_by_leader
;
33 Hashmap
*users
; /* indexed by UID */
36 Hashmap
*brightness_writers
;
38 LIST_HEAD(Seat
, seat_gc_queue
);
39 LIST_HEAD(Session
, session_gc_queue
);
40 LIST_HEAD(User
, user_gc_queue
);
42 sd_device_monitor
*device_seat_monitor
, *device_monitor
, *device_vcsa_monitor
, *device_button_monitor
;
44 sd_event_source
*console_active_event_source
;
47 sd_event_source
*utmp_event_source
;
50 int console_active_fd
;
59 char **kill_only_users
, **kill_exclude_users
;
60 bool kill_user_processes
;
62 unsigned long session_counter
;
63 unsigned long inhibit_counter
;
65 Hashmap
*session_units
;
68 usec_t inhibit_delay_max
;
69 usec_t user_stop_delay
;
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
;
75 /* If a shutdown/suspend is currently executed, then this is the job of it */
77 sd_event_source
*inhibit_timeout_source
;
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
;
88 bool enable_wall_messages
;
89 sd_event_source
*wall_message_timeout_source
;
91 bool shutdown_dry_run
;
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
;
99 usec_t stop_idle_session_usec
;
101 HandleAction handle_power_key
;
102 HandleAction handle_power_key_long_press
;
103 HandleAction handle_reboot_key
;
104 HandleAction handle_reboot_key_long_press
;
105 HandleAction handle_suspend_key
;
106 HandleAction handle_suspend_key_long_press
;
107 HandleAction handle_hibernate_key
;
108 HandleAction handle_hibernate_key_long_press
;
110 HandleAction handle_lid_switch
;
111 HandleAction handle_lid_switch_ep
;
112 HandleAction handle_lid_switch_docked
;
114 bool power_key_ignore_inhibited
;
115 bool suspend_key_ignore_inhibited
;
116 bool hibernate_key_ignore_inhibited
;
117 bool lid_switch_ignore_inhibited
;
118 bool reboot_key_ignore_inhibited
;
122 Hashmap
*polkit_registry
;
124 usec_t holdoff_timeout_usec
;
125 sd_event_source
*lid_switch_ignore_event_source
;
127 sd_event_source
*power_key_long_press_event_source
;
128 sd_event_source
*reboot_key_long_press_event_source
;
129 sd_event_source
*suspend_key_long_press_event_source
;
130 sd_event_source
*hibernate_key_long_press_event_source
;
132 uint64_t runtime_dir_size
;
133 uint64_t runtime_dir_inodes
;
134 uint64_t sessions_max
;
135 uint64_t inhibitors_max
;
137 char **efi_boot_loader_entries
;
138 bool efi_boot_loader_entries_set
;
140 char *efi_loader_entry_one_shot
;
141 struct stat efi_loader_entry_one_shot_stat
;
144 void manager_reset_config(Manager
*m
);
145 int manager_parse_config_file(Manager
*m
);
147 int manager_add_device(Manager
*m
, const char *sysfs
, bool master
, Device
**ret_device
);
148 int manager_add_button(Manager
*m
, const char *name
, Button
**ret_button
);
149 int manager_add_seat(Manager
*m
, const char *id
, Seat
**ret_seat
);
150 int manager_add_session(Manager
*m
, const char *id
, Session
**ret_session
);
151 int manager_add_user(Manager
*m
, UserRecord
*ur
, User
**ret_user
);
152 int manager_add_user_by_name(Manager
*m
, const char *name
, User
**ret_user
);
153 int manager_add_user_by_uid(Manager
*m
, uid_t uid
, User
**ret_user
);
154 int manager_add_inhibitor(Manager
*m
, const char* id
, Inhibitor
**ret_inhibitor
);
156 int manager_process_seat_device(Manager
*m
, sd_device
*d
);
157 int manager_process_button_device(Manager
*m
, sd_device
*d
);
159 int manager_spawn_autovt(Manager
*m
, unsigned vtnr
);
161 bool manager_shall_kill(Manager
*m
, const char *user
);
163 int manager_get_idle_hint(Manager
*m
, dual_timestamp
*t
);
165 int manager_get_user_by_pid(Manager
*m
, pid_t pid
, User
**user
);
166 int manager_get_session_by_pid(Manager
*m
, pid_t pid
, Session
**session
);
168 bool manager_is_lid_closed(Manager
*m
);
169 bool manager_is_docked_or_external_displays(Manager
*m
);
170 bool manager_is_on_external_power(void);
171 bool manager_all_buttons_ignored(Manager
*m
);
173 int manager_read_utmp(Manager
*m
);
174 void manager_connect_utmp(Manager
*m
);
175 void manager_reconnect_utmp(Manager
*m
);
177 /* gperf lookup function */
178 const struct ConfigPerfItem
* logind_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
180 int manager_set_lid_switch_ignore(Manager
*m
, usec_t until
);
182 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts
);
183 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size
);
185 int manager_setup_wall_message_timer(Manager
*m
);
186 bool logind_wall_tty_filter(const char *tty
, bool is_local
, void *userdata
);
188 int manager_read_efi_boot_loader_entries(Manager
*m
);