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