1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include <stdbool.h> 5 6 #include "errno-list.h" 7 #include "glyph-util.h" 8 #include "macro.h" 9 10 /* The enum order is used to order unit jobs in the job queue 11 * when other criteria (cpu weight, nice level) are identical. 12 * In this case service units have the highest priority. */ 13 typedef enum UnitType { 14 UNIT_SERVICE, 15 UNIT_MOUNT, 16 UNIT_SWAP, 17 UNIT_SOCKET, 18 UNIT_TARGET, 19 UNIT_DEVICE, 20 UNIT_AUTOMOUNT, 21 UNIT_TIMER, 22 UNIT_PATH, 23 UNIT_SLICE, 24 UNIT_SCOPE, 25 _UNIT_TYPE_MAX, 26 _UNIT_TYPE_INVALID = -EINVAL, 27 _UNIT_TYPE_ERRNO_MAX = -ERRNO_MAX, /* Ensure the whole errno range fits into this enum */ 28 } UnitType; 29 30 typedef enum UnitLoadState { 31 UNIT_STUB, 32 UNIT_LOADED, 33 UNIT_NOT_FOUND, /* error condition #1: unit file not found */ 34 UNIT_BAD_SETTING, /* error condition #2: we couldn't parse some essential unit file setting */ 35 UNIT_ERROR, /* error condition #3: other "system" error, catchall for the rest */ 36 UNIT_MERGED, 37 UNIT_MASKED, 38 _UNIT_LOAD_STATE_MAX, 39 _UNIT_LOAD_STATE_INVALID = -EINVAL, 40 } UnitLoadState; 41 42 typedef enum UnitActiveState { 43 UNIT_ACTIVE, 44 UNIT_RELOADING, 45 UNIT_INACTIVE, 46 UNIT_FAILED, 47 UNIT_ACTIVATING, 48 UNIT_DEACTIVATING, 49 UNIT_MAINTENANCE, 50 _UNIT_ACTIVE_STATE_MAX, 51 _UNIT_ACTIVE_STATE_INVALID = -EINVAL, 52 } UnitActiveState; 53 54 typedef enum FreezerState { 55 FREEZER_RUNNING, 56 FREEZER_FREEZING, 57 FREEZER_FROZEN, 58 FREEZER_THAWING, 59 _FREEZER_STATE_MAX, 60 _FREEZER_STATE_INVALID = -EINVAL, 61 } FreezerState; 62 63 typedef enum UnitMarker { 64 UNIT_MARKER_NEEDS_RELOAD, 65 UNIT_MARKER_NEEDS_RESTART, 66 _UNIT_MARKER_MAX, 67 _UNIT_MARKER_INVALID = -EINVAL, 68 } UnitMarker; 69 70 typedef enum AutomountState { 71 AUTOMOUNT_DEAD, 72 AUTOMOUNT_WAITING, 73 AUTOMOUNT_RUNNING, 74 AUTOMOUNT_FAILED, 75 _AUTOMOUNT_STATE_MAX, 76 _AUTOMOUNT_STATE_INVALID = -EINVAL, 77 } AutomountState; 78 79 /* We simply watch devices, we cannot plug/unplug them. That 80 * simplifies the state engine greatly */ 81 typedef enum DeviceState { 82 DEVICE_DEAD, 83 DEVICE_TENTATIVE, /* mounted or swapped, but not (yet) announced by udev */ 84 DEVICE_PLUGGED, /* announced by udev */ 85 _DEVICE_STATE_MAX, 86 _DEVICE_STATE_INVALID = -EINVAL, 87 } DeviceState; 88 89 typedef enum MountState { 90 MOUNT_DEAD, 91 MOUNT_MOUNTING, /* /usr/bin/mount is running, but the mount is not done yet. */ 92 MOUNT_MOUNTING_DONE, /* /usr/bin/mount is running, and the mount is done. */ 93 MOUNT_MOUNTED, 94 MOUNT_REMOUNTING, 95 MOUNT_UNMOUNTING, 96 MOUNT_REMOUNTING_SIGTERM, 97 MOUNT_REMOUNTING_SIGKILL, 98 MOUNT_UNMOUNTING_SIGTERM, 99 MOUNT_UNMOUNTING_SIGKILL, 100 MOUNT_FAILED, 101 MOUNT_CLEANING, 102 _MOUNT_STATE_MAX, 103 _MOUNT_STATE_INVALID = -EINVAL, 104 } MountState; 105 106 typedef enum PathState { 107 PATH_DEAD, 108 PATH_WAITING, 109 PATH_RUNNING, 110 PATH_FAILED, 111 _PATH_STATE_MAX, 112 _PATH_STATE_INVALID = -EINVAL, 113 } PathState; 114 115 typedef enum ScopeState { 116 SCOPE_DEAD, 117 SCOPE_RUNNING, 118 SCOPE_ABANDONED, 119 SCOPE_STOP_SIGTERM, 120 SCOPE_STOP_SIGKILL, 121 SCOPE_FAILED, 122 _SCOPE_STATE_MAX, 123 _SCOPE_STATE_INVALID = -EINVAL, 124 } ScopeState; 125 126 typedef enum ServiceState { 127 SERVICE_DEAD, 128 SERVICE_CONDITION, 129 SERVICE_START_PRE, 130 SERVICE_START, 131 SERVICE_START_POST, 132 SERVICE_RUNNING, 133 SERVICE_EXITED, /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */ 134 SERVICE_RELOAD, 135 SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */ 136 SERVICE_STOP_WATCHDOG, 137 SERVICE_STOP_SIGTERM, 138 SERVICE_STOP_SIGKILL, 139 SERVICE_STOP_POST, 140 SERVICE_FINAL_WATCHDOG, /* In case the STOP_POST executable needs to be aborted. */ 141 SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */ 142 SERVICE_FINAL_SIGKILL, 143 SERVICE_FAILED, 144 SERVICE_AUTO_RESTART, 145 SERVICE_CLEANING, 146 _SERVICE_STATE_MAX, 147 _SERVICE_STATE_INVALID = -EINVAL, 148 } ServiceState; 149 150 typedef enum SliceState { 151 SLICE_DEAD, 152 SLICE_ACTIVE, 153 _SLICE_STATE_MAX, 154 _SLICE_STATE_INVALID = -EINVAL, 155 } SliceState; 156 157 typedef enum SocketState { 158 SOCKET_DEAD, 159 SOCKET_START_PRE, 160 SOCKET_START_CHOWN, 161 SOCKET_START_POST, 162 SOCKET_LISTENING, 163 SOCKET_RUNNING, 164 SOCKET_STOP_PRE, 165 SOCKET_STOP_PRE_SIGTERM, 166 SOCKET_STOP_PRE_SIGKILL, 167 SOCKET_STOP_POST, 168 SOCKET_FINAL_SIGTERM, 169 SOCKET_FINAL_SIGKILL, 170 SOCKET_FAILED, 171 SOCKET_CLEANING, 172 _SOCKET_STATE_MAX, 173 _SOCKET_STATE_INVALID = -EINVAL, 174 } SocketState; 175 176 typedef enum SwapState { 177 SWAP_DEAD, 178 SWAP_ACTIVATING, /* /sbin/swapon is running, but the swap not yet enabled. */ 179 SWAP_ACTIVATING_DONE, /* /sbin/swapon is running, and the swap is done. */ 180 SWAP_ACTIVE, 181 SWAP_DEACTIVATING, 182 SWAP_DEACTIVATING_SIGTERM, 183 SWAP_DEACTIVATING_SIGKILL, 184 SWAP_FAILED, 185 SWAP_CLEANING, 186 _SWAP_STATE_MAX, 187 _SWAP_STATE_INVALID = -EINVAL, 188 } SwapState; 189 190 typedef enum TargetState { 191 TARGET_DEAD, 192 TARGET_ACTIVE, 193 _TARGET_STATE_MAX, 194 _TARGET_STATE_INVALID = -EINVAL, 195 } TargetState; 196 197 typedef enum TimerState { 198 TIMER_DEAD, 199 TIMER_WAITING, 200 TIMER_RUNNING, 201 TIMER_ELAPSED, 202 TIMER_FAILED, 203 _TIMER_STATE_MAX, 204 _TIMER_STATE_INVALID = -EINVAL, 205 } TimerState; 206 207 typedef enum UnitDependency { 208 /* Positive dependencies */ 209 UNIT_REQUIRES, 210 UNIT_REQUISITE, 211 UNIT_WANTS, 212 UNIT_BINDS_TO, 213 UNIT_PART_OF, 214 UNIT_UPHOLDS, 215 216 /* Inverse of the above */ 217 UNIT_REQUIRED_BY, /* inverse of 'requires' is 'required_by' */ 218 UNIT_REQUISITE_OF, /* inverse of 'requisite' is 'requisite_of' */ 219 UNIT_WANTED_BY, /* inverse of 'wants' */ 220 UNIT_BOUND_BY, /* inverse of 'binds_to' */ 221 UNIT_CONSISTS_OF, /* inverse of 'part_of' */ 222 UNIT_UPHELD_BY, /* inverse of 'uphold' */ 223 224 /* Negative dependencies */ 225 UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */ 226 UNIT_CONFLICTED_BY, 227 228 /* Order */ 229 UNIT_BEFORE, /* inverse of 'before' is 'after' and vice versa */ 230 UNIT_AFTER, 231 232 /* OnSuccess= + OnFailure= */ 233 UNIT_ON_SUCCESS, 234 UNIT_ON_SUCCESS_OF, 235 UNIT_ON_FAILURE, 236 UNIT_ON_FAILURE_OF, 237 238 /* Triggers (i.e. a socket triggers a service) */ 239 UNIT_TRIGGERS, 240 UNIT_TRIGGERED_BY, 241 242 /* Propagate reloads */ 243 UNIT_PROPAGATES_RELOAD_TO, 244 UNIT_RELOAD_PROPAGATED_FROM, 245 246 /* Propagate stops */ 247 UNIT_PROPAGATES_STOP_TO, 248 UNIT_STOP_PROPAGATED_FROM, 249 250 /* Joins namespace of */ 251 UNIT_JOINS_NAMESPACE_OF, 252 253 /* Reference information for GC logic */ 254 UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */ 255 UNIT_REFERENCED_BY, 256 257 /* Slice= */ 258 UNIT_IN_SLICE, 259 UNIT_SLICE_OF, 260 261 _UNIT_DEPENDENCY_MAX, 262 _UNIT_DEPENDENCY_INVALID = -EINVAL, 263 } UnitDependency; 264 265 typedef enum NotifyAccess { 266 NOTIFY_NONE, 267 NOTIFY_ALL, 268 NOTIFY_MAIN, 269 NOTIFY_EXEC, 270 _NOTIFY_ACCESS_MAX, 271 _NOTIFY_ACCESS_INVALID = -EINVAL, 272 } NotifyAccess; 273 274 char *unit_dbus_path_from_name(const char *name); 275 int unit_name_from_dbus_path(const char *path, char **name); 276 277 const char* unit_dbus_interface_from_type(UnitType t); 278 const char *unit_dbus_interface_from_name(const char *name); 279 280 const char *unit_type_to_string(UnitType i) _const_; 281 UnitType unit_type_from_string(const char *s) _pure_; 282 283 const char *unit_load_state_to_string(UnitLoadState i) _const_; 284 UnitLoadState unit_load_state_from_string(const char *s) _pure_; 285 286 const char *unit_active_state_to_string(UnitActiveState i) _const_; 287 UnitActiveState unit_active_state_from_string(const char *s) _pure_; 288 289 const char *freezer_state_to_string(FreezerState i) _const_; 290 FreezerState freezer_state_from_string(const char *s) _pure_; 291 292 const char *unit_marker_to_string(UnitMarker m) _const_; 293 UnitMarker unit_marker_from_string(const char *s) _pure_; 294 295 const char* automount_state_to_string(AutomountState i) _const_; 296 AutomountState automount_state_from_string(const char *s) _pure_; 297 298 const char* device_state_to_string(DeviceState i) _const_; 299 DeviceState device_state_from_string(const char *s) _pure_; 300 301 const char* mount_state_to_string(MountState i) _const_; 302 MountState mount_state_from_string(const char *s) _pure_; 303 304 const char* path_state_to_string(PathState i) _const_; 305 PathState path_state_from_string(const char *s) _pure_; 306 307 const char* scope_state_to_string(ScopeState i) _const_; 308 ScopeState scope_state_from_string(const char *s) _pure_; 309 310 const char* service_state_to_string(ServiceState i) _const_; 311 ServiceState service_state_from_string(const char *s) _pure_; 312 313 const char* slice_state_to_string(SliceState i) _const_; 314 SliceState slice_state_from_string(const char *s) _pure_; 315 316 const char* socket_state_to_string(SocketState i) _const_; 317 SocketState socket_state_from_string(const char *s) _pure_; 318 319 const char* swap_state_to_string(SwapState i) _const_; 320 SwapState swap_state_from_string(const char *s) _pure_; 321 322 const char* target_state_to_string(TargetState i) _const_; 323 TargetState target_state_from_string(const char *s) _pure_; 324 325 const char *timer_state_to_string(TimerState i) _const_; 326 TimerState timer_state_from_string(const char *s) _pure_; 327 328 const char *unit_dependency_to_string(UnitDependency i) _const_; 329 UnitDependency unit_dependency_from_string(const char *s) _pure_; 330 331 const char* notify_access_to_string(NotifyAccess i) _const_; 332 NotifyAccess notify_access_from_string(const char *s) _pure_; 333 334 SpecialGlyph unit_active_state_to_glyph(UnitActiveState state); 335