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 98 HandleAction handle_power_key; 99 HandleAction handle_power_key_long_press; 100 HandleAction handle_reboot_key; 101 HandleAction handle_reboot_key_long_press; 102 HandleAction handle_suspend_key; 103 HandleAction handle_suspend_key_long_press; 104 HandleAction handle_hibernate_key; 105 HandleAction handle_hibernate_key_long_press; 106 107 HandleAction handle_lid_switch; 108 HandleAction handle_lid_switch_ep; 109 HandleAction handle_lid_switch_docked; 110 111 bool power_key_ignore_inhibited; 112 bool suspend_key_ignore_inhibited; 113 bool hibernate_key_ignore_inhibited; 114 bool lid_switch_ignore_inhibited; 115 bool reboot_key_ignore_inhibited; 116 117 bool remove_ipc; 118 119 Hashmap *polkit_registry; 120 121 usec_t holdoff_timeout_usec; 122 sd_event_source *lid_switch_ignore_event_source; 123 124 sd_event_source *power_key_long_press_event_source; 125 sd_event_source *reboot_key_long_press_event_source; 126 sd_event_source *suspend_key_long_press_event_source; 127 sd_event_source *hibernate_key_long_press_event_source; 128 129 uint64_t runtime_dir_size; 130 uint64_t runtime_dir_inodes; 131 uint64_t sessions_max; 132 uint64_t inhibitors_max; 133 134 char **efi_boot_loader_entries; 135 bool efi_boot_loader_entries_set; 136 137 char *efi_loader_entry_one_shot; 138 struct stat efi_loader_entry_one_shot_stat; 139 }; 140 141 void manager_reset_config(Manager *m); 142 int manager_parse_config_file(Manager *m); 143 144 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device); 145 int manager_add_button(Manager *m, const char *name, Button **ret_button); 146 int manager_add_seat(Manager *m, const char *id, Seat **ret_seat); 147 int manager_add_session(Manager *m, const char *id, Session **ret_session); 148 int manager_add_user(Manager *m, UserRecord *ur, User **ret_user); 149 int manager_add_user_by_name(Manager *m, const char *name, User **ret_user); 150 int manager_add_user_by_uid(Manager *m, uid_t uid, User **ret_user); 151 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret_inhibitor); 152 153 int manager_process_seat_device(Manager *m, sd_device *d); 154 int manager_process_button_device(Manager *m, sd_device *d); 155 156 int manager_spawn_autovt(Manager *m, unsigned vtnr); 157 158 bool manager_shall_kill(Manager *m, const char *user); 159 160 int manager_get_idle_hint(Manager *m, dual_timestamp *t); 161 162 int manager_get_user_by_pid(Manager *m, pid_t pid, User **user); 163 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session); 164 165 bool manager_is_lid_closed(Manager *m); 166 bool manager_is_docked_or_external_displays(Manager *m); 167 bool manager_is_on_external_power(void); 168 bool manager_all_buttons_ignored(Manager *m); 169 170 int manager_read_utmp(Manager *m); 171 void manager_connect_utmp(Manager *m); 172 void manager_reconnect_utmp(Manager *m); 173 174 /* gperf lookup function */ 175 const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length); 176 177 int manager_set_lid_switch_ignore(Manager *m, usec_t until); 178 179 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts); 180 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size); 181 182 int manager_setup_wall_message_timer(Manager *m); 183 bool logind_wall_tty_filter(const char *tty, void *userdata); 184 185 int manager_read_efi_boot_loader_entries(Manager *m); 186