1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2011 Lennart Poettering
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
33 typedef struct Manager Manager
;
35 #include "logind-action.h"
36 #include "logind-button.h"
37 #include "logind-device.h"
38 #include "logind-inhibit.h"
51 LIST_HEAD(Seat
, seat_gc_queue
);
52 LIST_HEAD(Session
, session_gc_queue
);
53 LIST_HEAD(User
, user_gc_queue
);
56 struct udev_monitor
*udev_seat_monitor
, *udev_device_monitor
, *udev_vcsa_monitor
, *udev_button_monitor
;
58 sd_event_source
*console_active_event_source
;
59 sd_event_source
*udev_seat_event_source
;
60 sd_event_source
*udev_device_event_source
;
61 sd_event_source
*udev_vcsa_event_source
;
62 sd_event_source
*udev_button_event_source
;
64 int console_active_fd
;
73 char **kill_only_users
, **kill_exclude_users
;
74 bool kill_user_processes
;
76 unsigned long session_counter
;
77 unsigned long inhibit_counter
;
79 Hashmap
*session_units
;
82 usec_t inhibit_delay_max
;
84 /* If an action is currently being executed or is delayed,
85 * this is != 0 and encodes what is being done */
86 InhibitWhat action_what
;
88 /* If a shutdown/suspend was delayed due to a inhibitor this
89 contains the unit name we are supposed to start after the
91 const char *action_unit
;
93 /* If a shutdown/suspend is currently executed, then this is
96 sd_event_source
*inhibit_timeout_source
;
98 char *scheduled_shutdown_type
;
99 usec_t scheduled_shutdown_timeout
;
100 sd_event_source
*scheduled_shutdown_timeout_source
;
101 uid_t scheduled_shutdown_uid
;
102 char *scheduled_shutdown_tty
;
103 sd_event_source
*nologin_timeout_source
;
107 unsigned enable_wall_messages
;
108 sd_event_source
*wall_message_timeout_source
;
110 bool shutdown_dry_run
;
112 sd_event_source
*idle_action_event_source
;
113 usec_t idle_action_usec
;
114 usec_t idle_action_not_before_usec
;
115 HandleAction idle_action
;
117 HandleAction handle_power_key
;
118 HandleAction handle_suspend_key
;
119 HandleAction handle_hibernate_key
;
120 HandleAction handle_lid_switch
;
121 HandleAction handle_lid_switch_docked
;
123 bool power_key_ignore_inhibited
;
124 bool suspend_key_ignore_inhibited
;
125 bool hibernate_key_ignore_inhibited
;
126 bool lid_switch_ignore_inhibited
;
130 Hashmap
*polkit_registry
;
132 usec_t holdoff_timeout_usec
;
133 sd_event_source
*lid_switch_ignore_event_source
;
135 size_t runtime_dir_size
;
136 uint64_t user_tasks_max
;
137 uint64_t sessions_max
;
138 uint64_t inhibitors_max
;
141 int manager_add_device(Manager
*m
, const char *sysfs
, bool master
, Device
**_device
);
142 int manager_add_button(Manager
*m
, const char *name
, Button
**_button
);
143 int manager_add_seat(Manager
*m
, const char *id
, Seat
**_seat
);
144 int manager_add_session(Manager
*m
, const char *id
, Session
**_session
);
145 int manager_add_user(Manager
*m
, uid_t uid
, gid_t gid
, const char *name
, User
**_user
);
146 int manager_add_user_by_name(Manager
*m
, const char *name
, User
**_user
);
147 int manager_add_user_by_uid(Manager
*m
, uid_t uid
, User
**_user
);
148 int manager_add_inhibitor(Manager
*m
, const char* id
, Inhibitor
**_inhibitor
);
150 int manager_process_seat_device(Manager
*m
, struct udev_device
*d
);
151 int manager_process_button_device(Manager
*m
, struct udev_device
*d
);
153 int manager_spawn_autovt(Manager
*m
, unsigned int vtnr
);
155 bool manager_shall_kill(Manager
*m
, const char *user
);
157 int manager_get_idle_hint(Manager
*m
, dual_timestamp
*t
);
159 int manager_get_user_by_pid(Manager
*m
, pid_t pid
, User
**user
);
160 int manager_get_session_by_pid(Manager
*m
, pid_t pid
, Session
**session
);
162 bool manager_is_docked_or_external_displays(Manager
*m
);
164 extern const sd_bus_vtable manager_vtable
[];
166 int match_job_removed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
167 int match_unit_removed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
168 int match_properties_changed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
169 int match_reloading(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
170 int match_name_owner_changed(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
);
172 int bus_manager_shutdown_or_sleep_now_or_later(Manager
*m
, const char *unit_name
, InhibitWhat w
, sd_bus_error
*error
);
174 int manager_send_changed(Manager
*manager
, const char *property
, ...) _sentinel_
;
176 int manager_start_slice(Manager
*manager
, const char *slice
, const char *description
, const char *after
, const char *after2
, uint64_t tasks_max
, sd_bus_error
*error
, char **job
);
177 int manager_start_scope(Manager
*manager
, const char *scope
, pid_t pid
, const char *slice
, const char *description
, const char *after
, const char *after2
, uint64_t tasks_max
, sd_bus_error
*error
, char **job
);
178 int manager_start_unit(Manager
*manager
, const char *unit
, sd_bus_error
*error
, char **job
);
179 int manager_stop_unit(Manager
*manager
, const char *unit
, sd_bus_error
*error
, char **job
);
180 int manager_abandon_scope(Manager
*manager
, const char *scope
, sd_bus_error
*error
);
181 int manager_kill_unit(Manager
*manager
, const char *unit
, KillWho who
, int signo
, sd_bus_error
*error
);
182 int manager_unit_is_active(Manager
*manager
, const char *unit
);
183 int manager_job_is_active(Manager
*manager
, const char *path
);
185 /* gperf lookup function */
186 const struct ConfigPerfItem
* logind_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
188 int manager_set_lid_switch_ignore(Manager
*m
, usec_t until
);
190 int config_parse_n_autovts(const char *unit
, const char *filename
, unsigned line
, const char *section
, unsigned section_line
, const char *lvalue
, int ltype
, const char *rvalue
, void *data
, void *userdata
);
191 int config_parse_tmpfs_size(const char *unit
, const char *filename
, unsigned line
, const char *section
, unsigned section_line
, const char *lvalue
, int ltype
, const char *rvalue
, void *data
, void *userdata
);
192 int config_parse_user_tasks_max(const char *unit
, const char *filename
, unsigned line
, const char *section
, unsigned section_line
, const char *lvalue
, int ltype
, const char *rvalue
, void *data
, void *userdata
);
194 int manager_get_session_from_creds(Manager
*m
, sd_bus_message
*message
, const char *name
, sd_bus_error
*error
, Session
**ret
);
195 int manager_get_user_from_creds(Manager
*m
, sd_bus_message
*message
, uid_t uid
, sd_bus_error
*error
, User
**ret
);
196 int manager_get_seat_from_creds(Manager
*m
, sd_bus_message
*message
, const char *name
, sd_bus_error
*error
, Seat
**ret
);
198 int manager_setup_wall_message_timer(Manager
*m
);
199 bool logind_wall_tty_filter(const char *tty
, void *userdata
);
201 int manager_dispatch_delayed(Manager
*manager
, bool timeout
);