nspawn: support .nspawn files in per-user mode
This commit is contained in:
+44
-21
@@ -18,6 +18,7 @@
|
||||
#include "sd-event.h"
|
||||
#include "sd-id128.h"
|
||||
#include "sd-netlink.h"
|
||||
#include "sd-path.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "barrier.h"
|
||||
@@ -4936,30 +4937,49 @@ static int load_settings(void) {
|
||||
if (FLAGS_SET(arg_settings_mask, _SETTINGS_MASK_ALL))
|
||||
return 0;
|
||||
|
||||
/* We first look in the admin's directories in /etc and /run */
|
||||
if (arg_privileged)
|
||||
FOREACH_STRING(i, "/etc/systemd/nspawn", "/run/systemd/nspawn") {
|
||||
_cleanup_free_ char *j = NULL;
|
||||
/* We first look in the admin's directories in /etc/ and /run/ */
|
||||
static const uint64_t lookup_dir_system[] = {
|
||||
SD_PATH_SYSTEM_CONFIGURATION,
|
||||
SD_PATH_SYSTEM_RUNTIME,
|
||||
_SD_PATH_INVALID,
|
||||
};
|
||||
static const uint64_t lookup_dir_user[] = {
|
||||
SD_PATH_USER_CONFIGURATION,
|
||||
SD_PATH_USER_RUNTIME,
|
||||
_SD_PATH_INVALID,
|
||||
};
|
||||
|
||||
j = path_join(i, arg_settings_filename);
|
||||
if (!j)
|
||||
return log_oom();
|
||||
|
||||
f = fopen(j, "re");
|
||||
if (f) {
|
||||
p = TAKE_PTR(j);
|
||||
|
||||
/* By default, we trust configuration from /etc and /run */
|
||||
if (arg_settings_trusted < 0)
|
||||
arg_settings_trusted = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (errno != ENOENT)
|
||||
return log_error_errno(errno, "Failed to open %s: %m", j);
|
||||
const uint64_t *q = arg_privileged ? lookup_dir_system : lookup_dir_user;
|
||||
for (; *q != _SD_PATH_INVALID; q++) {
|
||||
_cleanup_free_ char *cd = NULL;
|
||||
r = sd_path_lookup(*q, "systemd/nspawn", &cd);
|
||||
if (r < 0) {
|
||||
log_warning_errno(r, "Failed to determine settings directory, ignoring: %m");
|
||||
continue;
|
||||
}
|
||||
|
||||
_cleanup_free_ char *j = NULL;
|
||||
j = path_join(cd, arg_settings_filename);
|
||||
if (!j)
|
||||
return log_oom();
|
||||
|
||||
f = fopen(j, "re");
|
||||
if (f) {
|
||||
p = TAKE_PTR(j);
|
||||
|
||||
log_debug("Found settings file: %s", p);
|
||||
|
||||
/* By default, we trust configuration from /etc and /run */
|
||||
if (arg_settings_trusted < 0)
|
||||
arg_settings_trusted = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (errno != ENOENT)
|
||||
return log_error_errno(errno, "Failed to open %s: %m", j);
|
||||
}
|
||||
|
||||
if (!f) {
|
||||
/* After that, let's look for a file next to the
|
||||
* actual image we shall boot. */
|
||||
@@ -4979,6 +4999,9 @@ static int load_settings(void) {
|
||||
if (!f && errno != ENOENT)
|
||||
return log_error_errno(errno, "Failed to open %s: %m", p);
|
||||
|
||||
if (f)
|
||||
log_debug("Found settings file: %s", p);
|
||||
|
||||
/* By default, we do not trust configuration from /var/lib/machines */
|
||||
if (arg_settings_trusted < 0)
|
||||
arg_settings_trusted = false;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
_SD_BEGIN_DECLARATIONS;
|
||||
|
||||
enum {
|
||||
__extension__ enum {
|
||||
/* Temporary files */
|
||||
SD_PATH_TEMPORARY,
|
||||
SD_PATH_TEMPORARY_LARGE,
|
||||
@@ -129,7 +129,8 @@ enum {
|
||||
SD_PATH_USER_CREDENTIAL_STORE_ENCRYPTED,
|
||||
SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED,
|
||||
|
||||
_SD_PATH_MAX
|
||||
_SD_PATH_MAX,
|
||||
_SD_PATH_INVALID = UINT64_MAX
|
||||
};
|
||||
|
||||
int sd_path_lookup(uint64_t type, const char *suffix, char **ret);
|
||||
|
||||
Reference in New Issue
Block a user