1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <errno.h>
5 
6 #include "unit-def.h"
7 
8 /* Flags that identify the various "atomic" behaviours a specific dependency type implies. Each dependency is
9  * a combination of one or more of these flags that define what they actually entail. */
10 typedef enum UnitDependencyAtom {
11 
12         /* This unit pulls in the other unit as JOB_START job into the transaction, and if that doesn't work
13          * the transaction fails. */
14         UNIT_ATOM_PULL_IN_START                       = UINT64_C(1) << 0,
15         /* Similar, but if it doesn't work, ignore. */
16         UNIT_ATOM_PULL_IN_START_IGNORED               = UINT64_C(1) << 1,
17         /* Pull in a JOB_VERIFY job into the transaction, i.e. pull in JOB_VERIFY rather than
18          * JOB_START. i.e. check the unit is started but don't pull it in. */
19         UNIT_ATOM_PULL_IN_VERIFY                      = UINT64_C(1) << 2,
20 
21         /* Pull in a JOB_STOP job for the other job into transactions, and fail if that doesn't work. */
22         UNIT_ATOM_PULL_IN_STOP                        = UINT64_C(1) << 3,
23         /* Same, but don't fail, ignore it. */
24         UNIT_ATOM_PULL_IN_STOP_IGNORED                = UINT64_C(1) << 4,
25 
26         /* If our enters inactive state, add the other unit to the StopWhenUneeded= queue */
27         UNIT_ATOM_ADD_STOP_WHEN_UNNEEDED_QUEUE        = UINT64_C(1) << 5,
28         /* Pin the other unit i.e. ensure StopWhenUneeded= won't trigger for the other unit as long as we are
29          * not in inactive state */
30         UNIT_ATOM_PINS_STOP_WHEN_UNNEEDED             = UINT64_C(1) << 6,
31 
32         /* Stop our unit if the other unit happens to inactive */
33         UNIT_ATOM_CANNOT_BE_ACTIVE_WITHOUT            = UINT64_C(1) << 7,
34         /* If our unit enters inactive state, add the other unit to the BoundBy= queue */
35         UNIT_ATOM_ADD_CANNOT_BE_ACTIVE_WITHOUT_QUEUE  = UINT64_C(1) << 8,
36 
37         /* Start this unit whenever we find it inactive and the other unit active */
38         UNIT_ATOM_START_STEADILY                      = UINT64_C(1) << 9,
39         /* Whenever our unit becomes active, add other unit to start_when_upheld_queue */
40         UNIT_ATOM_ADD_START_WHEN_UPHELD_QUEUE         = UINT64_C(1) << 10,
41 
42         /* If our unit unexpectedly becomes active, retroactively start the other unit too, in "replace" job
43          * mode */
44         UNIT_ATOM_RETROACTIVE_START_REPLACE           = UINT64_C(1) << 11,
45         /* Similar, but in "fail" job mode */
46         UNIT_ATOM_RETROACTIVE_START_FAIL              = UINT64_C(1) << 12,
47         /* If our unit unexpectedly becomes active, retroactively stop the other unit too */
48         UNIT_ATOM_RETROACTIVE_STOP_ON_START           = UINT64_C(1) << 13,
49         /* If our unit unexpectedly becomes inactive, retroactively stop the other unit too */
50         UNIT_ATOM_RETROACTIVE_STOP_ON_STOP            = UINT64_C(1) << 14,
51 
52         /* If a start job for this unit fails, propagate the failure to start job of other unit too */
53         UNIT_ATOM_PROPAGATE_START_FAILURE             = UINT64_C(1) << 15,
54         /* If a stop job for this unit fails, propagate the failure to any stop job of the other unit too */
55         UNIT_ATOM_PROPAGATE_STOP_FAILURE              = UINT64_C(1) << 16,
56         /* If our start job succeeded but the unit is inactive then (think: oneshot units), propagate this as
57          * failure to the other unit. */
58         UNIT_ATOM_PROPAGATE_INACTIVE_START_AS_FAILURE = UINT64_C(1) << 17,
59         /* When putting together a transaction, propagate JOB_STOP from our unit to the other. */
60         UNIT_ATOM_PROPAGATE_STOP                      = UINT64_C(1) << 18,
61         /* When putting together a transaction, propagate JOB_RESTART from our unit to the other. */
62         UNIT_ATOM_PROPAGATE_RESTART                   = UINT64_C(1) << 19,
63 
64         /* Add the other unit to the default target dependency queue */
65         UNIT_ATOM_ADD_DEFAULT_TARGET_DEPENDENCY_QUEUE = UINT64_C(1) << 20,
66         /* Recheck default target deps on other units (which are target units) */
67         UNIT_ATOM_DEFAULT_TARGET_DEPENDENCIES         = UINT64_C(1) << 21,
68 
69         /* The remaining atoms map 1:1 to the equally named high-level deps */
70         UNIT_ATOM_ON_FAILURE                          = UINT64_C(1) << 22,
71         UNIT_ATOM_ON_SUCCESS                          = UINT64_C(1) << 23,
72         UNIT_ATOM_ON_FAILURE_OF                       = UINT64_C(1) << 24,
73         UNIT_ATOM_ON_SUCCESS_OF                       = UINT64_C(1) << 25,
74         UNIT_ATOM_BEFORE                              = UINT64_C(1) << 26,
75         UNIT_ATOM_AFTER                               = UINT64_C(1) << 27,
76         UNIT_ATOM_TRIGGERS                            = UINT64_C(1) << 28,
77         UNIT_ATOM_TRIGGERED_BY                        = UINT64_C(1) << 29,
78         UNIT_ATOM_PROPAGATES_RELOAD_TO                = UINT64_C(1) << 30,
79         UNIT_ATOM_JOINS_NAMESPACE_OF                  = UINT64_C(1) << 31,
80         UNIT_ATOM_REFERENCES                          = UINT64_C(1) << 32,
81         UNIT_ATOM_REFERENCED_BY                       = UINT64_C(1) << 33,
82         UNIT_ATOM_IN_SLICE                            = UINT64_C(1) << 34,
83         UNIT_ATOM_SLICE_OF                            = UINT64_C(1) << 35,
84         _UNIT_DEPENDENCY_ATOM_MAX                     = (UINT64_C(1) << 36) - 1,
85         _UNIT_DEPENDENCY_ATOM_INVALID                 = -EINVAL,
86 } UnitDependencyAtom;
87 
88 UnitDependencyAtom unit_dependency_to_atom(UnitDependency d);
89 UnitDependency unit_dependency_from_unique_atom(UnitDependencyAtom atom);
90