X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Funit.h;h=756f465da339fe7310044da24d712ed4dbcb00c5;hp=b32c1a702e241dca527ebed1590d22a207c0ed00;hb=bb242b7b5277f5db4a01be905f26eccd382ff1e0;hpb=dc1ecd78e9f046880d10ddb45cf9b06df1084b10 diff --git a/src/unit.h b/src/unit.h index b32c1a702..756f465da 100644 --- a/src/unit.h +++ b/src/unit.h @@ -25,13 +25,13 @@ #include #include -typedef union Unit Unit; -typedef struct Meta Meta; +typedef struct Unit Unit; typedef struct UnitVTable UnitVTable; typedef enum UnitType UnitType; typedef enum UnitLoadState UnitLoadState; typedef enum UnitActiveState UnitActiveState; typedef enum UnitDependency UnitDependency; +typedef struct UnitRef UnitRef; #include "set.h" #include "util.h" @@ -119,6 +119,14 @@ enum UnitDependency { /* On Failure */ UNIT_ON_FAILURE, + /* Triggers (i.e. a socket triggers a service) */ + UNIT_TRIGGERS, + UNIT_TRIGGERED_BY, + + /* Propagate reloads */ + UNIT_PROPAGATE_RELOAD_TO, + UNIT_PROPAGATE_RELOAD_FROM, + /* Reference information for GC logic */ UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */ UNIT_REFERENCED_BY, @@ -132,7 +140,7 @@ enum UnitDependency { #include "cgroup.h" #include "cgroup-attr.h" -struct Meta { +struct Unit { Manager *manager; UnitType type; @@ -156,6 +164,9 @@ struct Meta { usec_t job_timeout; + /* References to this */ + LIST_HEAD(UnitRef, refs); + /* Conditions to check */ LIST_HEAD(Condition, conditions); @@ -171,19 +182,19 @@ struct Meta { CGroupAttribute *cgroup_attributes; /* Per type list */ - LIST_FIELDS(Meta, units_by_type); + LIST_FIELDS(Unit, units_by_type); /* Load queue */ - LIST_FIELDS(Meta, load_queue); + LIST_FIELDS(Unit, load_queue); /* D-Bus queue */ - LIST_FIELDS(Meta, dbus_queue); + LIST_FIELDS(Unit, dbus_queue); /* Cleanup queue */ - LIST_FIELDS(Meta, cleanup_queue); + LIST_FIELDS(Unit, cleanup_queue); /* GC queue */ - LIST_FIELDS(Meta, gc_queue); + LIST_FIELDS(Unit, gc_queue); /* Used during GC sweeps */ unsigned gc_marker; @@ -237,6 +248,15 @@ struct Meta { bool in_audit:1; }; +struct UnitRef { + /* Keeps tracks of references to a unit. This is useful so + * that we can merge two units if necessary and correct all + * references to them */ + + Unit* unit; + LIST_FIELDS(UnitRef, refs); +}; + #include "service.h" #include "timer.h" #include "socket.h" @@ -248,23 +268,12 @@ struct Meta { #include "swap.h" #include "path.h" -union Unit { - Meta meta; - Service service; - Timer timer; - Socket socket; - Target target; - Device device; - Mount mount; - Automount automount; - Snapshot snapshot; - Swap swap; - Path path; -}; - struct UnitVTable { const char *suffix; + /* How much memory does an object of this unit type need */ + size_t object_size; + /* Config file sections this unit type understands, separated * by NUL chars */ const char *sections; @@ -389,19 +398,19 @@ struct UnitVTable { extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX]; -#define UNIT_VTABLE(u) unit_vtable[(u)->meta.type] +#define UNIT_VTABLE(u) unit_vtable[(u)->type] /* For casting a unit into the various unit types */ #define DEFINE_CAST(UPPERCASE, MixedCase) \ static inline MixedCase* UPPERCASE(Unit *u) { \ - if (_unlikely_(!u || u->meta.type != UNIT_##UPPERCASE)) \ + if (_unlikely_(!u || u->type != UNIT_##UPPERCASE)) \ return NULL; \ \ return (MixedCase*) u; \ } /* For casting the various unit types into a unit */ -#define UNIT(u) ((Unit*) (&(u)->meta)) +#define UNIT(u) (&(u)->meta) DEFINE_CAST(SOCKET, Socket); DEFINE_CAST(TIMER, Timer); @@ -414,7 +423,7 @@ DEFINE_CAST(SNAPSHOT, Snapshot); DEFINE_CAST(SWAP, Swap); DEFINE_CAST(PATH, Path); -Unit *unit_new(Manager *m); +Unit *unit_new(Manager *m, size_t size); void unit_free(Unit *u); int unit_add_name(Unit *u, const char *name); @@ -536,6 +545,11 @@ bool unit_condition_test(Unit *u); UnitFileState unit_get_unit_file_state(Unit *u); +Unit* unit_ref_set(UnitRef *ref, Unit *u); +void unit_ref_unset(UnitRef *ref); + +#define UNIT_DEREF(ref) ((ref).unit) + const char *unit_load_state_to_string(UnitLoadState i); UnitLoadState unit_load_state_from_string(const char *s);