]>
Commit | Line | Data |
---|---|---|
91b79ba8 ZJS |
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | ||
d6b4d1c7 ZJS |
3 | #include <stdio.h> |
4 | ||
4453ebe4 | 5 | #include "alloc-util.h" |
91b79ba8 | 6 | #include "build.h" |
4453ebe4 | 7 | #include "extract-word.h" |
d6b4d1c7 | 8 | #include "macro.h" |
4453ebe4 LP |
9 | #include "string-util.h" |
10 | #include "terminal-util.h" | |
c47511da | 11 | #include "version.h" |
91b79ba8 ZJS |
12 | |
13 | const char* const systemd_features = | |
14 | ||
15 | /* PAM and MAC frameworks */ | |
16 | ||
17 | #if HAVE_PAM | |
18 | "+PAM" | |
19 | #else | |
20 | "-PAM" | |
21 | #endif | |
22 | ||
23 | #if HAVE_AUDIT | |
24 | " +AUDIT" | |
25 | #else | |
26 | " -AUDIT" | |
27 | #endif | |
28 | ||
29 | #if HAVE_SELINUX | |
30 | " +SELINUX" | |
31 | #else | |
32 | " -SELINUX" | |
33 | #endif | |
34 | ||
35 | #if HAVE_APPARMOR | |
36 | " +APPARMOR" | |
37 | #else | |
38 | " -APPARMOR" | |
39 | #endif | |
40 | ||
41 | #if ENABLE_IMA | |
42 | " +IMA" | |
43 | #else | |
44 | " -IMA" | |
45 | #endif | |
46 | ||
47 | #if ENABLE_SMACK | |
48 | " +SMACK" | |
49 | #else | |
50 | " -SMACK" | |
51 | #endif | |
52 | ||
53 | #if HAVE_SECCOMP | |
54 | " +SECCOMP" | |
55 | #else | |
56 | " -SECCOMP" | |
57 | #endif | |
58 | ||
7e8facb3 | 59 | /* cryptographic libraries */ |
91b79ba8 ZJS |
60 | |
61 | #if HAVE_GCRYPT | |
62 | " +GCRYPT" | |
63 | #else | |
64 | " -GCRYPT" | |
65 | #endif | |
66 | ||
67 | #if HAVE_GNUTLS | |
68 | " +GNUTLS" | |
69 | #else | |
70 | " -GNUTLS" | |
71 | #endif | |
72 | ||
73 | #if HAVE_OPENSSL | |
74 | " +OPENSSL" | |
75 | #else | |
76 | " -OPENSSL" | |
77 | #endif | |
78 | ||
79 | /* all other libraries, sorted alphabetically */ | |
80 | ||
81 | #if HAVE_ACL | |
82 | " +ACL" | |
83 | #else | |
84 | " -ACL" | |
85 | #endif | |
86 | ||
87 | #if HAVE_BLKID | |
88 | " +BLKID" | |
89 | #else | |
90 | " -BLKID" | |
91 | #endif | |
92 | ||
93 | #if HAVE_LIBCURL | |
94 | " +CURL" | |
95 | #else | |
96 | " -CURL" | |
97 | #endif | |
98 | ||
99 | #if HAVE_ELFUTILS | |
100 | " +ELFUTILS" | |
101 | #else | |
102 | " -ELFUTILS" | |
103 | #endif | |
104 | ||
105 | #if HAVE_LIBFIDO2 | |
106 | " +FIDO2" | |
107 | #else | |
108 | " -FIDO2" | |
109 | #endif | |
110 | ||
111 | #if HAVE_LIBIDN2 | |
112 | " +IDN2" | |
113 | #else | |
114 | " -IDN2" | |
115 | #endif | |
116 | ||
117 | #if HAVE_LIBIDN | |
118 | " +IDN" | |
119 | #else | |
120 | " -IDN" | |
121 | #endif | |
122 | ||
123 | #if HAVE_LIBIPTC | |
124 | " +IPTC" | |
125 | #else | |
126 | " -IPTC" | |
127 | #endif | |
128 | ||
129 | #if HAVE_KMOD | |
130 | " +KMOD" | |
131 | #else | |
132 | " -KMOD" | |
133 | #endif | |
134 | ||
135 | #if HAVE_LIBCRYPTSETUP | |
136 | " +LIBCRYPTSETUP" | |
137 | #else | |
138 | " -LIBCRYPTSETUP" | |
139 | #endif | |
140 | ||
a3c1b0d7 VS |
141 | #if HAVE_LIBCRYPTSETUP_PLUGINS |
142 | " +LIBCRYPTSETUP_PLUGINS" | |
143 | #else | |
144 | " -LIBCRYPTSETUP_PLUGINS" | |
145 | #endif | |
146 | ||
91b79ba8 ZJS |
147 | #if HAVE_LIBFDISK |
148 | " +LIBFDISK" | |
149 | #else | |
150 | " -LIBFDISK" | |
151 | #endif | |
152 | ||
153 | #if HAVE_PCRE2 | |
154 | " +PCRE2" | |
155 | #else | |
156 | " -PCRE2" | |
157 | #endif | |
158 | ||
159 | #if HAVE_PWQUALITY | |
160 | " +PWQUALITY" | |
161 | #else | |
162 | " -PWQUALITY" | |
163 | #endif | |
164 | ||
165 | #if HAVE_P11KIT | |
166 | " +P11KIT" | |
167 | #else | |
168 | " -P11KIT" | |
169 | #endif | |
170 | ||
171 | #if HAVE_QRENCODE | |
172 | " +QRENCODE" | |
173 | #else | |
174 | " -QRENCODE" | |
175 | #endif | |
176 | ||
6d39da79 FB |
177 | #if HAVE_TPM2 |
178 | " +TPM2" | |
179 | #else | |
180 | " -TPM2" | |
181 | #endif | |
182 | ||
91b79ba8 ZJS |
183 | /* compressors */ |
184 | ||
185 | #if HAVE_BZIP2 | |
186 | " +BZIP2" | |
187 | #else | |
188 | " -BZIP2" | |
189 | #endif | |
190 | ||
191 | #if HAVE_LZ4 | |
192 | " +LZ4" | |
193 | #else | |
194 | " -LZ4" | |
195 | #endif | |
196 | ||
197 | #if HAVE_XZ | |
198 | " +XZ" | |
199 | #else | |
200 | " -XZ" | |
201 | #endif | |
202 | ||
203 | #if HAVE_ZLIB | |
204 | " +ZLIB" | |
205 | #else | |
206 | " -ZLIB" | |
207 | #endif | |
208 | ||
209 | #if HAVE_ZSTD | |
210 | " +ZSTD" | |
211 | #else | |
212 | " -ZSTD" | |
213 | #endif | |
214 | ||
215 | /* other stuff that doesn't fit above */ | |
216 | ||
6b35ed80 YW |
217 | #if BPF_FRAMEWORK |
218 | " +BPF_FRAMEWORK" | |
219 | #else | |
220 | " -BPF_FRAMEWORK" | |
221 | #endif | |
222 | ||
91b79ba8 ZJS |
223 | #if HAVE_XKBCOMMON |
224 | " +XKBCOMMON" | |
225 | #else | |
226 | " -XKBCOMMON" | |
227 | #endif | |
228 | ||
229 | #if ENABLE_UTMP | |
230 | " +UTMP" | |
231 | #else | |
232 | " -UTMP" | |
233 | #endif | |
234 | ||
235 | #if HAVE_SYSV_COMPAT | |
236 | " +SYSVINIT" | |
237 | #else | |
238 | " -SYSVINIT" | |
239 | #endif | |
240 | ||
241 | " default-hierarchy=" DEFAULT_HIERARCHY_NAME | |
242 | ; | |
d6b4d1c7 | 243 | |
4453ebe4 LP |
244 | static char *systemd_features_with_color(void) { |
245 | const char *p = systemd_features; | |
246 | _cleanup_free_ char *ret = NULL; | |
247 | int r; | |
248 | ||
249 | for (;;) { | |
250 | _cleanup_free_ char *word = NULL; | |
251 | char *q; | |
252 | ||
253 | r = extract_first_word(&p, &word, NULL, 0); | |
254 | if (r < 0) { | |
255 | log_warning_errno(r, "Cannot split features string, ignoring: %m"); | |
256 | return NULL; | |
257 | } | |
258 | if (r == 0) | |
259 | return TAKE_PTR(ret); | |
260 | ||
261 | if (ret && !strextend(&ret, " ")) { | |
262 | log_oom_warning(); | |
263 | return NULL; | |
264 | } | |
265 | ||
266 | if (word[0] == '+') | |
267 | q = strextend(&ret, ANSI_HIGHLIGHT_GREEN, CHAR_TO_STR(word[0]), ANSI_GREEN, word+1, ANSI_NORMAL); | |
268 | else if (word[0] == '-') | |
269 | q = strextend(&ret, ANSI_HIGHLIGHT_RED, CHAR_TO_STR(word[0]), ANSI_RED, word+1, ANSI_NORMAL); | |
270 | else | |
271 | q = strextend(&ret, word); | |
272 | if (!q) { | |
273 | log_oom_warning(); | |
274 | return NULL; | |
275 | } | |
276 | } | |
277 | } | |
278 | ||
d6b4d1c7 | 279 | int version(void) { |
4453ebe4 LP |
280 | _cleanup_free_ char *b = NULL; |
281 | ||
282 | if (colors_enabled()) | |
283 | b = systemd_features_with_color(); | |
284 | ||
0c90efc9 ZJS |
285 | printf("%ssystemd " STRINGIFY(PROJECT_VERSION) "%s (" GIT_VERSION ")\n%s\n", |
286 | ansi_highlight(), ansi_normal(), | |
4453ebe4 | 287 | b ?: systemd_features); |
d6b4d1c7 ZJS |
288 | return 0; |
289 | } |