unit.h revision 0a9f8ed00c8f323d5bf24a9a11149a9342c0e1aa
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#ifndef foounithfoo
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define foounithfoo
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/***
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen This file is part of systemd.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen Copyright 2010 Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen systemd is free software; you can redistribute it and/or modify it
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen under the terms of the GNU Lesser General Public License as published by
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen (at your option) any later version.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen systemd is distributed in the hope that it will be useful, but
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen Lesser General Public License for more details.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen You should have received a copy of the GNU Lesser General Public License
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen***/
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdbool.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdlib.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersentypedef struct Unit Unit;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct UnitVTable UnitVTable;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersentypedef enum UnitType UnitType;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersentypedef enum UnitLoadState UnitLoadState;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersentypedef enum UnitActiveState UnitActiveState;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersentypedef enum UnitDependency UnitDependency;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct UnitRef UnitRef;
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poetteringtypedef struct UnitStatusMessageFormats UnitStatusMessageFormats;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering#include "set.h"
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering#include "util.h"
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering#include "list.h"
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering#include "socket-util.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "execute.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "condition.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "install.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "unit-name.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringenum UnitLoadState {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_STUB,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_LOADED,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_ERROR,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_MERGED,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_MASKED,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_LOAD_STATE_MAX,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_LOAD_STATE_INVALID = -1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringenum UnitActiveState {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_ACTIVE,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_RELOADING,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_INACTIVE,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_FAILED,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_ACTIVATING,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_DEACTIVATING,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_ACTIVE_STATE_MAX,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_ACTIVE_STATE_INVALID = -1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poetteringstatic inline bool UNIT_IS_ACTIVE_OR_RELOADING(UnitActiveState t) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return t == UNIT_ACTIVE || t == UNIT_RELOADING;
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic inline bool UNIT_IS_ACTIVE_OR_ACTIVATING(UnitActiveState t) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return t == UNIT_ACTIVE || t == UNIT_ACTIVATING || t == UNIT_RELOADING;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic inline bool UNIT_IS_INACTIVE_OR_DEACTIVATING(UnitActiveState t) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_DEACTIVATING;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poetteringstatic inline bool UNIT_IS_INACTIVE_OR_FAILED(UnitActiveState t) {
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering return t == UNIT_INACTIVE || t == UNIT_FAILED;
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poetteringenum UnitDependency {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Positive dependencies */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REQUIRES,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REQUIRES_OVERRIDABLE,
a2a416f768e2aa7db5b975cd50eb19237cac9cceLennart Poettering UNIT_REQUISITE,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REQUISITE_OVERRIDABLE,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_WANTS,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_BIND_TO,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Inverse of the above */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REQUIRED_BY_OVERRIDABLE, /* inverse of 'requires_overridable' and 'requisite_overridable' is 'soft_required_by' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_WANTED_BY, /* inverse of 'wants' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_BOUND_BY, /* inverse of 'bind_to' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Negative dependencies */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_CONFLICTED_BY,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Order */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_AFTER,
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* On Failure */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_ON_FAILURE,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Triggers (i.e. a socket triggers a service) */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_TRIGGERS,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_TRIGGERED_BY,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Propagate reloads */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_PROPAGATE_RELOAD_TO,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_PROPAGATE_RELOAD_FROM,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Reference information for GC logic */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UNIT_REFERENCED_BY,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_DEPENDENCY_MAX,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _UNIT_DEPENDENCY_INVALID = -1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "manager.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "job.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "cgroup.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "cgroup-attr.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct Unit {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Manager *manager;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UnitType type;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UnitLoadState load_state;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Unit *merged_into;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *id; /* One name is special because we use it for identification. Points to an entry in the names set */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *instance;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Set *names;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Set *dependencies[_UNIT_DEPENDENCY_MAX];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char **requires_mounts_for;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *description;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char **documentation;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *fragment_path; /* if loaded from a config file this is the primary path to it */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *source_path; /* if converted, the source file */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering usec_t fragment_mtime;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering usec_t source_mtime;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* If there is something to do with this unit, then this is the installed job for it */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Job *job;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* JOB_NOP jobs are special and can be installed without disturbing the real job. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Job *nop_job;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering usec_t job_timeout;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* References to this */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_HEAD(UnitRef, refs);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Conditions to check */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_HEAD(Condition, conditions);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp condition_timestamp;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp inactive_exit_timestamp;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp active_enter_timestamp;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp active_exit_timestamp;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering dual_timestamp inactive_enter_timestamp;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Counterparts in the cgroup filesystem */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering CGroupBonding *cgroup_bondings;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering CGroupAttribute *cgroup_attributes;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Per type list */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, units_by_type);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* All units which have requires_mounts_for set */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, has_requires_mounts_for);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Load queue */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, load_queue);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* D-Bus queue */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, dbus_queue);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Cleanup queue */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, cleanup_queue);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* GC queue */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(Unit, gc_queue);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Used during GC sweeps */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned gc_marker;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* When deserializing, temporarily store the job type for this
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * unit here, if there was a job scheduled.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Only for deserializing from a legacy version. New style uses full
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * serialized jobs. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int deserialized_job; /* This is actually of type JobType */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Error code when we didn't manage to load the unit (negative) */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int load_error;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Cached unit file state */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering UnitFileState unit_file_state;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Garbage collect us we nobody wants or requires us anymore */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool stop_when_unneeded;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen /* Create default dependencies */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool default_dependencies;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Refuse manual starting, allow starting only indirectly via dependency. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool refuse_manual_start;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Don't allow the user to stop this unit manually, allow stopping only indirectly via dependency. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool refuse_manual_stop;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Allow isolation requests */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool allow_isolate;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Isolate OnFailure unit */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool on_failure_isolate;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Ignore this unit when isolating */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool ignore_on_isolate;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Ignore this unit when snapshotting */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool ignore_on_snapshot;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Did the last condition check suceed? */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool condition_result;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool in_load_queue:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool in_dbus_queue:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool in_cleanup_queue:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool in_gc_queue:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool sent_dbus_new_signal:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool no_gc:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool in_audit:1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct UnitRef {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Keeps tracks of references to a unit. This is useful so
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * that we can merge two units if necessary and correct all
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * references to them */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Unit* unit;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIELDS(UnitRef, refs);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct UnitStatusMessageFormats {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *starting_stopping[2];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *finished_start_job[_JOB_RESULT_MAX];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *finished_stop_job[_JOB_RESULT_MAX];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "service.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "timer.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "socket.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "target.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "device.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "mount.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "automount.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "snapshot.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "swap.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "path.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct UnitVTable {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *suffix;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* How much memory does an object of this unit type need */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering size_t object_size;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Config file sections this unit type understands, separated
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * by NUL chars */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *sections;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* This should reset all type-specific variables. This should
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * not allocate memory, and is called with zero-initialized
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * data. It should hence only initialize variables that need
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * to be set != 0. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering void (*init)(Unit *u);
0014a4ad505d119c7ac4346d9d774c3f17f663a5Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* This should free all type-specific variables. It should be
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * idempotent. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering void (*done)(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Actually load data from disk. This may fail, and should set
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * load_state to UNIT_LOADED, UNIT_MERGED or leave it at
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * UNIT_STUB if no configuration could be found. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*load)(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* If a a lot of units got created via enumerate(), this is
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * where to actually set the state and call unit_notify(). */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*coldplug)(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering void (*dump)(Unit *u, FILE *f, const char *prefix);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*start)(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*stop)(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering int (*reload)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int (*kill)(Unit *u, KillWho w, KillMode m, int signo, DBusError *error);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool (*can_reload)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Write all data that cannot be restored from other sources
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * away using unit_serialize_item() */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int (*serialize)(Unit *u, FILE *f, FDSet *fds);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Restore one item from the serialization */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int (*deserialize_item)(Unit *u, const char *key, const char *data, FDSet *fds);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Boils down the more complex internal state of this unit to
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * a simpler one that the engine can understand */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering UnitActiveState (*active_state)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Returns the substate specific to this unit type as
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * string. This is purely information so that we can give the
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * user a more fine grained explanation in which actual state a
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * unit is in. */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering const char* (*sub_state_to_string)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Return true when there is reason to keep this entry around
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * even nothing references it and it isn't active in any
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * way */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool (*check_gc)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Return true when this unit is suitable for snapshotting */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool (*check_snapshot)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*fd_event)(Unit *u, int fd, uint32_t events, Watch *w);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*timer_event)(Unit *u, uint64_t n_elapsed, Watch *w);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Reset failed state if we are in failed state */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*reset_failed)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Called whenever any of the cgroups this unit watches for
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * ran empty */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*cgroup_notify_empty)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Called whenever a process of this unit sends us a message */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*notify_message)(Unit *u, pid_t pid, char **tags);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Called whenever a name thus Unit registered for comes or
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * goes away. */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*bus_name_owner_change)(Unit *u, const char *name, const char *old_owner, const char *new_owner);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Called whenever a bus PID lookup finishes */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*bus_query_pid_done)(Unit *u, const char *name, pid_t pid);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Called for each message received on the bus */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering DBusHandlerResult (*bus_message_handler)(Unit *u, DBusConnection *c, DBusMessage *message);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Return the unit this unit is following */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering Unit *(*following)(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Return the set of units that are following each other */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int (*following_set)(Unit *u, Set **s);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* This is called for each unit type and should be used to
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * enumerate existing devices and load them. However,
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * everything that is loaded here should still stay in
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * inactive state. It is the job of the coldplug() call above
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * to put the units into the initial state. */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering int (*enumerate)(Manager *m);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Type specific cleanups. */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering void (*shutdown)(Manager *m);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* When sending out PropertiesChanged signal, which properties
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * shall be invalidated? This is a NUL separated list of
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering * strings, to minimize relocations a little. */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering const char *bus_invalidating_properties;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* The interface name */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering const char *bus_interface;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering UnitStatusMessageFormats status_message_formats;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Can units of this type have multiple names? */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool no_alias:1;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering /* Instances make no sense for this type */
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering bool no_instances:1;
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen /* Exclude from automatic gc */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering bool no_gc:1;
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen};
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
c92e531c82a9815ec349aa1bf31236b86b2d5311Lennart Poetteringextern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX];
c92e531c82a9815ec349aa1bf31236b86b2d5311Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define UNIT_VTABLE(u) unit_vtable[(u)->type]
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/* For casting a unit into the various unit types */
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define DEFINE_CAST(UPPERCASE, MixedCase) \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering static inline MixedCase* UPPERCASE(Unit *u) { \
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (_unlikely_(!u || u->type != UNIT_##UPPERCASE)) \
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return NULL; \
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering \
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return (MixedCase*) u; \
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering }
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering/* For casting the various unit types into a unit */
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define UNIT(u) (&(u)->meta)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(SOCKET, Socket);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(TIMER, Timer);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(SERVICE, Service);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(TARGET, Target);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(DEVICE, Device);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(MOUNT, Mount);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(AUTOMOUNT, Automount);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(SNAPSHOT, Snapshot);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(SWAP, Swap);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenDEFINE_CAST(PATH, Path);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart PoetteringUnit *unit_new(Manager *m, size_t size);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poetteringvoid unit_free(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringint unit_add_name(Unit *u, const char *name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_exec_dependencies(Unit *u, ExecContext *c);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_cgroup(Unit *u, CGroupBonding *b);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_cgroup_from_text(Unit *u, const char *name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_add_default_cgroups(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart PoetteringCGroupBonding* unit_get_default_cgroup(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint unit_add_cgroup_attribute(Unit *u, const char *controller, const char *name, const char *value, CGroupAttributeMapCallback map_callback);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint unit_choose_id(Unit *u, const char *name);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint unit_set_description(Unit *u, const char *description);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringbool unit_check_gc(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringvoid unit_add_to_load_queue(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringvoid unit_add_to_dbus_queue(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringvoid unit_add_to_cleanup_queue(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringvoid unit_add_to_gc_queue(Unit *u);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_merge(Unit *u, Unit *other);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_merge_by_name(Unit *u, const char *other);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnit *unit_follow_merge(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_load_fragment_and_dropin(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_load_fragment_and_dropin_optional(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_load(Unit *unit);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenconst char *unit_description(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringbool unit_has_name(Unit *u, const char *name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringUnitActiveState unit_active_state(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poetteringconst char* unit_sub_state_to_string(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_dump(Unit *u, FILE *f, const char *prefix);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringbool unit_can_reload(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringbool unit_can_start(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringbool unit_can_isolate(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_start(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_stop(Unit *u);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poetteringint unit_reload(Unit *u);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error);
096b6773886bd7a0c8c97aa684b0b67dfae58355Lennart Poettering
096b6773886bd7a0c8c97aa684b0b67dfae58355Lennart Poetteringvoid unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_watch_fd(Unit *u, int fd, uint32_t events, Watch *w);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_unwatch_fd(Unit *u, Watch *w);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_watch_pid(Unit *u, pid_t pid);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_unwatch_pid(Unit *u, pid_t pid);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringint unit_watch_timer(Unit *u, usec_t delay, Watch *w);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringvoid unit_unwatch_timer(Unit *u, Watch *w);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringint unit_watch_bus_name(Unit *u, const char *name);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringvoid unit_unwatch_bus_name(Unit *u, const char *name);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringbool unit_job_is_applicable(Unit *u, JobType j);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint set_unit_path(const char *p);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringchar *unit_dbus_path(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_load_related_unit(Unit *u, const char *type, Unit **_found);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint unit_get_related_unit(Unit *u, const char *type, Unit **_found);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringchar *unit_name_printf(Unit *u, const char* text);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poetteringchar *unit_full_printf(Unit *u, const char *text);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poetteringchar **unit_full_printf_strv(Unit *u, char **l);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringbool unit_can_serialize(Unit *u);
eb60f9cd4e93ff5016dc1b5486fd1b7e1565fd92Lennart Poetteringint unit_serialize(Unit *u, FILE *f, FDSet *fds);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenvoid unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *value, ...) _printf_attr_(4,5);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_deserialize(Unit *u, FILE *f, FDSet *fds);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_add_node_link(Unit *u, const char *what, bool wants);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint unit_coldplug(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenvoid unit_status_printf(Unit *u, const char *status, const char *format, ...);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenbool unit_need_daemon_reload(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenvoid unit_reset_failed(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart PoetteringUnit *unit_following(Unit *u);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenbool unit_pending_inactive(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenbool unit_pending_active(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_add_default_target_dependency(Unit *u, Unit *target);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_following_set(Unit *u, Set **s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnitType unit_name_to_type(const char *n);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenbool unit_name_is_valid(const char *n, bool template_ok);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_trigger_on_failure(Unit *u);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenbool unit_condition_test(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnitFileState unit_get_unit_file_state(Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringUnit* unit_ref_set(UnitRef *ref, Unit *u);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringvoid unit_ref_unset(UnitRef *ref);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#define UNIT_DEREF(ref) ((ref).unit)
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenint unit_add_one_mount_link(Unit *u, Mount *m);
b686acb27ea4de042320fa196cfb14e08f30165bTom Gundersenint unit_add_mount_links(Unit *u);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenconst char *unit_load_state_to_string(UnitLoadState i);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnitLoadState unit_load_state_from_string(const char *s);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenconst char *unit_active_state_to_string(UnitActiveState i);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnitActiveState unit_active_state_from_string(const char *s);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersenconst char *unit_dependency_to_string(UnitDependency i);
091a364c802e34a58f3260c9cb5db9b75c62215cTom GundersenUnitDependency unit_dependency_from_string(const char *s);
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen#endif
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering