/src/systemd/src/shared/condition.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* SPDX-License-Identifier: LGPL-2.1-or-later */  | 
2  |  | #pragma once  | 
3  |  |  | 
4  |  | #include <stdbool.h>  | 
5  |  | #include <stdio.h>  | 
6  |  |  | 
7  |  | #include "list.h"  | 
8  |  | #include "macro.h"  | 
9  |  |  | 
10  |  | typedef enum ConditionType { | 
11  |  |         CONDITION_ARCHITECTURE,  | 
12  |  |         CONDITION_FIRMWARE,  | 
13  |  |         CONDITION_VIRTUALIZATION,  | 
14  |  |         CONDITION_HOST,  | 
15  |  |         CONDITION_KERNEL_COMMAND_LINE,  | 
16  |  |         CONDITION_KERNEL_VERSION,  | 
17  |  |         CONDITION_CREDENTIAL,  | 
18  |  |         CONDITION_SECURITY,  | 
19  |  |         CONDITION_CAPABILITY,  | 
20  |  |         CONDITION_AC_POWER,  | 
21  |  |         CONDITION_MEMORY,  | 
22  |  |         CONDITION_CPUS,  | 
23  |  |         CONDITION_ENVIRONMENT,  | 
24  |  |         CONDITION_CPU_FEATURE,  | 
25  |  |         CONDITION_OS_RELEASE,  | 
26  |  |         CONDITION_MEMORY_PRESSURE,  | 
27  |  |         CONDITION_CPU_PRESSURE,  | 
28  |  |         CONDITION_IO_PRESSURE,  | 
29  |  |  | 
30  |  |         CONDITION_NEEDS_UPDATE,  | 
31  |  |         CONDITION_FIRST_BOOT,  | 
32  |  |  | 
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,  | 
39  |  |         CONDITION_PATH_IS_ENCRYPTED,  | 
40  |  |         CONDITION_DIRECTORY_NOT_EMPTY,  | 
41  |  |         CONDITION_FILE_NOT_EMPTY,  | 
42  |  |         CONDITION_FILE_IS_EXECUTABLE,  | 
43  |  |  | 
44  |  |         CONDITION_USER,  | 
45  |  |         CONDITION_GROUP,  | 
46  |  |  | 
47  |  |         CONDITION_CONTROL_GROUP_CONTROLLER,  | 
48  |  |  | 
49  |  |         _CONDITION_TYPE_MAX,  | 
50  |  |         _CONDITION_TYPE_INVALID = -EINVAL,  | 
51  |  | } ConditionType;  | 
52  |  |  | 
53  |  | typedef enum ConditionResult { | 
54  |  |         CONDITION_UNTESTED,  | 
55  |  |         CONDITION_SUCCEEDED,  | 
56  |  |         CONDITION_FAILED,  | 
57  |  |         CONDITION_ERROR,  | 
58  |  |         _CONDITION_RESULT_MAX,  | 
59  |  |         _CONDITION_RESULT_INVALID = -EINVAL,  | 
60  |  | } ConditionResult;  | 
61  |  |  | 
62  |  | typedef struct Condition { | 
63  |  |         ConditionType type:8;  | 
64  |  |  | 
65  |  |         bool trigger:1;  | 
66  |  |         bool negate:1;  | 
67  |  |  | 
68  |  |         ConditionResult result:6;  | 
69  |  |  | 
70  |  |         char *parameter;  | 
71  |  |  | 
72  |  |         LIST_FIELDS(struct Condition, conditions);  | 
73  |  | } Condition;  | 
74  |  |  | 
75  |  | Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);  | 
76  |  | Condition* condition_free(Condition *c);  | 
77  |  | Condition* condition_free_list_type(Condition *first, ConditionType type);  | 
78  | 1.88k  | static inline Condition* condition_free_list(Condition *first) { | 
79  | 1.88k  |         return condition_free_list_type(first, _CONDITION_TYPE_INVALID);  | 
80  | 1.88k  | } Unexecuted instantiation: fuzz-link-parser.c:condition_free_list link-config.c:condition_free_list Line  | Count  | Source  |  78  | 1.88k  | static inline Condition* condition_free_list(Condition *first) { |  79  | 1.88k  |         return condition_free_list_type(first, _CONDITION_TYPE_INVALID);  |  80  | 1.88k  | }  |  
 Unexecuted instantiation: link-config-gperf.c:condition_free_list  | 
81  |  |  | 
82  |  | int condition_test(Condition *c, char **env);  | 
83  |  |  | 
84  |  | typedef 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);  | 
85  |  | typedef const char* (*condition_to_string_t)(ConditionType t) _const_;  | 
86  |  | bool condition_test_list(Condition *first, char **env, condition_to_string_t to_string, condition_test_logger_t logger, void *userdata);  | 
87  |  |  | 
88  |  | void condition_dump(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);  | 
89  |  | void condition_dump_list(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);  | 
90  |  |  | 
91  |  | const char* condition_type_to_string(ConditionType t) _const_;  | 
92  |  | ConditionType condition_type_from_string(const char *s) _pure_;  | 
93  |  |  | 
94  |  | const char* assert_type_to_string(ConditionType t) _const_;  | 
95  |  | ConditionType assert_type_from_string(const char *s) _pure_;  | 
96  |  |  | 
97  |  | const char* condition_result_to_string(ConditionResult r) _const_;  | 
98  |  | ConditionResult condition_result_from_string(const char *s) _pure_;  | 
99  |  |  | 
100  | 0  | static inline bool condition_takes_path(ConditionType t) { | 
101  | 0  |         return IN_SET(t,  | 
102  | 0  |                       CONDITION_PATH_EXISTS,  | 
103  | 0  |                       CONDITION_PATH_EXISTS_GLOB,  | 
104  | 0  |                       CONDITION_PATH_IS_DIRECTORY,  | 
105  | 0  |                       CONDITION_PATH_IS_SYMBOLIC_LINK,  | 
106  | 0  |                       CONDITION_PATH_IS_MOUNT_POINT,  | 
107  | 0  |                       CONDITION_PATH_IS_READ_WRITE,  | 
108  | 0  |                       CONDITION_PATH_IS_ENCRYPTED,  | 
109  | 0  |                       CONDITION_DIRECTORY_NOT_EMPTY,  | 
110  | 0  |                       CONDITION_FILE_NOT_EMPTY,  | 
111  | 0  |                       CONDITION_FILE_IS_EXECUTABLE,  | 
112  | 0  |                       CONDITION_NEEDS_UPDATE);  | 
113  | 0  | } Unexecuted instantiation: fuzz-link-parser.c:condition_takes_path Unexecuted instantiation: link-config.c:condition_takes_path Unexecuted instantiation: link-config-gperf.c:condition_takes_path  |