core: follow-ups for changes to MountOptions (#40395)
Follow-up for #39449
This commit is contained in:
@@ -796,7 +796,7 @@ static int property_get_root_hash_sig(
|
||||
|
||||
static int bus_append_mount_options(
|
||||
sd_bus_message *reply,
|
||||
MountOptions *options) {
|
||||
const MountOptions *options) {
|
||||
|
||||
int r;
|
||||
|
||||
|
||||
@@ -194,7 +194,8 @@ static int bus_service_method_mount(sd_bus_message *message, void *userdata, sd_
|
||||
return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path must be absolute and normalized");
|
||||
|
||||
if (is_image) {
|
||||
r = bus_read_mount_options(message, reterr_error, &options, NULL, "");
|
||||
r = bus_read_mount_options(message, reterr_error, &options,
|
||||
/* in_out_format_str = */ NULL, /* separator = */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
+24
-24
@@ -267,49 +267,50 @@ int bus_read_mount_options(
|
||||
|
||||
_cleanup_(mount_options_free_allp) MountOptions *options = NULL;
|
||||
_cleanup_free_ char *format_str = NULL;
|
||||
const char *mount_options, *partition;
|
||||
int r;
|
||||
|
||||
assert(message);
|
||||
assert(ret_options);
|
||||
assert(separator);
|
||||
assert(!in_out_format_str == !separator);
|
||||
|
||||
r = sd_bus_message_enter_container(message, 'a', "(ss)");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
const char *partition, *mount_options;
|
||||
while ((r = sd_bus_message_read(message, "(ss)", &partition, &mount_options)) > 0) {
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
PartitionDesignator partition_designator;
|
||||
|
||||
if (chars_intersect(mount_options, WHITESPACE))
|
||||
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
|
||||
"Invalid mount options string, contains whitespace character(s): %s", mount_options);
|
||||
"Invalid mount options string, contains whitespace character(s): %s", mount_options);
|
||||
|
||||
partition_designator = partition_designator_from_string(partition);
|
||||
if (partition_designator < 0)
|
||||
return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid partition name %s", partition);
|
||||
|
||||
/* Need to store the options with the escapes, so that they can be parsed again */
|
||||
escaped = shell_escape(mount_options, ":");
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
if (!options) {
|
||||
options = new0(MountOptions, 1);
|
||||
if (!options)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!isempty(escaped)) {
|
||||
if (!strextend_with_separator(&format_str, separator, partition, ":", escaped))
|
||||
r = free_and_strdup(&options->options[partition_designator], mount_options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (in_out_format_str && !isempty(mount_options)) {
|
||||
/* Need to store the options with the escapes, so that they can be parsed again */
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
|
||||
escaped = shell_escape(mount_options, ":");
|
||||
if (!escaped)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!options) {
|
||||
options = new0(MountOptions, 1);
|
||||
if (!options)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = free_and_strdup(&options->options[partition_designator], mount_options);
|
||||
r = strextendf_with_separator(&format_str, separator, "%s:%s", partition, escaped);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else if (options)
|
||||
options->options[partition_designator] = mfree(options->options[partition_designator]);
|
||||
}
|
||||
}
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -318,11 +319,10 @@ int bus_read_mount_options(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (options) {
|
||||
if (in_out_format_str && !strextend_with_separator(in_out_format_str, separator, format_str))
|
||||
return -ENOMEM;
|
||||
*ret_options = TAKE_PTR(options);
|
||||
}
|
||||
if (in_out_format_str && !strextend_with_separator(in_out_format_str, separator, format_str))
|
||||
return -ENOMEM;
|
||||
|
||||
*ret_options = TAKE_PTR(options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ static int json_append_mount_options(sd_json_variant **v, MountOptions *options)
|
||||
return 0;
|
||||
|
||||
for (PartitionDesignator j = 0; j < _PARTITION_DESIGNATOR_MAX; j++) {
|
||||
if (!options->options[j])
|
||||
if (isempty(options->options[j]))
|
||||
continue;
|
||||
|
||||
r = sd_json_variant_append_arraybo(
|
||||
|
||||
@@ -4631,9 +4631,7 @@ int mount_options_set_and_consume(MountOptions **options, PartitionDesignator d,
|
||||
}
|
||||
}
|
||||
|
||||
free_and_replace((*options)->options[d], s);
|
||||
|
||||
return 0;
|
||||
return free_and_replace((*options)->options[d], s);
|
||||
}
|
||||
|
||||
int mount_options_dup(const MountOptions *source, MountOptions **ret) {
|
||||
@@ -4644,7 +4642,7 @@ int mount_options_dup(const MountOptions *source, MountOptions **ret) {
|
||||
|
||||
options = new0(MountOptions, 1);
|
||||
if (!options)
|
||||
return log_oom();
|
||||
return log_oom_debug();
|
||||
|
||||
for (PartitionDesignator d = 0; d < _PARTITION_DESIGNATOR_MAX; d++)
|
||||
if (source->options[d]) {
|
||||
|
||||
Reference in New Issue
Block a user