2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "libudev.h"
|
2013-11-05 01:10:21 +01:00
|
|
|
#include "sd-bus.h"
|
2018-08-22 07:53:51 +02:00
|
|
|
#include "sd-device.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "sd-event.h"
|
|
|
|
|
2018-05-22 13:10:17 +02:00
|
|
|
#include "conf-parser.h"
|
2011-05-23 23:55:06 +02:00
|
|
|
#include "hashmap.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "list.h"
|
2013-11-05 01:10:21 +01:00
|
|
|
#include "set.h"
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
typedef struct Manager Manager;
|
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "logind-action.h"
|
|
|
|
#include "logind-button.h"
|
2011-05-24 00:19:22 +02:00
|
|
|
#include "logind-device.h"
|
2012-04-16 16:47:33 +02:00
|
|
|
#include "logind-inhibit.h"
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
struct Manager {
|
2013-11-05 01:10:21 +01:00
|
|
|
sd_event *event;
|
|
|
|
sd_bus *bus;
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
Hashmap *devices;
|
|
|
|
Hashmap *seats;
|
|
|
|
Hashmap *sessions;
|
|
|
|
Hashmap *users;
|
2012-04-16 16:47:33 +02:00
|
|
|
Hashmap *inhibitors;
|
2012-05-30 15:01:51 +02:00
|
|
|
Hashmap *buttons;
|
2013-11-05 01:10:21 +01:00
|
|
|
|
2011-05-25 00:55:58 +02:00
|
|
|
LIST_HEAD(Seat, seat_gc_queue);
|
|
|
|
LIST_HEAD(Session, session_gc_queue);
|
|
|
|
LIST_HEAD(User, user_gc_queue);
|
|
|
|
|
logind: listen actively for session devices
Session compositors need access to fbdev, DRM and evdev devices if they
control a session. To make logind pass them to sessions, we need to
listen for them actively.
However, we avoid creating new seats for non master-of-seat devices. Only
once a seat is created, we start remembering all other session devices. If
the last master-device is removed (even if there are other non-master
devices still available), we destroy the seat. This is the current
behavior, but we need to explicitly implement it now as there may be
non-master devices in the seat->devices list.
Unlike master devices, we don't care whether our list of non-master
devices is complete. We don't export this list but use it only as cache if
sessions request these devices. Hence, if a session requests a device that
is not in the list, we will simply look it up. However, once a session
requested a device, we must be notified of "remove" udev events. So we
must link the devices somehow into the device-list.
Regarding the implementation, we now sort the device list by the "master"
flag. This guarantees that master devices are at the front and non-master
devices at the tail of the list. Thus, we can easily test whether a seat
has a master device attached.
2013-09-17 17:39:54 +02:00
|
|
|
struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
|
2011-06-28 03:21:14 +02:00
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
sd_event_source *console_active_event_source;
|
|
|
|
sd_event_source *udev_seat_event_source;
|
|
|
|
sd_event_source *udev_device_event_source;
|
|
|
|
sd_event_source *udev_vcsa_event_source;
|
|
|
|
sd_event_source *udev_button_event_source;
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
int console_active_fd;
|
|
|
|
|
2011-05-26 02:21:16 +02:00
|
|
|
unsigned n_autovts;
|
2011-05-23 23:55:06 +02:00
|
|
|
|
2012-09-17 12:39:16 +02:00
|
|
|
unsigned reserve_vt;
|
|
|
|
int reserve_vt_fd;
|
|
|
|
|
2013-09-17 17:39:59 +02:00
|
|
|
Seat *seat0;
|
2011-05-23 23:55:06 +02:00
|
|
|
|
2011-05-26 02:21:16 +02:00
|
|
|
char **kill_only_users, **kill_exclude_users;
|
2011-05-23 23:55:06 +02:00
|
|
|
bool kill_user_processes;
|
2011-06-24 18:50:50 +02:00
|
|
|
|
|
|
|
unsigned long session_counter;
|
2012-04-16 16:47:33 +02:00
|
|
|
unsigned long inhibit_counter;
|
2011-06-24 20:41:56 +02:00
|
|
|
|
2013-07-02 01:46:30 +02:00
|
|
|
Hashmap *session_units;
|
|
|
|
Hashmap *user_units;
|
2012-05-31 19:46:42 +02:00
|
|
|
|
2012-05-05 00:34:48 +02:00
|
|
|
usec_t inhibit_delay_max;
|
2012-05-30 15:01:51 +02:00
|
|
|
|
2013-01-25 06:30:23 +01:00
|
|
|
/* If an action is currently being executed or is delayed,
|
|
|
|
* this is != 0 and encodes what is being done */
|
|
|
|
InhibitWhat action_what;
|
|
|
|
|
|
|
|
/* If a shutdown/suspend was delayed due to a inhibitor this
|
|
|
|
contains the unit name we are supposed to start after the
|
|
|
|
delay is over */
|
|
|
|
const char *action_unit;
|
|
|
|
|
|
|
|
/* If a shutdown/suspend is currently executed, then this is
|
|
|
|
* the job of it */
|
|
|
|
char *action_job;
|
2015-04-11 18:44:51 +02:00
|
|
|
sd_event_source *inhibit_timeout_source;
|
2013-01-24 04:56:44 +01:00
|
|
|
|
2015-04-20 15:27:15 +02:00
|
|
|
char *scheduled_shutdown_type;
|
|
|
|
usec_t scheduled_shutdown_timeout;
|
|
|
|
sd_event_source *scheduled_shutdown_timeout_source;
|
2015-04-22 17:20:42 +02:00
|
|
|
uid_t scheduled_shutdown_uid;
|
|
|
|
char *scheduled_shutdown_tty;
|
2015-04-23 17:11:28 +02:00
|
|
|
sd_event_source *nologin_timeout_source;
|
|
|
|
bool unlink_nologin;
|
2015-04-22 17:20:42 +02:00
|
|
|
|
|
|
|
char *wall_message;
|
|
|
|
unsigned enable_wall_messages;
|
|
|
|
sd_event_source *wall_message_timeout_source;
|
2015-04-20 15:27:15 +02:00
|
|
|
|
2015-09-09 17:05:03 +02:00
|
|
|
bool shutdown_dry_run;
|
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
sd_event_source *idle_action_event_source;
|
2012-12-23 22:32:48 +01:00
|
|
|
usec_t idle_action_usec;
|
|
|
|
usec_t idle_action_not_before_usec;
|
|
|
|
HandleAction idle_action;
|
|
|
|
|
|
|
|
HandleAction handle_power_key;
|
|
|
|
HandleAction handle_suspend_key;
|
|
|
|
HandleAction handle_hibernate_key;
|
|
|
|
HandleAction handle_lid_switch;
|
2018-02-09 17:37:39 +01:00
|
|
|
HandleAction handle_lid_switch_ep;
|
2014-08-26 22:08:02 +02:00
|
|
|
HandleAction handle_lid_switch_docked;
|
2012-09-19 13:10:10 +02:00
|
|
|
|
|
|
|
bool power_key_ignore_inhibited;
|
2012-09-21 15:44:14 +02:00
|
|
|
bool suspend_key_ignore_inhibited;
|
|
|
|
bool hibernate_key_ignore_inhibited;
|
2012-09-19 13:10:10 +02:00
|
|
|
bool lid_switch_ignore_inhibited;
|
2011-06-24 23:25:28 +02:00
|
|
|
|
2014-03-14 01:38:19 +01:00
|
|
|
bool remove_ipc;
|
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
Hashmap *polkit_registry;
|
2014-03-03 20:49:33 +01:00
|
|
|
|
2015-03-06 14:37:09 +01:00
|
|
|
usec_t holdoff_timeout_usec;
|
2014-03-03 20:49:33 +01:00
|
|
|
sd_event_source *lid_switch_ignore_event_source;
|
2014-03-04 19:20:21 +01:00
|
|
|
|
2018-05-17 04:33:13 +02:00
|
|
|
uint64_t runtime_dir_size;
|
2015-11-13 18:25:02 +01:00
|
|
|
uint64_t user_tasks_max;
|
2016-05-04 18:57:15 +02:00
|
|
|
uint64_t sessions_max;
|
2016-05-04 19:40:05 +02:00
|
|
|
uint64_t inhibitors_max;
|
2011-05-23 23:55:06 +02:00
|
|
|
};
|
|
|
|
|
2017-12-09 11:53:17 +01:00
|
|
|
void manager_reset_config(Manager *m);
|
|
|
|
int manager_parse_config_file(Manager *m);
|
|
|
|
|
logind: listen actively for session devices
Session compositors need access to fbdev, DRM and evdev devices if they
control a session. To make logind pass them to sessions, we need to
listen for them actively.
However, we avoid creating new seats for non master-of-seat devices. Only
once a seat is created, we start remembering all other session devices. If
the last master-device is removed (even if there are other non-master
devices still available), we destroy the seat. This is the current
behavior, but we need to explicitly implement it now as there may be
non-master devices in the seat->devices list.
Unlike master devices, we don't care whether our list of non-master
devices is complete. We don't export this list but use it only as cache if
sessions request these devices. Hence, if a session requests a device that
is not in the list, we will simply look it up. However, once a session
requested a device, we must be notified of "remove" udev events. So we
must link the devices somehow into the device-list.
Regarding the implementation, we now sort the device list by the "master"
flag. This guarantees that master devices are at the front and non-master
devices at the tail of the list. Thus, we can easily test whether a seat
has a master device attached.
2013-09-17 17:39:54 +02:00
|
|
|
int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
|
2012-05-30 15:01:51 +02:00
|
|
|
int manager_add_button(Manager *m, const char *name, Button **_button);
|
2011-05-23 23:55:06 +02:00
|
|
|
int manager_add_seat(Manager *m, const char *id, Seat **_seat);
|
2013-06-20 03:45:08 +02:00
|
|
|
int manager_add_session(Manager *m, const char *id, Session **_session);
|
2011-05-23 23:55:06 +02:00
|
|
|
int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
|
|
|
|
int manager_add_user_by_name(Manager *m, const char *name, User **_user);
|
|
|
|
int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
|
2012-04-16 16:47:33 +02:00
|
|
|
int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
|
2011-05-25 00:55:58 +02:00
|
|
|
|
2018-08-22 07:53:51 +02:00
|
|
|
int manager_process_seat_device(Manager *m, sd_device *d);
|
|
|
|
int manager_process_button_device(Manager *m, sd_device *d);
|
2012-05-30 15:01:51 +02:00
|
|
|
|
2013-11-28 17:05:34 +01:00
|
|
|
int manager_spawn_autovt(Manager *m, unsigned int vtnr);
|
2011-05-23 23:55:06 +02:00
|
|
|
|
2013-08-13 17:59:28 +02:00
|
|
|
bool manager_shall_kill(Manager *m, const char *user);
|
|
|
|
|
2011-06-17 15:59:18 +02:00
|
|
|
int manager_get_idle_hint(Manager *m, dual_timestamp *t);
|
|
|
|
|
2013-06-20 03:45:08 +02:00
|
|
|
int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
|
2012-01-31 23:51:16 +01:00
|
|
|
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
|
|
|
|
|
2015-06-17 00:24:05 +02:00
|
|
|
bool manager_is_docked_or_external_displays(Manager *m);
|
2018-02-09 17:37:39 +01:00
|
|
|
bool manager_is_on_external_power(void);
|
|
|
|
bool manager_all_buttons_ignored(Manager *m);
|
2014-02-24 16:22:23 +01:00
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
extern const sd_bus_vtable manager_vtable[];
|
2011-05-26 02:21:16 +02:00
|
|
|
|
2015-04-29 18:35:10 +02:00
|
|
|
int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
2011-06-24 20:41:56 +02:00
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
|
2012-05-30 15:01:51 +02:00
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
|
2011-06-21 21:46:13 +02:00
|
|
|
|
2018-04-17 16:42:44 +02:00
|
|
|
int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, sd_bus_message *more_properties, sd_bus_error *error, char **job);
|
2013-11-05 01:10:21 +01:00
|
|
|
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
|
|
|
|
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
|
2014-02-06 18:32:14 +01:00
|
|
|
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
|
2013-11-05 01:10:21 +01:00
|
|
|
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
|
2013-07-02 01:46:30 +02:00
|
|
|
int manager_unit_is_active(Manager *manager, const char *unit);
|
2013-11-05 01:10:21 +01:00
|
|
|
int manager_job_is_active(Manager *manager, const char *path);
|
2013-07-02 01:46:30 +02:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
/* gperf lookup function */
|
2017-01-10 08:39:05 +01:00
|
|
|
const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
|
2013-09-17 17:39:55 +02:00
|
|
|
|
2014-03-03 20:49:33 +01:00
|
|
|
int manager_set_lid_switch_ignore(Manager *m, usec_t until);
|
2014-03-04 19:20:21 +01:00
|
|
|
|
2018-05-22 13:10:17 +02:00
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
|
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
|
2015-01-09 16:14:19 +01:00
|
|
|
|
|
|
|
int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
|
|
|
|
int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);
|
|
|
|
int manager_get_seat_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Seat **ret);
|
2015-04-22 17:20:42 +02:00
|
|
|
|
|
|
|
int manager_setup_wall_message_timer(Manager *m);
|
|
|
|
bool logind_wall_tty_filter(const char *tty, void *userdata);
|
2015-06-08 22:58:50 +02:00
|
|
|
|
|
|
|
int manager_dispatch_delayed(Manager *manager, bool timeout);
|