2011-05-23 23:55:06 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2011 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-05-23 23:55:06 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2011-05-23 23:55:06 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2011-05-23 23:55:06 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <libudev.h>
|
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
#include "sd-event.h"
|
|
|
|
#include "sd-bus.h"
|
2011-05-23 23:55:06 +02:00
|
|
|
#include "util.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "hashmap.h"
|
2013-11-05 01:10:21 +01:00
|
|
|
#include "set.h"
|
2011-05-23 23:55:06 +02:00
|
|
|
|
|
|
|
typedef struct Manager Manager;
|
|
|
|
|
2011-05-24 00:19:22 +02:00
|
|
|
#include "logind-device.h"
|
|
|
|
#include "logind-seat.h"
|
|
|
|
#include "logind-session.h"
|
|
|
|
#include "logind-user.h"
|
2012-04-16 16:47:33 +02:00
|
|
|
#include "logind-inhibit.h"
|
2012-05-30 15:01:51 +02:00
|
|
|
#include "logind-button.h"
|
2012-12-23 22:32:48 +01:00
|
|
|
#include "logind-action.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
|
|
|
|
|
|
|
Set *busnames;
|
2011-05-23 23:55:06 +02: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);
|
|
|
|
|
2011-05-23 23:55:06 +02:00
|
|
|
struct udev *udev;
|
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;
|
|
|
|
usec_t action_timestamp;
|
2013-01-24 04:56:44 +01:00
|
|
|
|
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;
|
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
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
Hashmap *polkit_registry;
|
2011-05-23 23:55:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Manager *manager_new(void);
|
|
|
|
void manager_free(Manager *m);
|
2011-05-25 00:55:58 +02:00
|
|
|
|
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
|
|
|
|
2011-06-28 03:21:14 +02:00
|
|
|
int manager_process_seat_device(Manager *m, struct udev_device *d);
|
2012-05-30 15:01:51 +02:00
|
|
|
int manager_process_button_device(Manager *m, struct udev_device *d);
|
|
|
|
|
2011-05-23 23:55:06 +02:00
|
|
|
int manager_startup(Manager *m);
|
|
|
|
int manager_run(Manager *m);
|
|
|
|
int manager_spawn_autovt(Manager *m, int vtnr);
|
|
|
|
|
2011-06-29 03:48:16 +02:00
|
|
|
void manager_gc(Manager *m, bool drop_not_started);
|
2011-05-25 00:55:58 +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);
|
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
extern const sd_bus_vtable manager_vtable[];
|
2011-05-26 02:21:16 +02:00
|
|
|
|
2013-11-21 19:34:37 +01:00
|
|
|
int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
|
|
|
|
int match_name_owner_changed(sd_bus *bus, 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
|
|
|
|
2012-05-08 19:02:25 +02:00
|
|
|
int manager_dispatch_delayed(Manager *manager);
|
2012-05-05 00:34:48 +02:00
|
|
|
|
2013-11-05 01:10:21 +01:00
|
|
|
int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *kill_mode, sd_bus_error *error, char **job);
|
|
|
|
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);
|
|
|
|
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 */
|
|
|
|
const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
|
2013-09-17 17:39:55 +02:00
|
|
|
|
|
|
|
int manager_watch_busname(Manager *manager, const char *name);
|
|
|
|
void manager_drop_busname(Manager *manager, const char *name);
|