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

systemd / systemd / 16062852561

03 Jul 2025 10:04PM UTC coverage: 72.193% (+0.1%) from 72.096%
16062852561

push

github

bluca
pcrlock: process components outside of location window properly

So far, when we tried to match a component to eent log entries we
skipped those components if they were outside of our location window.
That however is too aggressive, since it means any components that are
already in the logs, but outside of the location window will be
considered unrecognized in the logs, and thus removed from the PCR
policy.

Change things around: always try to match up all components, regardless
if inside the location window or outside, but then make it non-fatal we
can't find a component outside of the location window.

Fixes: #36079

7 of 9 new or added lines in 1 file covered. (77.78%)

4116 existing lines in 75 files now uncovered.

301219 of 417241 relevant lines covered (72.19%)

730820.5 hits per line

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

88.57
/src/path/path-tool.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <getopt.h>
4
#include <stdio.h>
5

6
#include "sd-path.h"
7

8
#include "alloc-util.h"
9
#include "build.h"
10
#include "errno-util.h"
11
#include "log.h"
12
#include "main-func.h"
13
#include "pager.h"
14
#include "pretty-print.h"
15
#include "sort-util.h"
16
#include "string-util.h"
17

18
static const char *arg_suffix = NULL;
19
static PagerFlags arg_pager_flags = 0;
20

21
static const char* const path_table[_SD_PATH_MAX] = {
22
        [SD_PATH_TEMPORARY]                                   = "temporary",
23
        [SD_PATH_TEMPORARY_LARGE]                             = "temporary-large",
24

25
        [SD_PATH_SYSTEM_BINARIES]                             = "system-binaries",
26
        [SD_PATH_SYSTEM_INCLUDE]                              = "system-include",
27
        [SD_PATH_SYSTEM_LIBRARY_PRIVATE]                      = "system-library-private",
28
        [SD_PATH_SYSTEM_LIBRARY_ARCH]                         = "system-library-arch",
29
        [SD_PATH_SYSTEM_SHARED]                               = "system-shared",
30
        [SD_PATH_SYSTEM_CONFIGURATION_FACTORY]                = "system-configuration-factory",
31
        [SD_PATH_SYSTEM_STATE_FACTORY]                        = "system-state-factory",
32

33
        [SD_PATH_SYSTEM_CONFIGURATION]                        = "system-configuration",
34
        [SD_PATH_SYSTEM_RUNTIME]                              = "system-runtime",
35
        [SD_PATH_SYSTEM_RUNTIME_LOGS]                         = "system-runtime-logs",
36
        [SD_PATH_SYSTEM_STATE_PRIVATE]                        = "system-state-private",
37
        [SD_PATH_SYSTEM_STATE_LOGS]                           = "system-state-logs",
38
        [SD_PATH_SYSTEM_STATE_CACHE]                          = "system-state-cache",
39
        [SD_PATH_SYSTEM_STATE_SPOOL]                          = "system-state-spool",
40

41
        [SD_PATH_USER_BINARIES]                               = "user-binaries",
42
        [SD_PATH_USER_LIBRARY_PRIVATE]                        = "user-library-private",
43
        [SD_PATH_USER_LIBRARY_ARCH]                           = "user-library-arch",
44
        [SD_PATH_USER_SHARED]                                 = "user-shared",
45

46
        [SD_PATH_USER_CONFIGURATION]                          = "user-configuration",
47
        [SD_PATH_USER_RUNTIME]                                = "user-runtime",
48
        [SD_PATH_USER_STATE_CACHE]                            = "user-state-cache",
49
        [SD_PATH_USER_STATE_PRIVATE]                          = "user-state-private",
50

51
        [SD_PATH_USER]                                        = "user",
52
        [SD_PATH_USER_DOCUMENTS]                              = "user-documents",
53
        [SD_PATH_USER_MUSIC]                                  = "user-music",
54
        [SD_PATH_USER_PICTURES]                               = "user-pictures",
55
        [SD_PATH_USER_VIDEOS]                                 = "user-videos",
56
        [SD_PATH_USER_DOWNLOAD]                               = "user-download",
57
        [SD_PATH_USER_PUBLIC]                                 = "user-public",
58
        [SD_PATH_USER_TEMPLATES]                              = "user-templates",
59
        [SD_PATH_USER_DESKTOP]                                = "user-desktop",
60

61
        [SD_PATH_SEARCH_BINARIES]                             = "search-binaries",
62
        [SD_PATH_SEARCH_BINARIES_DEFAULT]                     = "search-binaries-default",
63
        [SD_PATH_SEARCH_LIBRARY_PRIVATE]                      = "search-library-private",
64
        [SD_PATH_SEARCH_LIBRARY_ARCH]                         = "search-library-arch",
65
        [SD_PATH_SEARCH_SHARED]                               = "search-shared",
66
        [SD_PATH_SEARCH_CONFIGURATION_FACTORY]                = "search-configuration-factory",
67
        [SD_PATH_SEARCH_STATE_FACTORY]                        = "search-state-factory",
68
        [SD_PATH_SEARCH_CONFIGURATION]                        = "search-configuration",
69

70
        [SD_PATH_SYSTEMD_UTIL]                                = "systemd-util",
71

72
        [SD_PATH_SYSTEMD_SYSTEM_UNIT]                         = "systemd-system-unit",
73
        [SD_PATH_SYSTEMD_SYSTEM_PRESET]                       = "systemd-system-preset",
74
        [SD_PATH_SYSTEMD_SYSTEM_CONF]                         = "systemd-system-conf",
75
        [SD_PATH_SYSTEMD_USER_UNIT]                           = "systemd-user-unit",
76
        [SD_PATH_SYSTEMD_USER_PRESET]                         = "systemd-user-preset",
77
        [SD_PATH_SYSTEMD_USER_CONF]                           = "systemd-user-conf",
78
        [SD_PATH_SYSTEMD_INITRD_PRESET]                       = "systemd-initrd-preset",
79

80
        [SD_PATH_SYSTEMD_SEARCH_SYSTEM_UNIT]                  = "systemd-search-system-unit",
81
        [SD_PATH_SYSTEMD_SEARCH_USER_UNIT]                    = "systemd-search-user-unit",
82

83
        [SD_PATH_SYSTEMD_SYSTEM_GENERATOR]                    = "systemd-system-generator",
84
        [SD_PATH_SYSTEMD_USER_GENERATOR]                      = "systemd-user-generator",
85
        [SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR]             = "systemd-search-system-generator",
86
        [SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR]               = "systemd-search-user-generator",
87

88
        [SD_PATH_SYSTEMD_SLEEP]                               = "systemd-sleep",
89
        [SD_PATH_SYSTEMD_SHUTDOWN]                            = "systemd-shutdown",
90

91
        [SD_PATH_TMPFILES]                                    = "tmpfiles",
92
        [SD_PATH_SYSUSERS]                                    = "sysusers",
93
        [SD_PATH_SYSCTL]                                      = "sysctl",
94
        [SD_PATH_BINFMT]                                      = "binfmt",
95
        [SD_PATH_MODULES_LOAD]                                = "modules-load",
96
        [SD_PATH_CATALOG]                                     = "catalog",
97

98
        [SD_PATH_SYSTEMD_SEARCH_NETWORK]                      = "systemd-search-network",
99

100
        [SD_PATH_SYSTEMD_SYSTEM_ENVIRONMENT_GENERATOR]        = "systemd-system-environment-generator",
101
        [SD_PATH_SYSTEMD_USER_ENVIRONMENT_GENERATOR]          = "systemd-user-environment-generator",
102
        [SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR] = "systemd-search-system-environment-generator",
103
        [SD_PATH_SYSTEMD_SEARCH_USER_ENVIRONMENT_GENERATOR]   = "systemd-search-user-environment-generator",
104

105
        [SD_PATH_SYSTEM_CREDENTIAL_STORE]                     = "system-credential-store",
106
        [SD_PATH_SYSTEM_SEARCH_CREDENTIAL_STORE]              = "system-search-credential-store",
107
        [SD_PATH_SYSTEM_CREDENTIAL_STORE_ENCRYPTED]           = "system-credential-store-encrypted",
108
        [SD_PATH_SYSTEM_SEARCH_CREDENTIAL_STORE_ENCRYPTED]    = "system-search-credential-store-encrypted",
109
        [SD_PATH_USER_CREDENTIAL_STORE]                       = "user-credential-store",
110
        [SD_PATH_USER_SEARCH_CREDENTIAL_STORE]                = "user-search-credential-store",
111
        [SD_PATH_USER_CREDENTIAL_STORE_ENCRYPTED]             = "user-credential-store-encrypted",
112
        [SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED]      = "user-search-credential-store-encrypted",
113
};
114

115
static int order_cmp(const size_t *a, const size_t *b) {
354✔
116
        assert(*a < ELEMENTSOF(path_table));
354✔
117
        assert(*b < ELEMENTSOF(path_table));
354✔
118
        return strcmp(path_table[*a], path_table[*b]);
354✔
119
}
120

121
static int list_paths(void) {
1✔
122
        int ret = 0, r;
1✔
123

124
        pager_open(arg_pager_flags);
1✔
125

126
        size_t order[ELEMENTSOF(path_table)];
127

128
        for (size_t i = 0; i < ELEMENTSOF(order); i++)
77✔
129
                order[i] = i;
76✔
130

131
        typesafe_qsort(order, ELEMENTSOF(order), order_cmp);
1✔
132

133
        for (size_t i = 0; i < ELEMENTSOF(order); i++) {
77✔
134
                size_t j = order[i];
76✔
135
                const char *t = ASSERT_PTR(path_table[j]);
76✔
136

137
                _cleanup_free_ char *p = NULL;
76✔
138
                r = sd_path_lookup(j, arg_suffix, &p);
76✔
139
                if (r < 0) {
76✔
140
                        log_full_errno(r == -ENXIO ? LOG_DEBUG : LOG_ERR, r, "Failed to query %s, proceeding: %m", t);
1✔
141
                        if (r != -ENXIO)
1✔
UNCOV
142
                                RET_GATHER(ret, r);
×
143
                        continue;
1✔
144
                }
145

146
                printf("%s%s:%s %s\n", ansi_highlight(), t, ansi_normal(), p);
150✔
147
        }
148

149
        return r;
1✔
150
}
151

152
static int print_path(const char *n) {
38✔
153
        int r;
38✔
154

155
        for (size_t i = 0; i < ELEMENTSOF(path_table); i++)
1,073✔
156
                if (streq(path_table[i], n)) {
1,071✔
157
                        _cleanup_free_ char *p = NULL;
36✔
158

159
                        r = sd_path_lookup(i, arg_suffix, &p);
36✔
160
                        if (r < 0)
36✔
UNCOV
161
                                return log_error_errno(r, "Failed to query %s: %m", n);
×
162

163
                        printf("%s\n", p);
36✔
164
                        return 0;
165
                }
166

167
        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
2✔
168
                               "Path %s not known.", n);
169
}
170

171
static int help(void) {
1✔
172
        _cleanup_free_ char *link = NULL;
1✔
173
        int r;
1✔
174

175
        r = terminal_urlify_man("systemd-path", "1", &link);
1✔
176
        if (r < 0)
1✔
UNCOV
177
                return log_oom();
×
178

179
        printf("%s [OPTIONS...] [NAME...]\n"
2✔
180
               "\n%sShow system and user paths.%s\n\n"
181
               "  -h --help             Show this help\n"
182
               "     --version          Show package version\n"
183
               "     --suffix=SUFFIX    Suffix to append to paths\n"
184
               "     --no-pager         Do not pipe output into a pager\n"
185
               "\nSee the %s for details.\n",
186
               program_invocation_short_name,
187
               ansi_highlight(),
188
               ansi_normal(),
189
               link);
190

191
        return 0;
192
}
193

194
static int parse_argv(int argc, char *argv[]) {
37✔
195
        enum {
37✔
196
                ARG_VERSION = 0x100,
197
                ARG_SUFFIX,
198
                ARG_NO_PAGER,
199
        };
200

201
        static const struct option options[] = {
37✔
202
                { "help",      no_argument,       NULL, 'h'           },
203
                { "version",   no_argument,       NULL, ARG_VERSION   },
204
                { "suffix",    required_argument, NULL, ARG_SUFFIX    },
205
                { "no-pager",  no_argument,       NULL, ARG_NO_PAGER  },
206
                {}
207
        };
208

209
        int c;
37✔
210

211
        assert(argc >= 0);
37✔
212
        assert(argv);
37✔
213

214
        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
44✔
215

216
                switch (c) {
10✔
217

218
                case 'h':
1✔
219
                        return help();
1✔
220

221
                case ARG_VERSION:
1✔
222
                        return version();
1✔
223

224
                case ARG_SUFFIX:
7✔
225
                        arg_suffix = optarg;
7✔
226
                        break;
7✔
227

228
                case ARG_NO_PAGER:
×
229
                        arg_pager_flags |= PAGER_DISABLE;
×
UNCOV
230
                        break;
×
231

232
                case '?':
233
                        return -EINVAL;
234

235
                default:
×
UNCOV
236
                        assert_not_reached();
×
237
                }
238

239
        return 1;
240
}
241

242
static int run(int argc, char* argv[]) {
37✔
243
        int r;
37✔
244

245
        log_setup();
37✔
246

247
        r = parse_argv(argc, argv);
37✔
248
        if (r <= 0)
37✔
249
                return r;
37✔
250

251
        if (argc > optind) {
34✔
252
                r = 0;
253
                for (int i = optind; i < argc; i++)
71✔
254
                        RET_GATHER(r, print_path(argv[i]));
38✔
255
        } else
256
                r = list_paths();
1✔
257

258
        return r;
259
}
260

261
DEFINE_MAIN_FUNCTION(run);
37✔
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