]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/condition.h
mkosi: update arch commit reference
[thirdparty/systemd.git] / src / shared / condition.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
b77c08e0
TG
2#pragma once
3
b77c08e0
TG
4#include <stdbool.h>
5#include <stdio.h>
6
7#include "list.h"
8#include "macro.h"
9
10typedef enum ConditionType {
651c3318 11 CONDITION_ARCHITECTURE,
cbcdcaaa 12 CONDITION_FIRMWARE,
651c3318
LP
13 CONDITION_VIRTUALIZATION,
14 CONDITION_HOST,
15 CONDITION_KERNEL_COMMAND_LINE,
5022f08a 16 CONDITION_KERNEL_VERSION,
4f80cfca 17 CONDITION_CREDENTIAL,
651c3318
LP
18 CONDITION_SECURITY,
19 CONDITION_CAPABILITY,
20 CONDITION_AC_POWER,
754f719a
LP
21 CONDITION_MEMORY,
22 CONDITION_CPUS,
a0b191b7 23 CONDITION_ENVIRONMENT,
68337e55 24 CONDITION_CPU_FEATURE,
1e26f8a6 25 CONDITION_OS_RELEASE,
81513b38
LB
26 CONDITION_MEMORY_PRESSURE,
27 CONDITION_CPU_PRESSURE,
28 CONDITION_IO_PRESSURE,
651c3318
LP
29
30 CONDITION_NEEDS_UPDATE,
31 CONDITION_FIRST_BOOT,
59fccdc5 32
b77c08e0
TG
33 CONDITION_PATH_EXISTS,
34 CONDITION_PATH_EXISTS_GLOB,
35 CONDITION_PATH_IS_DIRECTORY,
36 CONDITION_PATH_IS_SYMBOLIC_LINK,
37 CONDITION_PATH_IS_MOUNT_POINT,
38 CONDITION_PATH_IS_READ_WRITE,
7f19247b 39 CONDITION_PATH_IS_ENCRYPTED,
b77c08e0
TG
40 CONDITION_DIRECTORY_NOT_EMPTY,
41 CONDITION_FILE_NOT_EMPTY,
42 CONDITION_FILE_IS_EXECUTABLE,
59fccdc5 43
c465a29f
FS
44 CONDITION_USER,
45 CONDITION_GROUP,
46
e16647c3
CD
47 CONDITION_CONTROL_GROUP_CONTROLLER,
48
b77c08e0 49 _CONDITION_TYPE_MAX,
2d93c20e 50 _CONDITION_TYPE_INVALID = -EINVAL,
b77c08e0
TG
51} ConditionType;
52
cc50ef13
LP
53typedef enum ConditionResult {
54 CONDITION_UNTESTED,
55 CONDITION_SUCCEEDED,
56 CONDITION_FAILED,
57 CONDITION_ERROR,
58 _CONDITION_RESULT_MAX,
2d93c20e 59 _CONDITION_RESULT_INVALID = -EINVAL,
cc50ef13 60} ConditionResult;
592fd144 61
b77c08e0 62typedef struct Condition {
59fccdc5 63 ConditionType type:8;
b77c08e0
TG
64
65 bool trigger:1;
66 bool negate:1;
67
59fccdc5
LP
68 ConditionResult result:6;
69
b77c08e0 70 char *parameter;
b77c08e0
TG
71
72 LIST_FIELDS(struct Condition, conditions);
73} Condition;
74
75Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);
411e835c 76Condition* condition_free(Condition *c);
c4f58dea
YW
77Condition* condition_free_list_type(Condition *first, ConditionType type);
78static inline Condition* condition_free_list(Condition *first) {
79 return condition_free_list_type(first, _CONDITION_TYPE_INVALID);
80}
b77c08e0 81
a0b191b7 82int condition_test(Condition *c, char **env);
dce719f6 83
828fa610 84typedef int (*condition_test_logger_t)(void *userdata, int level, int error, const char *file, int line, const char *func, const char *format, ...) _printf_(7, 8);
a0b191b7
LP
85typedef const char* (*condition_to_string_t)(ConditionType t) _const_;
86bool condition_test_list(Condition *first, char **env, condition_to_string_t to_string, condition_test_logger_t logger, void *userdata);
d1bddcec 87
dce719f6
LP
88void condition_dump(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);
89void condition_dump_list(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);
b77c08e0
TG
90
91const char* condition_type_to_string(ConditionType t) _const_;
59fccdc5
LP
92ConditionType condition_type_from_string(const char *s) _pure_;
93
94const char* assert_type_to_string(ConditionType t) _const_;
95ConditionType assert_type_from_string(const char *s) _pure_;
cc50ef13
LP
96
97const char* condition_result_to_string(ConditionResult r) _const_;
98ConditionResult condition_result_from_string(const char *s) _pure_;
d8f37c89
YW
99
100static inline bool condition_takes_path(ConditionType t) {
101 return IN_SET(t,
102 CONDITION_PATH_EXISTS,
103 CONDITION_PATH_EXISTS_GLOB,
104 CONDITION_PATH_IS_DIRECTORY,
105 CONDITION_PATH_IS_SYMBOLIC_LINK,
106 CONDITION_PATH_IS_MOUNT_POINT,
107 CONDITION_PATH_IS_READ_WRITE,
7f19247b 108 CONDITION_PATH_IS_ENCRYPTED,
d8f37c89
YW
109 CONDITION_DIRECTORY_NOT_EMPTY,
110 CONDITION_FILE_NOT_EMPTY,
111 CONDITION_FILE_IS_EXECUTABLE,
112 CONDITION_NEEDS_UPDATE);
113}