Systemd/src/login/logind.h

182 lines
5.4 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <sys/stat.h>
2013-11-05 01:10:21 +01:00
#include "sd-bus.h"
#include "sd-device.h"
#include "sd-event.h"
#include "conf-parser.h"
#include "hashmap.h"
#include "list.h"
2013-11-05 01:10:21 +01:00
#include "set.h"
#include "time-util.h"
#include "user-record.h"
typedef struct Manager Manager;
#include "logind-action.h"
#include "logind-button.h"
2011-05-24 00:19:22 +02:00
#include "logind-device.h"
#include "logind-inhibit.h"
struct Manager {
2013-11-05 01:10:21 +01:00
sd_event *event;
sd_bus *bus;
Hashmap *devices;
Hashmap *seats;
Hashmap *sessions;
Hashmap *sessions_by_leader;
Hashmap *users; /* indexed by UID */
Hashmap *inhibitors;
Hashmap *buttons;
logind: add SetBrightness() bus call for setting brightness of leds/backlight devices associated with a seat This augments the drm/input device management by adding a single method call for setting the brightness of an "leds" or "backlight" kernel class device. This method call requires no privileges to call, but a caller can only change the brightness on sessions that are currently active, and they must own the session. This does not do enumeration of such class devices, feature or range probing, chnage notification; it doesn't help associating graphics or input devices with their backlight or leds devices. For all that clients should go directly to udev/sysfs. The SetBrightness() call is just for executing the actual change operation, that is otherwise privileged. Example line: busctl call org.freedesktop.login1 /org/freedesktop/login1/session/self org.freedesktop.login1.Session SetBrightness ssu "backlight" "intel_backlight" 200 The parameter the SetBrightness() call takes are the kernel subsystem (i.e. "leds" or "backlight"), the device name, and the brightness value. On some hw setting the brightness is slow, and implementation and write access to the sysfs knobs exposes this slowness. Due to this we'll fork off a writer process in the background so that logind doesn't have to block. Moreover, write requestes are coalesced: when a write request is enqueued while one is already being executed it is queued. When another write reques is then enqueued the earlier one is replaced by the newer one, so that only one queued write request per device remains at any time. Method replies are sent as soon as the first write request that happens after the request was received is completed. It is recommended that bus clients turn off the "expect_reply" flag on the dbus messages they send though, that relieves logind from sending completion notification and is particularly a good idea if clients implement reactive UI sliders that send a quick secession of write requests. Replaces: #12413
2019-04-28 11:07:56 +02:00
Hashmap *brightness_writers;
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);
sd_device_monitor *device_seat_monitor, *device_monitor, *device_vcsa_monitor, *device_button_monitor;
2013-11-05 01:10:21 +01:00
sd_event_source *console_active_event_source;
#if ENABLE_UTMP
sd_event_source *utmp_event_source;
#endif
int console_active_fd;
2011-05-26 02:21:16 +02:00
unsigned n_autovts;
unsigned reserve_vt;
int reserve_vt_fd;
Seat *seat0;
2011-05-26 02:21:16 +02:00
char **kill_only_users, **kill_exclude_users;
bool kill_user_processes;
2011-06-24 18:50:50 +02:00
unsigned long session_counter;
unsigned long inhibit_counter;
Hashmap *session_units;
Hashmap *user_units;
usec_t inhibit_delay_max;
usec_t user_stop_delay;
/* 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;
sd_event_source *inhibit_timeout_source;
char *scheduled_shutdown_type;
usec_t scheduled_shutdown_timeout;
sd_event_source *scheduled_shutdown_timeout_source;
uid_t scheduled_shutdown_uid;
char *scheduled_shutdown_tty;
sd_event_source *nologin_timeout_source;
bool unlink_nologin;
char *wall_message;
unsigned enable_wall_messages;
sd_event_source *wall_message_timeout_source;
bool shutdown_dry_run;
2013-11-05 01:10:21 +01:00
sd_event_source *idle_action_event_source;
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;
HandleAction handle_lid_switch_ep;
HandleAction handle_lid_switch_docked;
HandleAction handle_reboot_key;
bool power_key_ignore_inhibited;
bool suspend_key_ignore_inhibited;
bool hibernate_key_ignore_inhibited;
bool lid_switch_ignore_inhibited;
bool reboot_key_ignore_inhibited;
bool remove_ipc;
2013-11-05 01:10:21 +01:00
Hashmap *polkit_registry;
usec_t holdoff_timeout_usec;
sd_event_source *lid_switch_ignore_event_source;
uint64_t runtime_dir_size;
uint64_t runtime_dir_inodes;
uint64_t sessions_max;
uint64_t inhibitors_max;
char **efi_boot_loader_entries;
bool efi_boot_loader_entries_set;
char *efi_loader_entry_one_shot;
struct stat efi_loader_entry_one_shot_stat;
};
void manager_reset_config(Manager *m);
int manager_parse_config_file(Manager *m);
2019-09-06 09:18:33 +02:00
int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device);
int manager_add_button(Manager *m, const char *name, Button **ret_button);
int manager_add_seat(Manager *m, const char *id, Seat **ret_seat);
int manager_add_session(Manager *m, const char *id, Session **ret_session);
int manager_add_user(Manager *m, UserRecord *ur, User **ret_user);
2019-09-06 09:18:33 +02:00
int manager_add_user_by_name(Manager *m, const char *name, User **ret_user);
int manager_add_user_by_uid(Manager *m, uid_t uid, User **ret_user);
int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret_inhibitor);
2011-05-25 00:55:58 +02:00
int manager_process_seat_device(Manager *m, sd_device *d);
int manager_process_button_device(Manager *m, sd_device *d);
int manager_spawn_autovt(Manager *m, unsigned vtnr);
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);
int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
bool manager_is_lid_closed(Manager *m);
bool manager_is_docked_or_external_displays(Manager *m);
bool manager_is_on_external_power(void);
bool manager_all_buttons_ignored(Manager *m);
int manager_read_utmp(Manager *m);
void manager_connect_utmp(Manager *m);
void manager_reconnect_utmp(Manager *m);
/* gperf lookup function */
const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
int manager_set_lid_switch_ignore(Manager *m, usec_t until);
CONFIG_PARSER_PROTOTYPE(config_parse_n_autovts);
CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs_size);
int manager_setup_wall_message_timer(Manager *m);
bool logind_wall_tty_filter(const char *tty, void *userdata);
int manager_read_efi_boot_loader_entries(Manager *m);