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

systemd / systemd / 15079507752

16 May 2025 10:18PM UTC coverage: 72.276% (+0.009%) from 72.267%
15079507752

push

github

YHNdnzj
sd-bus: drop a bunch of 'else'

With the new US taxes on bits and bytes let's reduce our footprint a
bit.

11 of 19 new or added lines in 1 file covered. (57.89%)

4028 existing lines in 76 files now uncovered.

298564 of 413090 relevant lines covered (72.28%)

700985.27 hits per line

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

88.57
/src/path/path.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

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

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

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

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

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

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

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

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

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

123
        pager_open(arg_pager_flags);
1✔
124

125
        size_t order[ELEMENTSOF(path_table)];
126

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

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

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

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

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

148
        return r;
1✔
149
}
150

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

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

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

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

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

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

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

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

190
        return 0;
191
}
192

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

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

208
        int c;
37✔
209

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

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

215
                switch (c) {
10✔
216

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

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

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

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

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

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

238
        return 1;
239
}
240

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

244
        log_setup();
37✔
245

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

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

257
        return r;
258
}
259

260
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