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 an action is currently being executed or is delayed,
72 * this is != 0 and encodes what is being done */
73 InhibitWhat action_what
;
75 /* If a shutdown/suspend was delayed due to an inhibitor this
76 contains the unit name we are supposed to start after the
78 const char *action_unit
;
80 /* If a shutdown/suspend is currently executed, then this is
83 sd_event_source
*inhibit_timeout_source
;
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
;
94 unsigned enable_wall_messages
;
95 sd_event_source
*wall_message_timeout_source
;
97 bool shutdown_dry_run
;
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
;
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
;
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
;
120 Hashmap
*polkit_registry
;
122 usec_t holdoff_timeout_usec
;
123 sd_event_source
*lid_switch_ignore_event_source
;
125 uint64_t runtime_dir_size
;
126 uint64_t runtime_dir_inodes
;
127 uint64_t sessions_max
;
128 uint64_t inhibitors_max
;
130 char **efi_boot_loader_entries
;
131 bool efi_boot_loader_entries_set
;
133 char *efi_loader_entry_one_shot
;
134 struct stat efi_loader_entry_one_shot_stat
;
137 void manager_reset_config(Manager
*m
);
138 int manager_parse_config_file(Manager
*m
);
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
);
149 int manager_process_seat_device(Manager
*m
, sd_device
*d
);
150 int manager_process_button_device(Manager
*m
, sd_device
*d
);
152 int manager_spawn_autovt(Manager
*m
, unsigned vtnr
);
154 bool manager_shall_kill(Manager
*m
, const char *user
);
156 int manager_get_idle_hint(Manager
*m
, dual_timestamp
*t
);
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
);
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
);
166 int manager_read_utmp(Manager
*m
);
167 void manager_connect_utmp(Manager
*m
);
168 void manager_reconnect_utmp(Manager
*m
);
170 /* gperf lookup function */
171 const struct ConfigPerfItem
* logind_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
173 int manager_set_lid_switch_ignore(Manager
*m
, usec_t until
);
175 CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts
);
176 CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size
);
178 int manager_setup_wall_message_timer(Manager
*m
);
179 bool logind_wall_tty_filter(const char *tty
, void *userdata
);
181 int manager_read_efi_boot_loader_entries(Manager
*m
);