Compare commits
15 Commits
b3c41c9849
...
c77389e0c1
Author | SHA1 | Date |
---|---|---|
Mike Yuan | c77389e0c1 | |
Mike Yuan | 48cd3fe288 | |
Mike Yuan | 4b03d67466 | |
Mike Yuan | e417906b35 | |
Mike Yuan | 381d68ed39 | |
Mike Yuan | 4e534c9e62 | |
Mike Yuan | 452b13c3d4 | |
Mike Yuan | b47ab3f35b | |
Mike Yuan | 51d32424e8 | |
Mike Yuan | 25b99eb47d | |
Mike Yuan | f8e666759d | |
Mike Yuan | ee0c4f94d2 | |
Mike Yuan | 8300fa4dcf | |
Mike Yuan | 1c4c387071 | |
Mike Yuan | 3e40d55f09 |
|
@ -469,3 +469,30 @@ int conf_file_read(
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int find_portable_profile(const char *name, const char *unit, char **ret_path) {
|
||||||
|
const char *dot;
|
||||||
|
|
||||||
|
assert(name);
|
||||||
|
assert(ret_path);
|
||||||
|
|
||||||
|
assert_se(dot = strrchr(unit, '.'));
|
||||||
|
|
||||||
|
NULSTR_FOREACH(p, PORTABLE_PROFILE_DIRS) {
|
||||||
|
_cleanup_free_ char *joined = NULL;
|
||||||
|
|
||||||
|
joined = strjoin(p, "/", name, "/", dot + 1, ".conf");
|
||||||
|
if (!joined)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (laccess(joined, F_OK) >= 0) {
|
||||||
|
*ret_path = TAKE_PTR(joined);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errno != ENOENT)
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
|
@ -47,3 +47,9 @@ int conf_file_read(
|
||||||
void *userdata,
|
void *userdata,
|
||||||
bool ignore_enoent,
|
bool ignore_enoent,
|
||||||
bool *invalid_config);
|
bool *invalid_config);
|
||||||
|
|
||||||
|
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
|
||||||
|
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
|
||||||
|
|
||||||
|
#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
|
||||||
|
int find_portable_profile(const char *name, const char *unit, char **ret_path);
|
||||||
|
|
|
@ -70,7 +70,6 @@ basic_sources = files(
|
||||||
'ordered-set.c',
|
'ordered-set.c',
|
||||||
'os-util.c',
|
'os-util.c',
|
||||||
'parse-util.c',
|
'parse-util.c',
|
||||||
'path-lookup.c',
|
|
||||||
'path-util.c',
|
'path-util.c',
|
||||||
'percent-util.c',
|
'percent-util.c',
|
||||||
'pidref.c',
|
'pidref.c',
|
||||||
|
|
|
@ -181,7 +181,7 @@ static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
|
||||||
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
|
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = xdg_user_config_dir(&base, "/systemd");
|
r = xdg_user_config_dir("/systemd", &base);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -2478,7 +2478,7 @@ static int initialize_runtime(
|
||||||
/* Create the runtime directory and place the inaccessible device nodes there, if we run in
|
/* Create the runtime directory and place the inaccessible device nodes there, if we run in
|
||||||
* user mode. In system mode mount_setup() already did that. */
|
* user mode. In system mode mount_setup() already did that. */
|
||||||
|
|
||||||
r = xdg_user_runtime_dir(&p, "/systemd");
|
r = xdg_user_runtime_dir("/systemd", &base);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
*ret_error_message = "$XDG_RUNTIME_DIR is not set";
|
*ret_error_message = "$XDG_RUNTIME_DIR is not set";
|
||||||
return log_struct_errno(LOG_EMERG, r,
|
return log_struct_errno(LOG_EMERG, r,
|
||||||
|
|
|
@ -1031,7 +1031,7 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
|
||||||
r = mkdir_label("/run/systemd/units", 0755);
|
r = mkdir_label("/run/systemd/units", 0755);
|
||||||
else {
|
else {
|
||||||
_cleanup_free_ char *units_path = NULL;
|
_cleanup_free_ char *units_path = NULL;
|
||||||
r = xdg_user_runtime_dir(&units_path, "/systemd/units");
|
r = xdg_user_runtime_dir("/systemd/units", &units_path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
|
@ -5576,12 +5576,13 @@ static int unit_get_invocation_path(Unit *u, char **ret) {
|
||||||
p = strjoin("/run/systemd/units/invocation:", u->id);
|
p = strjoin("/run/systemd/units/invocation:", u->id);
|
||||||
else {
|
else {
|
||||||
_cleanup_free_ char *user_path = NULL;
|
_cleanup_free_ char *user_path = NULL;
|
||||||
r = xdg_user_runtime_dir(&user_path, "/systemd/units/invocation:");
|
|
||||||
|
r = xdg_user_runtime_dir("/systemd/units/invocation:", &user_path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
p = strjoin(user_path, u->id);
|
p = strjoin(user_path, u->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ sd_journal_sources += [audit_type_to_name]
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
id128_sources = files(
|
sd_id128_sources = files(
|
||||||
'sd-id128/id128-util.c',
|
'sd-id128/id128-util.c',
|
||||||
'sd-id128/sd-id128.c',
|
'sd-id128/sd-id128.c',
|
||||||
)
|
)
|
||||||
|
@ -62,6 +62,40 @@ sd_event_sources = files(
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
|
sd_bus_sources = files(
|
||||||
|
'sd-bus/bus-common-errors.c',
|
||||||
|
'sd-bus/bus-container.c',
|
||||||
|
'sd-bus/bus-control.c',
|
||||||
|
'sd-bus/bus-convenience.c',
|
||||||
|
'sd-bus/bus-creds.c',
|
||||||
|
'sd-bus/bus-dump.c',
|
||||||
|
'sd-bus/bus-error.c',
|
||||||
|
'sd-bus/bus-internal.c',
|
||||||
|
'sd-bus/bus-introspect.c',
|
||||||
|
'sd-bus/bus-kernel.c',
|
||||||
|
'sd-bus/bus-match.c',
|
||||||
|
'sd-bus/bus-message.c',
|
||||||
|
'sd-bus/bus-objects.c',
|
||||||
|
'sd-bus/bus-signature.c',
|
||||||
|
'sd-bus/bus-slot.c',
|
||||||
|
'sd-bus/bus-socket.c',
|
||||||
|
'sd-bus/bus-track.c',
|
||||||
|
'sd-bus/bus-type.c',
|
||||||
|
'sd-bus/sd-bus.c',
|
||||||
|
)
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
sd_device_sources = files(
|
||||||
|
'sd-device/device-enumerator.c',
|
||||||
|
'sd-device/device-filter.c',
|
||||||
|
'sd-device/device-monitor.c',
|
||||||
|
'sd-device/device-private.c',
|
||||||
|
'sd-device/device-util.c',
|
||||||
|
'sd-device/sd-device.c',
|
||||||
|
)
|
||||||
|
############################################################
|
||||||
|
|
||||||
sd_login_sources = files('sd-login/sd-login.c')
|
sd_login_sources = files('sd-login/sd-login.c')
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
@ -83,33 +117,14 @@ sd_varlink_sources = files(
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
libsystemd_sources = files(
|
sd_path_sources = files(
|
||||||
'sd-bus/bus-common-errors.c',
|
'sd-path/path-lookup.c',
|
||||||
'sd-bus/bus-container.c',
|
'sd-path/sd-path.c',
|
||||||
'sd-bus/bus-control.c',
|
)
|
||||||
'sd-bus/bus-convenience.c',
|
|
||||||
'sd-bus/bus-creds.c',
|
############################################################
|
||||||
'sd-bus/bus-dump.c',
|
|
||||||
'sd-bus/bus-error.c',
|
sd_netlink_sources = files(
|
||||||
'sd-bus/bus-internal.c',
|
|
||||||
'sd-bus/bus-introspect.c',
|
|
||||||
'sd-bus/bus-kernel.c',
|
|
||||||
'sd-bus/bus-match.c',
|
|
||||||
'sd-bus/bus-message.c',
|
|
||||||
'sd-bus/bus-objects.c',
|
|
||||||
'sd-bus/bus-signature.c',
|
|
||||||
'sd-bus/bus-slot.c',
|
|
||||||
'sd-bus/bus-socket.c',
|
|
||||||
'sd-bus/bus-track.c',
|
|
||||||
'sd-bus/bus-type.c',
|
|
||||||
'sd-bus/sd-bus.c',
|
|
||||||
'sd-device/device-enumerator.c',
|
|
||||||
'sd-device/device-filter.c',
|
|
||||||
'sd-device/device-monitor.c',
|
|
||||||
'sd-device/device-private.c',
|
|
||||||
'sd-device/device-util.c',
|
|
||||||
'sd-device/sd-device.c',
|
|
||||||
'sd-hwdb/sd-hwdb.c',
|
|
||||||
'sd-netlink/netlink-genl.c',
|
'sd-netlink/netlink-genl.c',
|
||||||
'sd-netlink/netlink-message-nfnl.c',
|
'sd-netlink/netlink-message-nfnl.c',
|
||||||
'sd-netlink/netlink-message-rtnl.c',
|
'sd-netlink/netlink-message-rtnl.c',
|
||||||
|
@ -122,11 +137,24 @@ libsystemd_sources = files(
|
||||||
'sd-netlink/netlink-types.c',
|
'sd-netlink/netlink-types.c',
|
||||||
'sd-netlink/netlink-util.c',
|
'sd-netlink/netlink-util.c',
|
||||||
'sd-netlink/sd-netlink.c',
|
'sd-netlink/sd-netlink.c',
|
||||||
|
)
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
sd_network_sources = files(
|
||||||
'sd-network/network-util.c',
|
'sd-network/network-util.c',
|
||||||
'sd-network/sd-network.c',
|
'sd-network/sd-network.c',
|
||||||
'sd-path/sd-path.c',
|
)
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
libsystemd_sources = files(
|
||||||
|
'sd-hwdb/sd-hwdb.c',
|
||||||
'sd-resolve/sd-resolve.c',
|
'sd-resolve/sd-resolve.c',
|
||||||
) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources + sd_json_sources + sd_varlink_sources
|
) + sd_journal_sources + sd_id128_sources + sd_daemon_sources \
|
||||||
|
+ sd_event_sources + sd_bus_sources + sd_device_sources \
|
||||||
|
+ sd_login_sources + sd_json_sources + sd_varlink_sources \
|
||||||
|
+ sd_path_sources + sd_netlink_sources + sd_network_sources
|
||||||
|
|
||||||
libsystemd_c_args = ['-fvisibility=default']
|
libsystemd_c_args = ['-fvisibility=default']
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "sd-path.h"
|
||||||
#include "macro.h"
|
|
||||||
#include "runtime-scope.h"
|
#include "runtime-scope.h"
|
||||||
|
|
||||||
typedef enum LookupPathsFlags {
|
typedef enum LookupPathsFlags {
|
||||||
|
@ -55,11 +55,21 @@ typedef struct LookupPaths {
|
||||||
int lookup_paths_init(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
int lookup_paths_init(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||||
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||||
|
|
||||||
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
|
int runtime_directory(RuntimeScope scope, const char *suffix, char **ret);
|
||||||
int xdg_user_runtime_dir(char **ret, const char *suffix);
|
|
||||||
int xdg_user_config_dir(char **ret, const char *suffix);
|
/* We don't treat /etc/xdg/systemd in these functions as the xdg base dir spec suggests because we assume
|
||||||
int xdg_user_data_dir(char **ret, const char *suffix);
|
* that is a link to /etc/systemd/ anyway. */
|
||||||
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix);
|
|
||||||
|
int user_search_dirs(const char *suffix, char ***ret_config_dirs, char ***ret_data_dirs);
|
||||||
|
static inline int xdg_user_runtime_dir(const char *suffix, char **ret) {
|
||||||
|
return sd_path_lookup(SD_PATH_USER_RUNTIME, suffix, ret);
|
||||||
|
}
|
||||||
|
static inline int xdg_user_config_dir(const char *suffix, char **ret) {
|
||||||
|
return sd_path_lookup(SD_PATH_USER_CONFIGURATION, suffix, ret);
|
||||||
|
}
|
||||||
|
static inline int xdg_user_data_dir(const char *suffix, char **ret) {
|
||||||
|
return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret);
|
||||||
|
}
|
||||||
|
|
||||||
bool path_is_user_data_dir(const char *path);
|
bool path_is_user_data_dir(const char *path);
|
||||||
bool path_is_user_config_dir(const char *path);
|
bool path_is_user_config_dir(const char *path);
|
||||||
|
@ -67,11 +77,10 @@ bool path_is_user_config_dir(const char *path);
|
||||||
void lookup_paths_log(LookupPaths *p);
|
void lookup_paths_log(LookupPaths *p);
|
||||||
void lookup_paths_done(LookupPaths *p);
|
void lookup_paths_done(LookupPaths *p);
|
||||||
|
|
||||||
char **generator_binary_paths(RuntimeScope scope);
|
char** generator_binary_paths_internal(RuntimeScope scope, bool env_generator);
|
||||||
char **env_generator_binary_paths(RuntimeScope scope);
|
static inline char** generator_binary_paths(RuntimeScope runtime_scope) {
|
||||||
|
return generator_binary_paths_internal(runtime_scope, false);
|
||||||
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
|
}
|
||||||
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
|
static inline char** env_generator_binary_paths(RuntimeScope runtime_scope) {
|
||||||
|
return generator_binary_paths_internal(runtime_scope, true);
|
||||||
#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
|
}
|
||||||
int find_portable_profile(const char *name, const char *unit, char **ret_path);
|
|
|
@ -65,26 +65,20 @@ static int from_home_dir(const char *envname, const char *suffix, char **buffer,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int from_user_dir(const char *field, char **buffer, const char **ret) {
|
static int from_xdg_user_dir(const char *field, char **buffer, const char **ret) {
|
||||||
|
_cleanup_free_ char *user_dirs = NULL;
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
_cleanup_free_ char *b = NULL;
|
|
||||||
_cleanup_free_ const char *fn = NULL;
|
|
||||||
const char *c = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(field);
|
assert(field);
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
r = from_home_dir("XDG_CONFIG_HOME", ".config", &b, &c);
|
r = sd_path_lookup(SD_PATH_USER_CONFIGURATION, "user-dirs.dirs", &user_dirs);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
fn = path_join(c, "user-dirs.dirs");
|
f = fopen(user_dirs, "re");
|
||||||
if (!fn)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
f = fopen(fn, "re");
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
goto fallback;
|
goto fallback;
|
||||||
|
@ -107,14 +101,12 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) {
|
||||||
if (!p)
|
if (!p)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
p += strspn(p, WHITESPACE);
|
p = skip_leading_chars(p, WHITESPACE);
|
||||||
|
|
||||||
if (*p != '=')
|
if (*p != '=')
|
||||||
continue;
|
continue;
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
p += strspn(p, WHITESPACE);
|
p = skip_leading_chars(p, WHITESPACE);
|
||||||
|
|
||||||
if (*p != '"')
|
if (*p != '"')
|
||||||
continue;
|
continue;
|
||||||
p++;
|
p++;
|
||||||
|
@ -125,62 +117,34 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) {
|
||||||
*e = 0;
|
*e = 0;
|
||||||
|
|
||||||
/* Three syntaxes permitted: relative to $HOME, $HOME itself, and absolute path */
|
/* Three syntaxes permitted: relative to $HOME, $HOME itself, and absolute path */
|
||||||
if (startswith(p, "$HOME/")) {
|
if (streq(p, "$HOME"))
|
||||||
_cleanup_free_ char *h = NULL;
|
goto home;
|
||||||
|
|
||||||
r = get_home_dir(&h);
|
const char *s = startswith(p, "$HOME/");
|
||||||
if (r < 0)
|
if (s)
|
||||||
return r;
|
return from_home_dir(/* envname = */ NULL, s, buffer, ret);
|
||||||
|
|
||||||
if (!path_extend(&h, p+5))
|
if (path_is_absolute(p)) {
|
||||||
|
char *c = strdup(p);
|
||||||
|
if (!c)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*buffer = h;
|
*buffer = *ret = c;
|
||||||
*ret = TAKE_PTR(h);
|
|
||||||
return 0;
|
|
||||||
} else if (streq(p, "$HOME")) {
|
|
||||||
|
|
||||||
r = get_home_dir(buffer);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
*ret = *buffer;
|
|
||||||
return 0;
|
|
||||||
} else if (path_is_absolute(p)) {
|
|
||||||
char *copy;
|
|
||||||
|
|
||||||
copy = strdup(p);
|
|
||||||
if (!copy)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
*buffer = copy;
|
|
||||||
*ret = copy;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fallback:
|
fallback:
|
||||||
/* The desktop directory defaults to $HOME/Desktop, the others to $HOME */
|
/* The desktop directory defaults to $HOME/Desktop, the others to $HOME */
|
||||||
if (streq(field, "XDG_DESKTOP_DIR")) {
|
if (streq(field, "XDG_DESKTOP_DIR"))
|
||||||
_cleanup_free_ char *h = NULL;
|
return from_home_dir(/* envname = */ NULL, "Desktop", buffer, ret);
|
||||||
|
|
||||||
r = get_home_dir(&h);
|
home:
|
||||||
if (r < 0)
|
r = get_home_dir(buffer);
|
||||||
return r;
|
if (r < 0)
|
||||||
|
return r;
|
||||||
if (!path_extend(&h, "Desktop"))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
*buffer = h;
|
|
||||||
*ret = TAKE_PTR(h);
|
|
||||||
} else {
|
|
||||||
r = get_home_dir(buffer);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
*ret = *buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
*ret = *buffer;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,28 +251,28 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case SD_PATH_USER_DOCUMENTS:
|
case SD_PATH_USER_DOCUMENTS:
|
||||||
return from_user_dir("XDG_DOCUMENTS_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_DOCUMENTS_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_MUSIC:
|
case SD_PATH_USER_MUSIC:
|
||||||
return from_user_dir("XDG_MUSIC_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_MUSIC_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_PICTURES:
|
case SD_PATH_USER_PICTURES:
|
||||||
return from_user_dir("XDG_PICTURES_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_PICTURES_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_VIDEOS:
|
case SD_PATH_USER_VIDEOS:
|
||||||
return from_user_dir("XDG_VIDEOS_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_VIDEOS_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_DOWNLOAD:
|
case SD_PATH_USER_DOWNLOAD:
|
||||||
return from_user_dir("XDG_DOWNLOAD_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_DOWNLOAD_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_PUBLIC:
|
case SD_PATH_USER_PUBLIC:
|
||||||
return from_user_dir("XDG_PUBLICSHARE_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_PUBLICSHARE_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_TEMPLATES:
|
case SD_PATH_USER_TEMPLATES:
|
||||||
return from_user_dir("XDG_TEMPLATES_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_TEMPLATES_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_USER_DESKTOP:
|
case SD_PATH_USER_DESKTOP:
|
||||||
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret);
|
return from_xdg_user_dir("XDG_DESKTOP_DIR", buffer, ret);
|
||||||
|
|
||||||
case SD_PATH_SYSTEMD_UTIL:
|
case SD_PATH_SYSTEMD_UTIL:
|
||||||
*ret = PREFIX_NOSLASH "/lib/systemd";
|
*ret = PREFIX_NOSLASH "/lib/systemd";
|
||||||
|
@ -390,55 +354,56 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_path_alloc(uint64_t type, const char *suffix, char **path) {
|
static int get_path_alloc(uint64_t type, const char *suffix, char **ret) {
|
||||||
_cleanup_free_ char *buffer = NULL;
|
_cleanup_free_ char *buffer = NULL;
|
||||||
char *buffer2 = NULL;
|
const char *p;
|
||||||
const char *ret;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(path);
|
assert(ret);
|
||||||
|
|
||||||
r = get_path(type, &buffer, &ret);
|
r = get_path(type, &buffer, &p);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
suffix += strspn(suffix, "/");
|
char *suffixed = path_join(p, suffix);
|
||||||
buffer2 = path_join(ret, suffix);
|
if (!suffixed)
|
||||||
if (!buffer2)
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
path_simplify(suffixed);
|
||||||
|
|
||||||
|
free_and_replace(buffer, suffixed);
|
||||||
} else if (!buffer) {
|
} else if (!buffer) {
|
||||||
buffer = strdup(ret);
|
buffer = strdup(p);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
*path = buffer2 ?: TAKE_PTR(buffer);
|
*ret = TAKE_PTR(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) {
|
_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **ret) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_return(path, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
|
|
||||||
r = get_path_alloc(type, suffix, path);
|
r = get_path_alloc(type, suffix, ret);
|
||||||
if (r != -EOPNOTSUPP)
|
if (r != -EOPNOTSUPP)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
/* Fall back to sd_path_lookup_strv */
|
/* Fall back to sd_path_lookup_strv */
|
||||||
_cleanup_strv_free_ char **l = NULL;
|
_cleanup_strv_free_ char **l = NULL;
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
r = sd_path_lookup_strv(type, suffix, &l);
|
r = sd_path_lookup_strv(type, suffix, &l);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
buffer = strv_join(l, ":");
|
char *joined = strv_join(l, ":");
|
||||||
if (!buffer)
|
if (!joined)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*path = buffer;
|
*ret = joined;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,25 +580,16 @@ static int get_search(uint64_t type, char ***ret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR:
|
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR:
|
||||||
case SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR: {
|
case SD_PATH_SYSTEMD_SEARCH_USER_GENERATOR:
|
||||||
RuntimeScope scope = type == SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR ?
|
|
||||||
RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER;
|
|
||||||
char **t;
|
|
||||||
|
|
||||||
t = generator_binary_paths(scope);
|
|
||||||
if (!t)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
*ret = t;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR:
|
case SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR:
|
||||||
case SD_PATH_SYSTEMD_SEARCH_USER_ENVIRONMENT_GENERATOR: {
|
case SD_PATH_SYSTEMD_SEARCH_USER_ENVIRONMENT_GENERATOR: {
|
||||||
char **t;
|
RuntimeScope scope = IN_SET(type, SD_PATH_SYSTEMD_SEARCH_SYSTEM_GENERATOR,
|
||||||
|
SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR) ?
|
||||||
|
RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER;
|
||||||
|
bool env_generator = IN_SET(type, SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR,
|
||||||
|
SD_PATH_SYSTEMD_SEARCH_USER_ENVIRONMENT_GENERATOR);
|
||||||
|
|
||||||
t = env_generator_binary_paths(type == SD_PATH_SYSTEMD_SEARCH_SYSTEM_ENVIRONMENT_GENERATOR ?
|
char **t = generator_binary_paths_internal(scope, env_generator);
|
||||||
RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER);
|
|
||||||
if (!t)
|
if (!t)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -649,11 +605,11 @@ static int get_search(uint64_t type, char ***ret) {
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) {
|
_public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***ret) {
|
||||||
_cleanup_strv_free_ char **l = NULL, **n = NULL;
|
_cleanup_strv_free_ char **l = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_return(paths, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
|
|
||||||
r = get_search(type, &l);
|
r = get_search(type, &l);
|
||||||
if (r == -EOPNOTSUPP) {
|
if (r == -EOPNOTSUPP) {
|
||||||
|
@ -669,31 +625,20 @@ _public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***path
|
||||||
l[0] = TAKE_PTR(t);
|
l[0] = TAKE_PTR(t);
|
||||||
l[1] = NULL;
|
l[1] = NULL;
|
||||||
|
|
||||||
*paths = TAKE_PTR(l);
|
*ret = TAKE_PTR(l);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
} else if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!suffix) {
|
if (suffix)
|
||||||
*paths = TAKE_PTR(l);
|
STRV_FOREACH(i, l) {
|
||||||
return 0;
|
if (!path_extend(i, suffix))
|
||||||
}
|
return -ENOMEM;
|
||||||
|
|
||||||
n = new(char*, strv_length(l)+1);
|
path_simplify(*i);
|
||||||
if (!n)
|
}
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
char **j = n;
|
*ret = TAKE_PTR(l);
|
||||||
STRV_FOREACH(i, l) {
|
|
||||||
*j = path_join(*i, suffix);
|
|
||||||
if (!*j)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
*j = NULL;
|
|
||||||
|
|
||||||
*paths = TAKE_PTR(n);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,8 +123,8 @@ enum {
|
||||||
_SD_PATH_MAX
|
_SD_PATH_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
int sd_path_lookup(uint64_t type, const char *suffix, char **path);
|
int sd_path_lookup(uint64_t type, const char *suffix, char **ret);
|
||||||
int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths);
|
int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***ret);
|
||||||
|
|
||||||
_SD_END_DECLARATIONS;
|
_SD_END_DECLARATIONS;
|
||||||
|
|
||||||
|
|
|
@ -347,49 +347,35 @@ static int log_unresolvable_specifier(const char *filename, unsigned line) {
|
||||||
arg_dry_run ? (would) : (doing), \
|
arg_dry_run ? (would) : (doing), \
|
||||||
__VA_ARGS__)
|
__VA_ARGS__)
|
||||||
|
|
||||||
static int user_config_paths(char*** ret) {
|
static int user_config_paths(char ***ret) {
|
||||||
_cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
|
_cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
|
||||||
_cleanup_free_ char *persistent_config = NULL, *runtime_config = NULL, *data_home = NULL;
|
_cleanup_free_ char *runtime_config = NULL;
|
||||||
_cleanup_strv_free_ char **res = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = xdg_user_dirs(&config_dirs, &data_dirs);
|
assert(ret);
|
||||||
|
|
||||||
|
/* Combined user-specific and global dirs */
|
||||||
|
r = user_search_dirs("/user-tmpfiles.d", &config_dirs, &data_dirs);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = xdg_user_config_dir(&persistent_config, "/user-tmpfiles.d");
|
r = xdg_user_runtime_dir("/user-tmpfiles.d", &runtime_config);
|
||||||
if (r < 0 && !ERRNO_IS_NOINFO(r))
|
if (r < 0 && !ERRNO_IS_NEG_NOINFO(r))
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = xdg_user_runtime_dir(&runtime_config, "/user-tmpfiles.d");
|
r = strv_consume(&config_dirs, TAKE_PTR(runtime_config));
|
||||||
if (r < 0 && !ERRNO_IS_NOINFO(r))
|
|
||||||
return r;
|
|
||||||
|
|
||||||
r = xdg_user_data_dir(&data_home, "/user-tmpfiles.d");
|
|
||||||
if (r < 0 && !ERRNO_IS_NOINFO(r))
|
|
||||||
return r;
|
|
||||||
|
|
||||||
r = strv_extend_strv_concat(&res, (const char* const*) config_dirs, "/user-tmpfiles.d");
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = strv_extend_many(
|
r = strv_extend_strv(&config_dirs, data_dirs, /* filter_duplicates = */ true);
|
||||||
&res,
|
|
||||||
persistent_config,
|
|
||||||
runtime_config,
|
|
||||||
data_home);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = strv_extend_strv_concat(&res, (const char* const*) data_dirs, "/user-tmpfiles.d");
|
r = path_strv_make_absolute_cwd(config_dirs);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = path_strv_make_absolute_cwd(res);
|
*ret = TAKE_PTR(config_dirs);
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(res);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ static int get_firmware_search_dirs(char ***ret) {
|
||||||
* Prioritising entries in "more specific" directories */
|
* Prioritising entries in "more specific" directories */
|
||||||
|
|
||||||
_cleanup_free_ char *user_firmware_dir = NULL;
|
_cleanup_free_ char *user_firmware_dir = NULL;
|
||||||
r = xdg_user_config_dir(&user_firmware_dir, "/qemu/firmware");
|
r = xdg_user_config_dir("/qemu/firmware", &user_firmware_dir);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
|
@ -1488,11 +1488,11 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
||||||
|
|
||||||
/* if we are going to be starting any units with state then create our runtime dir */
|
/* if we are going to be starting any units with state then create our runtime dir */
|
||||||
if (arg_tpm != 0 || arg_directory || arg_runtime_mounts.n_mounts != 0) {
|
if (arg_tpm != 0 || arg_directory || arg_runtime_mounts.n_mounts != 0) {
|
||||||
r = runtime_directory(&arg_runtime_directory, arg_privileged ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER, "systemd/vmspawn");
|
r = runtime_directory(arg_privileged ? RUNTIME_SCOPE_SYSTEM : RUNTIME_SCOPE_USER, "systemd/vmspawn",
|
||||||
|
&arg_runtime_directory);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to lookup runtime directory: %m");
|
return log_error_errno(r, "Failed to lookup runtime directory: %m");
|
||||||
if (r) {
|
if (r > 0) { /* We need to create our own runtime dir */
|
||||||
/* r > 0 means we need to create our own runtime dir */
|
|
||||||
r = mkdir_p(arg_runtime_directory, 0755);
|
r = mkdir_p(arg_runtime_directory, 0755);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to create runtime directory: %m");
|
return log_error_errno(r, "Failed to create runtime directory: %m");
|
||||||
|
|
|
@ -20,6 +20,39 @@
|
||||||
|
|
||||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(xdgautostartservice_hash_ops, char, string_hash_func, string_compare_func, XdgAutostartService, xdg_autostart_service_free);
|
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(xdgautostartservice_hash_ops, char, string_hash_func, string_compare_func, XdgAutostartService, xdg_autostart_service_free);
|
||||||
|
|
||||||
|
static int xdg_base_dirs(char ***ret_config_dirs, char ***ret_data_dirs) {
|
||||||
|
_cleanup_strv_free_ char **config_dirs = NULL, **data_dirs = NULL;
|
||||||
|
const char *e;
|
||||||
|
|
||||||
|
/* Implement the mechanisms defined in
|
||||||
|
* https://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html */
|
||||||
|
|
||||||
|
assert(ret_config_dirs);
|
||||||
|
assert(ret_data_dirs);
|
||||||
|
|
||||||
|
e = getenv("XDG_CONFIG_DIRS");
|
||||||
|
if (e)
|
||||||
|
config_dirs = strv_split(e, ":");
|
||||||
|
else
|
||||||
|
config_dirs = strv_new("/etc/xdg");
|
||||||
|
if (!config_dirs)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
e = getenv("XDG_DATA_DIRS");
|
||||||
|
if (e)
|
||||||
|
data_dirs = strv_split(e, ":");
|
||||||
|
else
|
||||||
|
data_dirs = strv_new("/usr/local/share",
|
||||||
|
"/usr/share");
|
||||||
|
if (!data_dirs)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
*ret_config_dirs = TAKE_PTR(config_dirs);
|
||||||
|
*ret_data_dirs = TAKE_PTR(data_dirs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int enumerate_xdg_autostart(Hashmap *all_services) {
|
static int enumerate_xdg_autostart(Hashmap *all_services) {
|
||||||
_cleanup_strv_free_ char **autostart_dirs = NULL;
|
_cleanup_strv_free_ char **autostart_dirs = NULL;
|
||||||
_cleanup_strv_free_ char **config_dirs = NULL;
|
_cleanup_strv_free_ char **config_dirs = NULL;
|
||||||
|
@ -27,14 +60,14 @@ static int enumerate_xdg_autostart(Hashmap *all_services) {
|
||||||
_cleanup_free_ char *user_config_autostart_dir = NULL;
|
_cleanup_free_ char *user_config_autostart_dir = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = xdg_user_config_dir(&user_config_autostart_dir, "/autostart");
|
r = xdg_user_config_dir("/autostart", &user_config_autostart_dir);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
r = strv_extend(&autostart_dirs, user_config_autostart_dir);
|
r = strv_extend(&autostart_dirs, user_config_autostart_dir);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = xdg_user_dirs(&config_dirs, &data_dirs);
|
r = xdg_base_dirs(&config_dirs, &data_dirs);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
r = strv_extend_strv_concat(&autostart_dirs, (const char* const*) config_dirs, "/autostart");
|
r = strv_extend_strv_concat(&autostart_dirs, (const char* const*) config_dirs, "/autostart");
|
||||||
|
|
Loading…
Reference in New Issue