]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/login/logind.h
core: watch SIGCHLD more closely to track processes of units with no reliable cgroup...
[thirdparty/systemd.git] / src / login / logind.h
CommitLineData
20263082
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
c2f1db8f 3#pragma once
20263082
LP
4
5/***
6 This file is part of systemd.
7
8 Copyright 2011 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
20263082
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
20263082 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
20263082
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <stdbool.h>
25#include <inttypes.h>
20263082
LP
26#include <libudev.h>
27
cc377381
LP
28#include "sd-event.h"
29#include "sd-bus.h"
20263082
LP
30#include "util.h"
31#include "list.h"
32#include "hashmap.h"
cc377381 33#include "set.h"
20263082 34
20263082 35typedef struct Manager Manager;
20263082 36
90821c93
LP
37#include "logind-device.h"
38#include "logind-seat.h"
39#include "logind-session.h"
40#include "logind-user.h"
f8e2fb7b 41#include "logind-inhibit.h"
069cfc85 42#include "logind-button.h"
23406ce5 43#include "logind-action.h"
20263082
LP
44
45struct Manager {
cc377381
LP
46 sd_event *event;
47 sd_bus *bus;
20263082
LP
48
49 Hashmap *devices;
50 Hashmap *seats;
51 Hashmap *sessions;
52 Hashmap *users;
f8e2fb7b 53 Hashmap *inhibitors;
069cfc85 54 Hashmap *buttons;
cc377381
LP
55
56 Set *busnames;
20263082 57
14c3baca
LP
58 LIST_HEAD(Seat, seat_gc_queue);
59 LIST_HEAD(Session, session_gc_queue);
60 LIST_HEAD(User, user_gc_queue);
61
20263082 62 struct udev *udev;
718d006a 63 struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
30ed21ce 64
cc377381
LP
65 sd_event_source *console_active_event_source;
66 sd_event_source *udev_seat_event_source;
67 sd_event_source *udev_device_event_source;
68 sd_event_source *udev_vcsa_event_source;
69 sd_event_source *udev_button_event_source;
20263082 70
20263082 71 int console_active_fd;
20263082 72
3f49d45a 73 unsigned n_autovts;
20263082 74
98a77df5
LP
75 unsigned reserve_vt;
76 int reserve_vt_fd;
77
92432fcc 78 Seat *seat0;
20263082 79
3f49d45a 80 char **kill_only_users, **kill_exclude_users;
20263082 81 bool kill_user_processes;
98a28fef
LP
82
83 unsigned long session_counter;
f8e2fb7b 84 unsigned long inhibit_counter;
1713813d 85
fb6becb4
LP
86 Hashmap *session_units;
87 Hashmap *user_units;
8c8c4351 88
eecd1362 89 usec_t inhibit_delay_max;
069cfc85 90
314b4b0a
LP
91 /* If an action is currently being executed or is delayed,
92 * this is != 0 and encodes what is being done */
93 InhibitWhat action_what;
94
95 /* If a shutdown/suspend was delayed due to a inhibitor this
96 contains the unit name we are supposed to start after the
97 delay is over */
98 const char *action_unit;
99
100 /* If a shutdown/suspend is currently executed, then this is
101 * the job of it */
102 char *action_job;
103 usec_t action_timestamp;
af9792ac 104
cc377381 105 sd_event_source *idle_action_event_source;
23406ce5
LP
106 usec_t idle_action_usec;
107 usec_t idle_action_not_before_usec;
108 HandleAction idle_action;
109
110 HandleAction handle_power_key;
111 HandleAction handle_suspend_key;
112 HandleAction handle_hibernate_key;
113 HandleAction handle_lid_switch;
beaafb2e
LP
114
115 bool power_key_ignore_inhibited;
8e7fd6ad
LP
116 bool suspend_key_ignore_inhibited;
117 bool hibernate_key_ignore_inhibited;
beaafb2e 118 bool lid_switch_ignore_inhibited;
31b79c2b 119
cc377381 120 Hashmap *polkit_registry;
20263082
LP
121};
122
20263082
LP
123Manager *manager_new(void);
124void manager_free(Manager *m);
14c3baca 125
718d006a 126int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
069cfc85 127int manager_add_button(Manager *m, const char *name, Button **_button);
20263082 128int manager_add_seat(Manager *m, const char *id, Seat **_seat);
9444b1f2 129int manager_add_session(Manager *m, const char *id, Session **_session);
20263082
LP
130int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user);
131int manager_add_user_by_name(Manager *m, const char *name, User **_user);
132int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
f8e2fb7b 133int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
14c3baca 134
30ed21ce 135int manager_process_seat_device(Manager *m, struct udev_device *d);
069cfc85
LP
136int manager_process_button_device(Manager *m, struct udev_device *d);
137
20263082
LP
138int manager_startup(Manager *m);
139int manager_run(Manager *m);
92bd5ff3 140int manager_spawn_autovt(Manager *m, unsigned int vtnr);
20263082 141
4a4b033f 142void manager_gc(Manager *m, bool drop_not_started);
14c3baca 143
405e0255
LP
144bool manager_shall_kill(Manager *m, const char *user);
145
a185c5aa
LP
146int manager_get_idle_hint(Manager *m, dual_timestamp *t);
147
9444b1f2 148int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
9b221b63
LP
149int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
150
cc377381 151extern const sd_bus_vtable manager_vtable[];
3f49d45a 152
ebcf1f97
LP
153int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
154int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
155int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
156int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
157int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
1713813d 158
cc377381 159int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
069cfc85 160
cc377381 161int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
9418f147 162
d889a206 163int manager_dispatch_delayed(Manager *manager);
eecd1362 164
cc377381
LP
165int 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);
166int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
167int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
168int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
fb6becb4 169int manager_unit_is_active(Manager *manager, const char *unit);
cc377381 170int manager_job_is_active(Manager *manager, const char *path);
fb6becb4 171
f975e971
LP
172/* gperf lookup function */
173const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length);
e8b212fe
DH
174
175int manager_watch_busname(Manager *manager, const char *name);
176void manager_drop_busname(Manager *manager, const char *name);