summaryrefslogtreecommitdiff
path: root/src/analyze/analyze-condition.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-08-23 16:44:58 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2021-09-01 10:01:18 +0200
commit8de7929de5b70c4a130a0477c2f9baeecb86c905 (patch)
tree971a99f1722cf8f233905251e127a326ba1ff18b /src/analyze/analyze-condition.c
parente11ca6bb4d30bbb6cfc09f4cb94adebc3f88ad50 (diff)
downloadsystemd-8de7929de5b70c4a130a0477c2f9baeecb86c905.tar.gz
mkosi: Add zsh to Arch packages
Useful for testing zsh completion changes.
Diffstat (limited to 'src/analyze/analyze-condition.c')
-rw-r--r--src/analyze/analyze-condition.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/analyze/analyze-condition.c b/src/analyze/analyze-condition.c
index 09870b95ec..f57bb27b9a 100644
--- a/src/analyze/analyze-condition.c
+++ b/src/analyze/analyze-condition.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include "analyze-condition.h"
+#include "analyze-verify.h"
#include "condition.h"
#include "conf-parser.h"
#include "load-fragment.h"
@@ -72,29 +73,57 @@ static int log_helper(void *userdata, int level, int error, const char *file, in
return r;
}
-int verify_conditions(char **lines, UnitFileScope scope) {
+int verify_conditions(char **lines, UnitFileScope scope, const char *unit, const char *root) {
_cleanup_(manager_freep) Manager *m = NULL;
Unit *u;
- char **line;
int r, q = 1;
+ if (unit) {
+ _cleanup_strv_free_ char **filenames = NULL;
+ _cleanup_free_ char *var = NULL;
+
+ filenames = strv_new(unit);
+ if (!filenames)
+ return log_oom();
+
+ r = verify_generate_path(&var, filenames);
+ if (r < 0)
+ return log_error_errno(r, "Failed to generate unit load path: %m");
+
+ assert_se(set_unit_path(var) >= 0);
+ }
+
r = manager_new(scope, MANAGER_TEST_RUN_MINIMAL, &m);
if (r < 0)
return log_error_errno(r, "Failed to initialize manager: %m");
log_debug("Starting manager...");
- r = manager_startup(m, /* serialization= */ NULL, /* fds= */ NULL, /* root= */ NULL);
+ r = manager_startup(m, /* serialization= */ NULL, /* fds= */ NULL, root);
if (r < 0)
return r;
- r = unit_new_for_name(m, sizeof(Service), "test.service", &u);
- if (r < 0)
- return log_error_errno(r, "Failed to create test.service: %m");
+ if (unit) {
+ _cleanup_free_ char *prepared = NULL;
- STRV_FOREACH(line, lines) {
- r = parse_condition(u, *line);
+ r = verify_prepare_filename(unit, &prepared);
+ if (r < 0)
+ return log_error_errno(r, "Failed to prepare filename %s: %m", unit);
+
+ r = manager_load_startable_unit_or_warn(m, NULL, prepared, &u);
if (r < 0)
return r;
+ } else {
+ char **line;
+
+ r = unit_new_for_name(m, sizeof(Service), "test.service", &u);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create test.service: %m");
+
+ STRV_FOREACH(line, lines) {
+ r = parse_condition(u, *line);
+ if (r < 0)
+ return r;
+ }
}
r = condition_test_list(u->asserts, environ, assert_type_to_string, log_helper, u);