• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14630481637

23 Apr 2025 07:04PM UTC coverage: 72.178% (-0.002%) from 72.18%
14630481637

push

github

DaanDeMeyer
mkosi: Run clangd within the tools tree instead of the build container

Running within the build sandbox has a number of disadvantages:
- We have a separate clangd cache for each distribution/release combo
- It requires to build the full image before clangd can be used
- It breaks every time the image becomes out of date and requires a
  rebuild
- We can't look at system headers as we don't have the knowledge to map
  them from inside the build sandbox to the corresponding path on the host

Instead, let's have mkosi.clangd run clangd within the tools tree. We
already require building systemd for both the host and the target anyway,
and all the dependencies to build systemd are installed in the tools tree
already for that, as well as clangd since it's installed together with the
other clang tooling we install in the tools tree. Unlike the previous approach,
this approach only requires the mkosi tools tree to be built upfront, which has
a much higher chance of not invalidating its cache. We can also trivially map
system header lookups from within the sandbox to the path within mkosi.tools
on the host so that starts working as well.

297054 of 411557 relevant lines covered (72.18%)

686269.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/src/core/load-dropin.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "conf-parser.h"
4
#include "dropin.h"
5
#include "fs-util.h"
6
#include "load-dropin.h"
7
#include "load-fragment.h"
8
#include "log.h"
9
#include "manager.h"
10
#include "stat-util.h"
11
#include "string-util.h"
12
#include "strv.h"
13
#include "unit-name.h"
14
#include "unit.h"
15

16
int unit_find_dropin_paths(Unit *u, bool use_unit_path_cache, char ***paths) {
58,353✔
17
        assert(u);
58,353✔
18

19
        return unit_file_find_dropin_paths(NULL,
231,598✔
20
                                           u->manager->lookup_paths.search_path,
58,353✔
21
                                           use_unit_path_cache ? u->manager->unit_path_cache : NULL,
56,539✔
22
                                           ".d", ".conf",
23
                                           u->id, u->aliases,
58,353✔
24
                                           paths);
25
}
26

27
static int process_deps(Unit *u, UnitDependency dependency, const char *dir_suffix) {
169,617✔
28
        _cleanup_strv_free_ char **paths = NULL;
169,617✔
29
        int r;
169,617✔
30

31
        r = unit_file_find_dropin_paths(NULL,
339,234✔
32
                                        u->manager->lookup_paths.search_path,
33
                                        u->manager->unit_path_cache,
169,617✔
34
                                        dir_suffix, NULL,
35
                                        u->id, u->aliases,
169,617✔
36
                                        &paths);
37
        if (r < 0)
169,617✔
38
                return r;
39

40
        STRV_FOREACH(p, paths) {
184,196✔
41
                _cleanup_free_ char *target = NULL;
14,579✔
42
                const char *entry;
14,579✔
43

44
                entry = basename(*p);
14,579✔
45

46
                if (null_or_empty_path(*p) > 0) {
14,579✔
47
                        /* an error usually means an invalid symlink, which is not a mask */
48
                        log_unit_debug(u, "%s dependency on %s is masked by %s, ignoring.",
×
49
                                       unit_dependency_to_string(dependency), entry, *p);
50
                        continue;
×
51
                }
52

53
                r = is_symlink(*p);
14,579✔
54
                if (r < 0) {
14,579✔
55
                        log_unit_warning_errno(u, r, "%s dropin %s unreadable, ignoring: %m",
×
56
                                               unit_dependency_to_string(dependency), *p);
57
                        continue;
×
58
                }
59
                if (r == 0) {
14,579✔
60
                        log_unit_warning(u, "%s dependency dropin %s is not a symlink, ignoring.",
×
61
                                         unit_dependency_to_string(dependency), *p);
62
                        continue;
×
63
                }
64

65
                if (!unit_name_is_valid(entry, UNIT_NAME_ANY)) {
14,579✔
66
                        log_unit_warning(u, "%s dependency dropin %s is not a valid unit name, ignoring.",
×
67
                                         unit_dependency_to_string(dependency), *p);
68
                        continue;
×
69
                }
70

71
                r = readlink_malloc(*p, &target);
14,579✔
72
                if (r < 0) {
14,579✔
73
                        log_unit_warning_errno(u, r, "readlink(\"%s\") failed, ignoring: %m", *p);
×
74
                        continue;
×
75
                }
76

77
                /* We don't treat this as an error, especially because we didn't check this for a
78
                 * long time. Nevertheless, we warn, because such mismatch can be mighty confusing. */
79
                r = unit_symlink_name_compatible(entry, basename(target), u->instance);
14,579✔
80
                if (r < 0) {
14,579✔
81
                        log_unit_warning_errno(u, r, "Can't check if names %s and %s are compatible, ignoring: %m",
×
82
                                               entry, basename(target));
83
                        continue;
×
84
                }
85
                if (r == 0)
14,579✔
86
                        log_unit_warning(u, "%s dependency dropin %s target %s has different name",
×
87
                                         unit_dependency_to_string(dependency), *p, target);
88

89
                r = unit_add_dependency_by_name(u, dependency, entry, true, UNIT_DEPENDENCY_FILE);
14,579✔
90
                if (r < 0)
14,579✔
91
                        log_unit_warning_errno(u, r, "Cannot add %s dependency on %s, ignoring: %m",
×
92
                                               unit_dependency_to_string(dependency), entry);
93
        }
94

95
        return 0;
96
}
97

98
int unit_load_dropin(Unit *u) {
56,539✔
99
        _cleanup_strv_free_ char **l = NULL;
56,539✔
100
        int r;
56,539✔
101

102
        assert(u);
56,539✔
103

104
        /* Load dependencies from .wants, .requires and .upholds directories */
105
        r = process_deps(u, UNIT_WANTS, ".wants");
56,539✔
106
        if (r < 0)
56,539✔
107
                return r;
108

109
        r = process_deps(u, UNIT_REQUIRES, ".requires");
56,539✔
110
        if (r < 0)
56,539✔
111
                return r;
112

113
        r = process_deps(u, UNIT_UPHOLDS, ".upholds");
56,539✔
114
        if (r < 0)
56,539✔
115
                return r;
116

117
        /* Load .conf dropins */
118
        r = unit_find_dropin_paths(u, /* use_unit_path_cache = */ true, &l);
56,539✔
119
        if (r <= 0)
56,539✔
120
                return 0;
121

122
        r = strv_extend_strv_consume(&u->dropin_paths, TAKE_PTR(l), /* filter_duplicates = */ true);
11,335✔
123
        if (r < 0)
11,335✔
124
                return log_oom();
×
125

126
        u->dropin_mtime = 0;
11,335✔
127
        STRV_FOREACH(f, u->dropin_paths) {
23,020✔
128
                struct stat st;
11,685✔
129

130
                r = config_parse(u->id, *f, NULL,
11,685✔
131
                                 UNIT_VTABLE(u)->sections,
11,685✔
132
                                 config_item_perf_lookup, load_fragment_gperf_lookup,
133
                                 0, u, &st);
134
                if (r > 0)
11,685✔
135
                        u->dropin_mtime = MAX(u->dropin_mtime, timespec_load(&st.st_mtim));
11,685✔
136
        }
137

138
        return 0;
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc