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

systemd / systemd / 19282013399

12 Nov 2025 12:00AM UTC coverage: 72.412% (+0.01%) from 72.402%
19282013399

push

github

web-flow
core/exec-credentials: port to new mount API, ensure atomicity for creds installation (#39637)

103 of 137 new or added lines in 4 files covered. (75.18%)

850 existing lines in 45 files now uncovered.

307170 of 424195 relevant lines covered (72.41%)

1105108.57 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
        [SD_PATH_SEARCH_SYSCTL]                               = "search-sysctl",
70

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

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

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

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

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

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

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

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

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

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

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

125
        pager_open(arg_pager_flags);
1✔
126

127
        size_t order[ELEMENTSOF(path_table)];
128

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

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

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

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

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

150
        return ret;
1✔
151
}
152

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

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

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

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

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

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

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

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

192
        return 0;
193
}
194

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

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

210
        int c;
37✔
211

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

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

217
                switch (c) {
10✔
218

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

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

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

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

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

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

240
        return 1;
241
}
242

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

246
        log_setup();
37✔
247

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

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

259
        return r;
260
}
261

262
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