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

systemd / systemd / 26546993077

27 May 2026 08:34PM UTC coverage: 72.995% (+0.3%) from 72.667%
26546993077

push

github

bluca
test-pressure: set timeout to make not wait forever

If this runs on a slow or busy machine, then we may not get enough
pressure to trigger the event sources. In such case, the test does not
finish. It is problematic when the test is _not_ run with 'meson test',
e.g. debian/ubuntu CIs.

Let's introduce a timeout for each event loop, and skip test cases
gracefully.

8 of 12 new or added lines in 1 file covered. (66.67%)

19671 existing lines in 226 files now uncovered.

337119 of 461841 relevant lines covered (72.99%)

1326365.62 hits per line

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

75.0
/src/bootctl/bootctl-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdlib.h>
4
#include <unistd.h>
5

6
#include "alloc-util.h"
7
#include "boot-entry.h"
8
#include "bootctl.h"
9
#include "bootctl-util.h"
10
#include "efivars.h"
11
#include "errno-util.h"
12
#include "fileio.h"
13
#include "log.h"
14
#include "pe-binary.h"
15
#include "string-util.h"
16
#include "sync-util.h"
17
#include "virt.h"
18

19
bool touch_variables(void) {
140✔
20
        /* If we run in a container or on a non-EFI system, automatically turn off EFI file system access,
21
         * unless explicitly overridden. */
22

23
        if (arg_touch_variables >= 0)
140✔
UNCOV
24
                return set_efi_boot(arg_touch_variables);
×
25

26
        if (arg_root) {
140✔
27
                log_once(LOG_NOTICE,
46✔
28
                         "Operating on %s, skipping EFI variable modifications.",
29
                         arg_image ? "image" : "root directory");
30
                return set_efi_boot(false);
29✔
31
        }
32

33
        if (!is_efi_boot()) { /* NB: this internally checks if we run in a container */
111✔
UNCOV
34
                log_once(LOG_NOTICE,
×
35
                         "Not booted with EFI or running in a container, skipping EFI variable modifications.");
36
                return false;
37
        }
38

39
        return true;
40
}
41

42
int verify_touch_variables_allowed(const char *command) {
6✔
43
        /* Note: changing EFI variables is the primary purpose of these verbs, hence unlike in the other
44
         * verbs that might touch EFI variables where we skip things gracefully, here we fail loudly if we
45
         * are not run on EFI or EFI variable modifications were turned off. */
46

47
        if (arg_touch_variables > 0) {
6✔
48
                /* If we explicitly allowed to touch EFI variables, then skip the is_efi_boot() checks used
49
                 * at various places. */
UNCOV
50
                set_efi_boot(true);
×
51
                return 0;
×
52
        }
53

54
        if (arg_touch_variables == 0)
6✔
UNCOV
55
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
56
                                       "'%s' operation cannot be combined with --variables=no.",
57
                                       command);
58

59
        if (arg_root)
6✔
UNCOV
60
                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
×
61
                                       "Acting on %s, refusing EFI variable setup.",
62
                                       arg_image ? "image" : "root directory");
63

64
        if (detect_container() > 0)
6✔
UNCOV
65
                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
×
66
                                       "'%s' operation not supported in a container.",
67
                                       command);
68

69
        if (!is_efi_boot())
6✔
UNCOV
70
                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
×
71
                                       "Not booted with UEFI.");
72

73
        if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderInfo")), F_OK) < 0) {
6✔
UNCOV
74
                if (errno == ENOENT) {
×
75
                        log_error_errno(errno, "Not booted with a supported boot loader.");
×
76
                        return -EOPNOTSUPP;
77
                }
78

UNCOV
79
                return log_error_errno(errno, "Failed to detect whether boot loader supports '%s' operation: %m", command);
×
80
        }
81

82
        return 0;
83
}
84

85
int sync_everything(void) {
155✔
86
        int r = 0, k;
155✔
87

88
        if (arg_esp_path) {
155✔
89
                k = syncfs_path(AT_FDCWD, arg_esp_path);
155✔
90
                if (k < 0)
155✔
UNCOV
91
                        RET_GATHER(r, log_error_errno(k, "Failed to synchronize the ESP '%s': %m", arg_esp_path));
×
92
        }
93

94
        if (arg_xbootldr_path) {
155✔
95
                k = syncfs_path(AT_FDCWD, arg_xbootldr_path);
18✔
96
                if (k < 0)
18✔
UNCOV
97
                        RET_GATHER(r, log_error_errno(k, "Failed to synchronize $BOOT '%s': %m", arg_xbootldr_path));
×
98
        }
99

100
        return r;
155✔
101
}
102

103
const char* get_efi_arch(void) {
160✔
104
        /* Detect EFI firmware architecture of the running system. On mixed mode systems, it could be 32-bit
105
         * while the kernel is running in 64-bit. */
106

107
#ifdef __x86_64__
108
        _cleanup_free_ char *platform_size = NULL;
160✔
109
        int r;
160✔
110

111
        r = read_one_line_file("/sys/firmware/efi/fw_platform_size", &platform_size);
160✔
112
        if (r == -ENOENT)
160✔
113
                return EFI_MACHINE_TYPE_NAME;
114
        if (r < 0) {
50✔
115
                log_warning_errno(r,
160✔
116
                        "Error reading EFI firmware word size, assuming machine type '%s': %m",
117
                        EFI_MACHINE_TYPE_NAME);
118
                return EFI_MACHINE_TYPE_NAME;
119
        }
120

121
        if (streq(platform_size, "64"))
50✔
122
                return EFI_MACHINE_TYPE_NAME;
UNCOV
123
        if (streq(platform_size, "32"))
×
124
                return "ia32";
125

UNCOV
126
        log_warning(
×
127
                "Unknown EFI firmware word size '%s', using machine type '%s'.",
128
                platform_size,
129
                EFI_MACHINE_TYPE_NAME);
130
#endif
131

132
        return EFI_MACHINE_TYPE_NAME;
133
}
134

135
int get_file_version(int fd, char **ret) {
601✔
136
        int r;
601✔
137

138
        assert(fd >= 0);
601✔
139
        assert(ret);
601✔
140

141
        /* Reads the version marker that systemd-boot/systemd-stub and friends store in their ".sdmagic" PE
142
         * section, i.e. a string such as "#### LoaderInfo: systemd-boot 218 ####", and returns the inner
143
         * part, e.g. "systemd-boot 218". Does not reposition the file offset (as it uses pread()). */
144

145
        _cleanup_free_ IMAGE_DOS_HEADER *dos_header = NULL;
1,202✔
146
        _cleanup_free_ PeHeader *pe_header = NULL;
601✔
147
        r = pe_load_headers(fd, &dos_header, &pe_header);
601✔
148
        if (r == -EBADMSG)
601✔
149
                return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "EFI binary is not a valid PE file, assuming no version information.");
1✔
150
        if (r < 0)
600✔
151
                return r;
152

153
        _cleanup_free_ IMAGE_SECTION_HEADER *sections = NULL;
600✔
154
        r = pe_load_sections(fd, dos_header, pe_header, &sections);
600✔
155
        if (r == -EBADMSG)
600✔
UNCOV
156
                return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "Failed to load PE section table, assuming no version information.");
×
157
        if (r < 0)
600✔
158
                return r;
159

160
        _cleanup_free_ char *sdmagic = NULL;
600✔
161
        r = pe_read_section_data_by_name(
600✔
162
                        fd,
163
                        pe_header,
164
                        sections,
165
                        ".sdmagic",
166
                        /* max_size= */ 4U*1024U,
167
                        (void**) &sdmagic,
168
                        /* ret_size= */ NULL);
169
        if (IN_SET(r, -ENXIO, -EBADMSG))
600✔
170
                return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "EFI binary has no .sdmagic section, assuming no version information.");
×
171
        if (r < 0)
600✔
UNCOV
172
                return log_debug_errno(r, "Failed to read .sdmagic section of EFI binary: %m");
×
173

174
        const char *p = startswith(sdmagic, "#### LoaderInfo: ");
600✔
175
        if (!p)
600✔
176
                return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "EFI binary .sdmagic section lacks LoaderInfo marker.");
×
177

178
        const char *e = endswith(p, " ####");
600✔
179
        if (!e || e <= p)
600✔
UNCOV
180
                return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "EFI binary has malformed LoaderInfo marker.");
×
181

182
        char *marker = strndup(p, e - p);
600✔
183
        if (!marker)
600✔
UNCOV
184
                return log_oom_debug();
×
185

186
        log_debug("EFI binary LoaderInfo marker: \"%s\"", marker);
600✔
187
        *ret = TAKE_PTR(marker);
600✔
188
        return 0;
600✔
189
}
190

191
int settle_entry_token(void) {
20✔
192
        int r;
20✔
193

194
        r = boot_entry_token_ensure(
20✔
195
                        arg_root,
196
                        secure_getenv("KERNEL_INSTALL_CONF_ROOT"),
20✔
197
                        arg_machine_id,
198
                        /* machine_id_is_random= */ false,
199
                        &arg_entry_token_type,
200
                        &arg_entry_token);
201
        if (r < 0)
20✔
202
                return r;
203

204
        log_debug("Using entry token: %s", arg_entry_token);
20✔
205
        return 0;
206
}
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