mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
path-lookup: modernize runtime_directory() too
This commit is contained in:
parent
60cd6deb06
commit
8cff087d27
@ -17,16 +17,15 @@
|
|||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
#include "user-util.h"
|
#include "user-util.h"
|
||||||
|
|
||||||
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
|
int runtime_directory(RuntimeScope scope, const char *suffix, char **ret) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(ret);
|
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER));
|
||||||
assert(suffix);
|
assert(suffix);
|
||||||
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, RUNTIME_SCOPE_GLOBAL));
|
assert(ret);
|
||||||
|
|
||||||
/* Accept $RUNTIME_DIRECTORY as authoritative
|
/* Accept $RUNTIME_DIRECTORY as authoritative
|
||||||
* If its missing apply the suffix to /run or $XDG_RUNTIME_DIR
|
* If it's missing, apply the suffix to /run/, or $XDG_RUNTIME_DIR if we are in a user runtime scope.
|
||||||
* if we are in a user runtime scope.
|
|
||||||
*
|
*
|
||||||
* Return value indicates whether the suffix was applied or not */
|
* Return value indicates whether the suffix was applied or not */
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
|
|||||||
*ret = d;
|
*ret = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* const user_data_unit_paths[] = {
|
static const char* const user_data_unit_paths[] = {
|
||||||
|
@ -58,6 +58,8 @@ int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFl
|
|||||||
void lookup_paths_log(LookupPaths *p);
|
void lookup_paths_log(LookupPaths *p);
|
||||||
void lookup_paths_done(LookupPaths *p);
|
void lookup_paths_done(LookupPaths *p);
|
||||||
|
|
||||||
|
int runtime_directory(RuntimeScope scope, const char *suffix, char **ret);
|
||||||
|
|
||||||
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
|
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
|
||||||
|
|
||||||
/* We don't treat /etc/xdg/systemd/ in these functions as the xdg base dir spec suggests because we assume
|
/* We don't treat /etc/xdg/systemd/ in these functions as the xdg base dir spec suggests because we assume
|
||||||
@ -72,7 +74,6 @@ static inline int xdg_user_config_dir(const char *suffix, char **ret) {
|
|||||||
static inline int xdg_user_data_dir(const char *suffix, char **ret) {
|
static inline int xdg_user_data_dir(const char *suffix, char **ret) {
|
||||||
return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret);
|
return sd_path_lookup(SD_PATH_USER_SHARED, suffix, ret);
|
||||||
}
|
}
|
||||||
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user