]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/condition.h
Merge pull request #12106 from poettering/nosuidns
[thirdparty/systemd.git] / src / shared / condition.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
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
LP
11 CONDITION_ARCHITECTURE,
12 CONDITION_VIRTUALIZATION,
13 CONDITION_HOST,
14 CONDITION_KERNEL_COMMAND_LINE,
5022f08a 15 CONDITION_KERNEL_VERSION,
651c3318
LP
16 CONDITION_SECURITY,
17 CONDITION_CAPABILITY,
18 CONDITION_AC_POWER,
19
20 CONDITION_NEEDS_UPDATE,
21 CONDITION_FIRST_BOOT,
59fccdc5 22
b77c08e0
TG
23 CONDITION_PATH_EXISTS,
24 CONDITION_PATH_EXISTS_GLOB,
25 CONDITION_PATH_IS_DIRECTORY,
26 CONDITION_PATH_IS_SYMBOLIC_LINK,
27 CONDITION_PATH_IS_MOUNT_POINT,
28 CONDITION_PATH_IS_READ_WRITE,
29 CONDITION_DIRECTORY_NOT_EMPTY,
30 CONDITION_FILE_NOT_EMPTY,
31 CONDITION_FILE_IS_EXECUTABLE,
59fccdc5 32
651c3318 33 CONDITION_NULL,
59fccdc5 34
c465a29f
FS
35 CONDITION_USER,
36 CONDITION_GROUP,
37
e16647c3
CD
38 CONDITION_CONTROL_GROUP_CONTROLLER,
39
b77c08e0
TG
40 _CONDITION_TYPE_MAX,
41 _CONDITION_TYPE_INVALID = -1
42} ConditionType;
43
cc50ef13
LP
44typedef enum ConditionResult {
45 CONDITION_UNTESTED,
46 CONDITION_SUCCEEDED,
47 CONDITION_FAILED,
48 CONDITION_ERROR,
49 _CONDITION_RESULT_MAX,
50 _CONDITION_RESULT_INVALID = -1
51} ConditionResult;
592fd144 52
b77c08e0 53typedef struct Condition {
59fccdc5 54 ConditionType type:8;
b77c08e0
TG
55
56 bool trigger:1;
57 bool negate:1;
58
59fccdc5
LP
59 ConditionResult result:6;
60
b77c08e0 61 char *parameter;
b77c08e0
TG
62
63 LIST_FIELDS(struct Condition, conditions);
64} Condition;
65
66Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);
67void condition_free(Condition *c);
c4f58dea
YW
68Condition* condition_free_list_type(Condition *first, ConditionType type);
69static inline Condition* condition_free_list(Condition *first) {
70 return condition_free_list_type(first, _CONDITION_TYPE_INVALID);
71}
b77c08e0 72
d1bddcec 73int condition_test(Condition *c);
828fa610
YW
74typedef 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);
75bool condition_test_list(Condition *first, const char *(*to_string)(ConditionType t), condition_test_logger_t logger, void *userdata);
d1bddcec 76
59fccdc5
LP
77void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
78void condition_dump_list(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t));
b77c08e0
TG
79
80const char* condition_type_to_string(ConditionType t) _const_;
59fccdc5
LP
81ConditionType condition_type_from_string(const char *s) _pure_;
82
83const char* assert_type_to_string(ConditionType t) _const_;
84ConditionType assert_type_from_string(const char *s) _pure_;
cc50ef13
LP
85
86const char* condition_result_to_string(ConditionResult r) _const_;
87ConditionResult condition_result_from_string(const char *s) _pure_;
d8f37c89
YW
88
89static inline bool condition_takes_path(ConditionType t) {
90 return IN_SET(t,
91 CONDITION_PATH_EXISTS,
92 CONDITION_PATH_EXISTS_GLOB,
93 CONDITION_PATH_IS_DIRECTORY,
94 CONDITION_PATH_IS_SYMBOLIC_LINK,
95 CONDITION_PATH_IS_MOUNT_POINT,
96 CONDITION_PATH_IS_READ_WRITE,
97 CONDITION_DIRECTORY_NOT_EMPTY,
98 CONDITION_FILE_NOT_EMPTY,
99 CONDITION_FILE_IS_EXECUTABLE,
100 CONDITION_NEEDS_UPDATE);
101}