unit.h revision b2dc4e44c540a30c5ea12a9a570425ceb310c320
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright 2010 Lennart Poettering
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersentypedef struct UnitStatusMessageFormats UnitStatusMessageFormats;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersenstatic inline bool UNIT_IS_ACTIVE_OR_RELOADING(UnitActiveState t) {
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen return t == UNIT_ACTIVE || t == UNIT_RELOADING;
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenstatic inline bool UNIT_IS_ACTIVE_OR_ACTIVATING(UnitActiveState t) {
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen return t == UNIT_ACTIVE || t == UNIT_ACTIVATING || t == UNIT_RELOADING;
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersenstatic inline bool UNIT_IS_INACTIVE_OR_DEACTIVATING(UnitActiveState t) {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_DEACTIVATING;
be077570f779664ed87b50f60608df9fbe258821Tom Gundersenstatic inline bool UNIT_IS_INACTIVE_OR_FAILED(UnitActiveState t) {
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen return t == UNIT_INACTIVE || t == UNIT_FAILED;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen /* Keeps tracks of references to a unit. This is useful so
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen * that we can merge two units if necessary and correct all
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen * references to them */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen char *id; /* One name is special because we use it for identification. Points to an entry in the names set */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen char *fragment_path; /* if loaded from a config file this is the primary path to it */
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen char *source_path; /* if converted, the source file */
4dc355680460fdc8e0d590d8572dff1b6a257d88Tom Gundersen /* If there is something to do with this unit, then this is the installed job for it */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* JOB_NOP jobs are special and can be installed without disturbing the real job. */
4dc355680460fdc8e0d590d8572dff1b6a257d88Tom Gundersen /* Job timeout and action to take */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* References to this */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* Conditions to check */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* Per type list */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen /* All units which have requires_mounts_for set */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen /* Load queue */
bd57b45029ff25067704c9538e79f31e71c10045Tom Gundersen /* D-Bus queue */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen /* Cleanup queue */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen /* GC queue */
bd57b45029ff25067704c9538e79f31e71c10045Tom Gundersen /* CGroup realize members queue */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* PIDs we keep an eye on. Note that a unit might have many
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen * more, but these are the ones we care enough about to
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen * process SIGCHLD for */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* Used during GC sweeps */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* When deserializing, temporarily store the job type for this
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen * unit here, if there was a job scheduled.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen * Only for deserializing from a legacy version. New style uses full
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen * serialized jobs. */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen int deserialized_job; /* This is actually of type JobType */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* Error code when we didn't manage to load the unit (negative) */
char *cgroup_path;
bool stop_when_unneeded;
bool default_dependencies;
bool refuse_manual_start;
/* Don't allow the user to stop this unit manually, allow stopping only indirectly via dependency. */
bool refuse_manual_stop;
bool allow_isolate;
bool ignore_on_isolate;
bool ignore_on_snapshot;
bool condition_result;
bool assert_result;
bool transient;
struct UnitStatusMessageFormats {
typedef enum UnitSetPropertiesMode {
UNIT_CHECK = 0,
#include "service.h"
#include "socket.h"
#include "busname.h"
#include "target.h"
#include "snapshot.h"
#include "device.h"
#include "mount.h"
#include "automount.h"
#include "swap.h"
#include "timer.h"
#include "path.h"
#include "slice.h"
#include "scope.h"
struct UnitVTable {
const char *private_section;
const char *sections;
void (*bus_name_owner_change)(Unit *u, const char *name, const char *old_owner, const char *new_owner);
int (*bus_set_property)(Unit *u, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error);
const char *bus_interface;
return NULL; \
return (MixedCase*) u; \
int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference);
int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference);
int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference);
int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t control_pid, sd_bus_error *error);
int set_unit_path(const char *p);
void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *value, ...) _printf_(4,5);
void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) _printf_(3, 0);
int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) _printf_(4,5);
int unit_write_drop_in_private(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data);
int unit_write_drop_in_private_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) _printf_(4,5);
int unit_kill_context(Unit *u, KillContext *c, KillOperation k, pid_t main_pid, pid_t control_pid, bool main_pid_alien);
#define log_unit_full_errno(unit, level, error, ...) log_object_internal(level, error, __FILE__, __LINE__, __func__, getpid() == 1 ? "UNIT=" : "USER_UNIT=", unit, __VA_ARGS__)
#define log_unit_debug_errno(unit, error, ...) log_unit_full_errno(unit, LOG_DEBUG, error, __VA_ARGS__)
#define log_unit_info_errno(unit, error, ...) log_unit_full_errno(unit, LOG_INFO, error, __VA_ARGS__)
#define log_unit_notice_errno(unit, error, ...) log_unit_full_errno(unit, LOG_NOTICE, error, __VA_ARGS__)
#define log_unit_warning_errno(unit, error, ...) log_unit_full_errno(unit, LOG_WARNING, error, __VA_ARGS__)
#define log_unit_error_errno(unit, error, ...) log_unit_full_errno(unit, LOG_ERR, error, __VA_ARGS__)
#define log_unit_struct(unit, level, ...) log_struct(level, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__)
#define log_unit_struct_errno(unit, level, error, ...) log_struct_errno(level, error, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__)