Coverage Report

Created: 2024-01-17 17:11

/src/systemd/src/basic/path-lookup.h
Line
Count
Source
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3
4
#include <stdbool.h>
5
6
#include "def.h"
7
#include "macro.h"
8
9
typedef enum LookupPathsFlags {
10
        LOOKUP_PATHS_EXCLUDE_GENERATED   = 1 << 0,
11
        LOOKUP_PATHS_TEMPORARY_GENERATED = 1 << 1,
12
        LOOKUP_PATHS_SPLIT_USR           = 1 << 2,
13
} LookupPathsFlags;
14
15
typedef enum LookupScope {
16
        LOOKUP_SCOPE_SYSTEM,
17
        LOOKUP_SCOPE_GLOBAL,
18
        LOOKUP_SCOPE_USER,
19
        _LOOKUP_SCOPE_MAX,
20
        _LOOKUP_SCOPE_INVALID = -EINVAL,
21
} LookupScope;
22
23
typedef struct LookupPaths {
24
        /* Where we look for unit files. This includes the individual special paths below, but also any vendor
25
         * supplied, static unit file paths. */
26
        char **search_path;
27
28
        /* Where we shall create or remove our installation symlinks, aka "configuration", and where the user/admin
29
         * shall place their own unit files. */
30
        char *persistent_config;
31
        char *runtime_config;
32
33
        /* Where units from a portable service image shall be placed. */
34
        char *persistent_attached;
35
        char *runtime_attached;
36
37
        /* Where to place generated unit files (i.e. those a "generator" tool generated). Note the special semantics of
38
         * this directory: the generators are flushed each time a "systemctl daemon-reload" is issued. The user should
39
         * not alter these directories directly. */
40
        char *generator;
41
        char *generator_early;
42
        char *generator_late;
43
44
        /* Where to place transient unit files (i.e. those created dynamically via the bus API). Note the special
45
         * semantics of this directory: all units created transiently have their unit files removed as the transient
46
         * unit is unloaded. The user should not alter this directory directly. */
47
        char *transient;
48
49
        /* Where the snippets created by "systemctl set-property" are placed. Note that for transient units, the
50
         * snippets are placed in the transient directory though (see above). The user should not alter this directory
51
         * directly. */
52
        char *persistent_control;
53
        char *runtime_control;
54
55
        /* The root directory prepended to all items above, or NULL */
56
        char *root_dir;
57
58
        /* A temporary directory when running in test mode, to be nuked */
59
        char *temporary_dir;
60
} LookupPaths;
61
62
int lookup_paths_init(LookupPaths *lp, LookupScope scope, LookupPathsFlags flags, const char *root_dir);
63
int lookup_paths_init_or_warn(LookupPaths *lp, LookupScope scope, LookupPathsFlags flags, const char *root_dir);
64
65
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
66
int xdg_user_runtime_dir(char **ret, const char *suffix);
67
int xdg_user_config_dir(char **ret, const char *suffix);
68
int xdg_user_data_dir(char **ret, const char *suffix);
69
70
bool path_is_user_data_dir(const char *path);
71
bool path_is_user_config_dir(const char *path);
72
73
void lookup_paths_log(LookupPaths *p);
74
void lookup_paths_free(LookupPaths *p);
75
76
char **generator_binary_paths(LookupScope scope);
77
char **env_generator_binary_paths(bool is_system);
78
79
14.5k
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
80
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
81
82
#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
83
int find_portable_profile(const char *name, const char *unit, char **ret_path);