• 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

77.11
/src/shared/fdisk-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "bitfield.h"
4
#include "dissect-image.h"
5
#include "extract-word.h"
6
#include "fd-util.h"
7
#include "fdisk-util.h"
8
#include "log.h"
9
#include "parse-util.h"
10

11
#if HAVE_LIBFDISK
12

13
int fdisk_new_context_at(
332✔
14
                int dir_fd,
15
                const char *path,
16
                bool read_only,
17
                uint32_t sector_size,
18
                struct fdisk_context **ret) {
19

20
        _cleanup_(fdisk_unref_contextp) struct fdisk_context *c = NULL;
332✔
21
        _cleanup_close_ int fd = -EBADF;
332✔
22
        int r;
332✔
23

24
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
332✔
25
        assert(ret);
332✔
26

27
        if (!isempty(path)) {
332✔
28
                fd = openat(dir_fd, path, (read_only ? O_RDONLY : O_RDWR)|O_CLOEXEC);
312✔
29
                if (fd < 0)
264✔
30
                        return -errno;
×
31

32
                dir_fd = fd;
33
        }
34

35
        c = fdisk_new_context();
332✔
36
        if (!c)
332✔
37
                return -ENOMEM;
38

39
        if (sector_size == UINT32_MAX) {
332✔
40
                r = probe_sector_size_prefer_ioctl(dir_fd, &sector_size);
268✔
41
                if (r < 0)
268✔
42
                        return r;
43
        }
44

45
        if (sector_size != 0) {
332✔
46
                r = fdisk_save_user_sector_size(c, /* phy= */ 0, sector_size);
306✔
47
                if (r < 0)
306✔
48
                        return r;
49
        }
50

51
        r = fdisk_assign_device(c, FORMAT_PROC_FD_PATH(dir_fd), read_only);
332✔
52
        if (r < 0)
332✔
53
                return r;
54

55
        *ret = TAKE_PTR(c);
332✔
56
        return 0;
332✔
57
}
58

59
int fdisk_partition_get_uuid_as_id128(struct fdisk_partition *p, sd_id128_t *ret) {
990✔
60
        const char *ids;
990✔
61

62
        assert(p);
990✔
63
        assert(ret);
990✔
64

65
        ids = fdisk_partition_get_uuid(p);
990✔
66
        if (!ids)
990✔
67
                return -ENXIO;
68

69
        return sd_id128_from_string(ids, ret);
990✔
70
}
71

72
int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret) {
990✔
73
        struct fdisk_parttype *pt;
990✔
74
        const char *pts;
990✔
75

76
        assert(p);
990✔
77
        assert(ret);
990✔
78

79
        pt = fdisk_partition_get_type(p);
990✔
80
        if (!pt)
990✔
81
                return -ENXIO;
82

83
        pts = fdisk_parttype_get_string(pt);
990✔
84
        if (!pts)
990✔
85
                return -ENXIO;
86

87
        return sd_id128_from_string(pts, ret);
990✔
88
}
89

90
int fdisk_partition_get_attrs_as_uint64(struct fdisk_partition *pa, uint64_t *ret) {
876✔
91
        uint64_t flags = 0;
876✔
92
        const char *a;
876✔
93
        int r;
876✔
94

95
        assert(pa);
876✔
96
        assert(ret);
876✔
97

98
        /* Retrieve current flags as uint64_t mask */
99

100
        a = fdisk_partition_get_attrs(pa);
876✔
101
        if (!a) {
876✔
102
                *ret = 0;
864✔
103
                return 0;
876✔
104
        }
105

106
        for (;;) {
24✔
107
                _cleanup_free_ char *word = NULL;
12✔
108

109
                r = extract_first_word(&a, &word, ",", EXTRACT_DONT_COALESCE_SEPARATORS);
24✔
110
                if (r < 0)
24✔
111
                        return r;
×
112
                if (r == 0)
24✔
113
                        break;
114

115
                if (streq(word, "RequiredPartition"))
12✔
116
                        flags |= SD_GPT_FLAG_REQUIRED_PARTITION;
×
117
                else if (streq(word, "NoBlockIOProtocol"))
12✔
118
                        flags |= SD_GPT_FLAG_NO_BLOCK_IO_PROTOCOL;
×
119
                else if (streq(word, "LegacyBIOSBootable"))
12✔
120
                        flags |= SD_GPT_FLAG_LEGACY_BIOS_BOOTABLE;
×
121
                else {
122
                        const char *e;
12✔
123
                        unsigned u;
12✔
124

125
                        /* Drop "GUID" prefix if specified */
126
                        e = startswith(word, "GUID:") ?: word;
12✔
127

128
                        if (safe_atou(e, &u) < 0) {
12✔
129
                                log_debug("Unknown partition flag '%s', ignoring.", word);
×
130
                                continue;
×
131
                        }
132

133
                        if (u >= sizeof(flags)*8) { /* partition flags on GPT are 64-bit. Let's ignore any further
12✔
134
                                                       bits should libfdisk report them */
135
                                log_debug("Partition flag above bit 63 (%s), ignoring.", word);
×
136
                                continue;
×
137
                        }
138

139
                        flags |= UINT64_C(1) << u;
12✔
140
                }
141
        }
142

143
        *ret = flags;
12✔
144
        return 0;
12✔
145
}
146

147
int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t flags) {
×
148
        _cleanup_free_ char *attrs = NULL;
×
149
        int r;
×
150

151
        assert(pa);
×
152

153
        for (unsigned i = 0; i < sizeof(flags) * 8; i++) {
×
154
                if (!BIT_SET(flags, i))
×
155
                        continue;
×
156

157
                r = strextendf_with_separator(&attrs, ",", "%u", i);
×
158
                if (r < 0)
×
159
                        return r;
160
        }
161

162
        return fdisk_partition_set_attrs(pa, strempty(attrs));
×
163
}
164

165
#endif
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