manager.h revision e46b13c8c7f48f81d4e09912f2265daaa7f6d27e
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#pragma once
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/***
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering This file is part of systemd.
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Copyright 2010 Lennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is free software; you can redistribute it and/or modify it
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering under the terms of the GNU Lesser General Public License as published by
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (at your option) any later version.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is distributed in the hope that it will be useful, but
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Lesser General Public License for more details.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering You should have received a copy of the GNU Lesser General Public License
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering***/
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include <stdbool.h>
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include <inttypes.h>
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include <stdio.h>
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sd-bus.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sd-event.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "fdset.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "cgroup-util.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers/* Enforce upper limit how many names we allow */
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers#define MANAGER_MAX_NAMES 131072 /* 128K */
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieverstypedef struct Manager Manager;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringtypedef enum ManagerState {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_INITIALIZING,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_STARTING,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_RUNNING,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_DEGRADED,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_MAINTENANCE,
0affed79d2e30013f07cb94e6f07e3fcb81c02faLennart Poettering MANAGER_STOPPING,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _MANAGER_STATE_MAX,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _MANAGER_STATE_INVALID = -1
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering} ManagerState;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallacetypedef enum ManagerExitCode {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_OK,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_EXIT,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_RELOAD,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_REEXECUTE,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_REBOOT,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_POWEROFF,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_HALT,
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyer MANAGER_KEXEC,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MANAGER_SWITCH_ROOT,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _MANAGER_EXIT_CODE_MAX,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _MANAGER_EXIT_CODE_INVALID = -1
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering} ManagerExitCode;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "unit.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "job.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "hashmap.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "list.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "set.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "path-lookup.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "execute.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "unit-name.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "exit-status.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "show-status.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "failure-action.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstruct Manager {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Note that the set of units we know of is allowed to be
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * inconsistent. However the subset of it that is loaded may
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * not, and the list of jobs may neither. */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Active jobs and units */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *units; /* name string => Unit object n:1 */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *jobs; /* job id => Job object 1:1 */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* To make it easy to iterate through the units of a specific
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * type we maintain a per type linked list */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Units that need to be loaded */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Jobs that need to be run */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Units and jobs that have not yet been announced via
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * D-Bus. When something about a job changes it is added here
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * if it is not in there yet. This allows easy coalescing of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * D-Bus change signals. */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Unit, dbus_unit_queue);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Job, dbus_job_queue);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Units to remove */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(Unit, cleanup_queue);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Units to check when doing GC */
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers LIST_HEAD(Unit, gc_queue);
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers /* Units that should be realized */
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers LIST_HEAD(Unit, cgroup_queue);
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers sd_event *event;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers /* We use two hash tables here, since the same PID might be
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers * watched by two different units: once the unit that forked
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers * it off, and possibly a different unit to which it was
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers * joined as cgroup member. Since we know that it is either
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers * one or two units for each PID we just use to hashmaps
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers * here. */
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers Hashmap *watch_pids1; /* pid => Unit object n:1 */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *watch_pids2; /* pid => Unit object n:1 */
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* A set contains all units which cgroup should be refreshed after startup */
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers Set *startup_units;
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers /* A set which contains all currently failed units */
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers Set *failed_units;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers sd_event_source *run_queue_event_source;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char *notify_socket;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int notify_fd;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers sd_event_source *notify_event_source;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int signal_fd;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers sd_event_source *signal_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int time_change_fd;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers sd_event_source *time_change_event_source;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers sd_event_source *jobs_in_progress_event_source;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_snapshots;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LookupPaths lookup_paths;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Set *unit_path_cache;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char **environment;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers usec_t runtime_watchdog;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering usec_t shutdown_watchdog;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering dual_timestamp firmware_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp loader_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp kernel_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp initrd_timestamp;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering dual_timestamp userspace_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp finish_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp security_start_timestamp;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering dual_timestamp security_finish_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp generators_start_timestamp;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering dual_timestamp generators_finish_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers dual_timestamp units_load_start_timestamp;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering dual_timestamp units_load_finish_timestamp;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers char *generator_unit_path;
e1636421f46db6d06fbd028ef20a3113fa3e11f8Lennart Poettering char *generator_unit_path_early;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers char *generator_unit_path_late;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering struct udev* udev;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the device subsystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering struct udev_monitor* udev_monitor;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna sd_event_source *udev_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *devices_by_sysfs;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the mount subsystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering FILE *proc_self_mountinfo;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *mount_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the swap filesystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering FILE *proc_swaps;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *swap_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *swaps_by_devnode;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the D-Bus subsystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_bus *api_bus, *system_bus;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Set *private_buses;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int private_listen_fd;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *private_listen_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Contains all the clients that are subscribed to signals via
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the API bus. Note that private bus connections are always
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering considered subscribes, since they last for very short only,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering and it is much simpler that way. */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_bus_track *subscribed;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char **deserialized_subscribed;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_bus_message *queued_message; /* This is used during reloading:
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * before the reload we queue the
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * reply message here, and
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * afterwards we send it */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_bus *queued_message_bus; /* The connection to send the queued message on */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool send_reloading_done;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering uint32_t current_job_id;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering uint32_t default_unit_job_id;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the Automount subsystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int dev_autofs_fd;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Data specific to the cgroup subsystem */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *cgroup_unit;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering CGroupControllerMask cgroup_supported;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char *cgroup_root;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna int gc_marker;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_in_gc_queue;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Make sure the user cannot accidentally unmount our cgroup
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * file system */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int pin_cgroupfs_fd;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Flags */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering SystemdRunningAs running_as;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ManagerExitCode exit_code:5;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool dispatching_load_queue:1;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool dispatching_dbus_queue:1;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool taint_usr:1;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool first_boot:1;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool test_run:1;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ShowStatus show_status;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool confirm_spawn;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool no_console_output;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering ExecOutput default_std_output, default_std_error;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering usec_t default_restart_usec, default_timeout_start_usec, default_timeout_stop_usec;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering usec_t default_start_limit_interval;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned default_start_limit_burst;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool default_cpu_accounting;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool default_memory_accounting;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering bool default_blockio_accounting;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering usec_t default_timer_accuracy_usec;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering struct rlimit *rlimit[_RLIMIT_MAX];
2f7a4867babd3fd382e5495f21724358f30fa67dMichal Sekletar
2f7a4867babd3fd382e5495f21724358f30fa67dMichal Sekletar /* non-zero if we are reloading or reexecuting, */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int n_reloading;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_installed_jobs;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_failed_jobs;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Jobs in progress watching */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_running_jobs;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_on_console;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned jobs_in_progress_iteration;
0affed79d2e30013f07cb94e6f07e3fcb81c02faLennart Poettering
0affed79d2e30013f07cb94e6f07e3fcb81c02faLennart Poettering /* Do we have any outstanding password prompts? */
0affed79d2e30013f07cb94e6f07e3fcb81c02faLennart Poettering int have_ask_password;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int ask_password_inotify_fd;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *ask_password_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Type=idle pipes */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int idle_pipe[4];
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *idle_pipe_event_source;
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmek
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char *switch_root;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering char *switch_root_init;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* This maps all possible path prefixes to the units needing
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * them. It's a hashmap with a path string as key and a Set as
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering * value where Unit objects are contained. */
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna Hashmap *units_requiring_mounts_for;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna /* Reference to the kdbus bus control fd */
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna int kdbus_fd;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna /* Used for processing polkit authorization responses */
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna Hashmap *polkit_registry;
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna};
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_new(SystemdRunningAs running_as, bool test_run, Manager **m);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyervoid manager_free(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_enumerate(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_startup(Manager *m, FILE *serialization, FDSet *fds);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni CampagnaJob *manager_get_job(Manager *m, uint32_t id);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni CampagnaUnit *manager_get_unit(Manager *m, const char *name);
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_get_unit_by_path(Manager *m, const char *path, const char *suffix, Unit **_found);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_load_unit_prepare(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_load_unit(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **_ret);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e, Unit **_u);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, sd_bus_error *e, Job **_ret);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, sd_bus_error *e, Job **_ret);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_dump_units(Manager *s, FILE *f, const char *prefix);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmek
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_clear_jobs(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmekunsigned manager_dispatch_load_queue(Manager *m);
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmek
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmekint manager_environment_add(Manager *m, char **minus, char **plus);
ef42202ac8ed27e7ff1fc90ef8bc2590046dff25Zbigniew Jędrzejewski-Szmekint manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_loop(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_dispatch_bus_name_owner_changed(Manager *m, const char *name, const char* old_owner, const char *new_owner);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
8333c77edf8fd1654cd96f3f6ee0f078dd64b58bZbigniew Jędrzejewski-Szmekint manager_open_serialization(Manager *m, FILE **_f);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekint manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnaint manager_deserialize(Manager *m, FILE *f, FDSet *fds);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekint manager_reload(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnabool manager_is_reloading_or_reexecuting(Manager *m) _pure_;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_reset_failed(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_send_unit_plymouth(Manager *m, Unit *u);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnabool manager_unit_inactive_or_pending(Manager *m, const char *name);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_check_finished(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_run_generators(Manager *m);
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_undo_generators(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_recheck_journal(Manager *m);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagna
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_set_show_status(Manager *m, ShowStatus mode);
17d33cecaa762f7e43200307328af5e9135e2091Giovanni Campagnavoid manager_set_first_boot(Manager *m, bool b);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) _printf_(4,5);
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekvoid manager_flip_auto_status(Manager *m, bool enable);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringSet *manager_get_units_requiring_mounts_for(Manager *m, const char *path);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringconst char *manager_get_runtime_prefix(Manager *m);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
7c2d80944afb4196f2eff614e8da1450dffcbeaaThomas Hindoe Paaboel AndersenManagerState manager_state(Manager *m);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
bac3c8eefe23a820caac930d41629cebafbfc7b2Zbigniew Jędrzejewski-Szmekconst char *manager_state_to_string(ManagerState m) _const_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringManagerState manager_state_from_string(const char *s) _pure_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering