mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Merge pull request #24294 from rphibel/add-support-for-list-of-definitions-directories
repart: add support for list of definitions directories
This commit is contained in:
commit
be6c89b8f1
@ -71,7 +71,9 @@
|
||||
|
||||
<orderedlist>
|
||||
<listitem><para>The <filename>repart.d/*.conf</filename> configuration files are loaded and parsed,
|
||||
and ordered by filename (without the directory prefix).</para></listitem>
|
||||
and ordered by filename (without the directory prefix). For each configuration file,
|
||||
drop-in files are looked for in directories with same name as the configuration file
|
||||
with a suffix ".d" added.</para></listitem>
|
||||
|
||||
<listitem><para>The partition table already existing on the block device is loaded and
|
||||
parsed.</para></listitem>
|
||||
@ -293,7 +295,9 @@
|
||||
<listitem><para>Takes a file system path. If specified the <filename>*.conf</filename> files are read
|
||||
from the specified directory instead of searching in <filename>/usr/lib/repart.d/*.conf</filename>,
|
||||
<filename>/etc/repart.d/*.conf</filename>,
|
||||
<filename>/run/repart.d/*.conf</filename>.</para></listitem>
|
||||
<filename>/run/repart.d/*.conf</filename>.</para>
|
||||
|
||||
<para>This parameter can be specified multiple times.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
|
@ -95,7 +95,7 @@ static bool arg_dry_run = true;
|
||||
static const char *arg_node = NULL;
|
||||
static char *arg_root = NULL;
|
||||
static char *arg_image = NULL;
|
||||
static char *arg_definitions = NULL;
|
||||
static char **arg_definitions = NULL;
|
||||
static bool arg_discard = true;
|
||||
static bool arg_can_factory_reset = false;
|
||||
static int arg_factory_reset = -1;
|
||||
@ -114,7 +114,7 @@ static uint32_t arg_tpm2_pcr_mask = UINT32_MAX;
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_definitions, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_definitions, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_key, erase_and_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_tpm2_device, freep);
|
||||
|
||||
@ -1404,7 +1404,7 @@ static int partition_read_definition(Partition *p, const char *path, const char
|
||||
|
||||
static int context_read_definitions(
|
||||
Context *context,
|
||||
const char *directory,
|
||||
char **directories,
|
||||
const char *root) {
|
||||
|
||||
_cleanup_strv_free_ char **files = NULL;
|
||||
@ -1414,11 +1414,9 @@ static int context_read_definitions(
|
||||
|
||||
assert(context);
|
||||
|
||||
dirs = directory ?
|
||||
STRV_MAKE_CONST(directory) :
|
||||
(const char* const*)CONF_PATHS_STRV("repart.d");
|
||||
dirs = (const char* const*) (directories ?: CONF_PATHS_STRV("repart.d"));
|
||||
|
||||
r = conf_files_list_strv(&files, ".conf", directory ? NULL : root, CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, dirs);
|
||||
r = conf_files_list_strv(&files, ".conf", directories ? NULL : root, CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, dirs);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate *.conf files: %m");
|
||||
|
||||
@ -4281,11 +4279,15 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
arg_pretty = r;
|
||||
break;
|
||||
|
||||
case ARG_DEFINITIONS:
|
||||
r = parse_path_argument(optarg, false, &arg_definitions);
|
||||
case ARG_DEFINITIONS: {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
r = parse_path_argument(optarg, false, &path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (strv_consume(&arg_definitions, TAKE_PTR(path)) < 0)
|
||||
return log_oom();
|
||||
break;
|
||||
}
|
||||
|
||||
case ARG_SIZE: {
|
||||
uint64_t parsed, rounded;
|
||||
@ -4904,6 +4906,8 @@ static int run(int argc, char *argv[]) {
|
||||
if (!context)
|
||||
return log_oom();
|
||||
|
||||
strv_uniq(arg_definitions);
|
||||
|
||||
r = context_read_definitions(context, arg_definitions, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -272,3 +272,60 @@ diff <(echo "$JSON_OUTPUT") - <<EOF
|
||||
}
|
||||
]
|
||||
EOF
|
||||
|
||||
echo "### Testing list of definitions directories ###"
|
||||
|
||||
mkdir -p "$D/definitions1"
|
||||
|
||||
cat >"$D/definitions1/root1.conf" <<EOF
|
||||
[Partition]
|
||||
Type=swap
|
||||
SizeMaxBytes=32M
|
||||
UUID=7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0
|
||||
Label=label1
|
||||
EOF
|
||||
|
||||
mkdir -p "$D/definitions2"
|
||||
|
||||
cat >"$D/definitions2/root2.conf" <<EOF
|
||||
[Partition]
|
||||
Type=swap
|
||||
SizeMaxBytes=32M
|
||||
UUID=837c3d67-21b3-478e-be82-7e7f83bf96d3
|
||||
Label=label2
|
||||
EOF
|
||||
|
||||
rm -f test-definitions
|
||||
|
||||
JSON_OUTPUT=$("$repart" --definitions="$D/definitions1" --definitions="$D/definitions2" --dry-run=yes --empty=create --size=100M --json=pretty test-definitions)
|
||||
|
||||
diff <(echo "$JSON_OUTPUT") - <<EOF
|
||||
[
|
||||
{
|
||||
"type" : "swap",
|
||||
"label" : "label1",
|
||||
"uuid" : "7b93d1f2-595d-4ce3-b0b9-837fbd9e63b0",
|
||||
"file" : "root1.conf",
|
||||
"node" : "test-definitions1",
|
||||
"offset" : 1048576,
|
||||
"old_size" : 0,
|
||||
"raw_size" : 33554432,
|
||||
"old_padding" : 0,
|
||||
"raw_padding" : 0,
|
||||
"activity" : "create"
|
||||
},
|
||||
{
|
||||
"type" : "swap",
|
||||
"label" : "label2",
|
||||
"uuid" : "837c3d67-21b3-478e-be82-7e7f83bf96d3",
|
||||
"file" : "root2.conf",
|
||||
"node" : "test-definitions2",
|
||||
"offset" : 34603008,
|
||||
"old_size" : 0,
|
||||
"raw_size" : 33554432,
|
||||
"old_padding" : 0,
|
||||
"raw_padding" : 0,
|
||||
"activity" : "create"
|
||||
}
|
||||
]
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user