mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
Merge pull request #24730 from yuwata/dissect-image-drop-reference-to-decrypted-image
dissect-image: introduce dissected_image_relinquish()
This commit is contained in:
@@ -539,7 +539,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
|
||||
static const Verb verbs[] = {
|
||||
@@ -598,8 +597,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_RELAX_VAR_CHECK |
|
||||
DISSECT_IMAGE_READ_ONLY,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2579,7 +2579,6 @@ static int bootctl_main(int argc, char *argv[]) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
int r;
|
||||
|
||||
@@ -2603,8 +2602,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_GENERIC_ROOT |
|
||||
DISSECT_IMAGE_RELAX_VAR_CHECK,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2003,7 +2003,6 @@ int setup_namespace(
|
||||
char **error_path) {
|
||||
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
|
||||
_cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
|
||||
_cleanup_strv_free_ char **hierarchies = NULL;
|
||||
@@ -2083,8 +2082,7 @@ int setup_namespace(
|
||||
dissected_image,
|
||||
NULL,
|
||||
&verity,
|
||||
dissect_image_flags,
|
||||
&decrypted_image);
|
||||
dissect_image_flags);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to decrypt dissected image: %m");
|
||||
}
|
||||
@@ -2416,16 +2414,12 @@ int setup_namespace(
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (decrypted_image) {
|
||||
r = decrypted_image_relinquish(decrypted_image);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to relinquish decrypted image: %m");
|
||||
goto finish;
|
||||
}
|
||||
r = dissected_image_relinquish(dissected_image);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to relinquish dissected image: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
loop_device_relinquish(loop_device);
|
||||
|
||||
} else if (root_directory) {
|
||||
|
||||
/* A root directory is specified. Turn its directory into bind mount, if it isn't one yet. */
|
||||
|
||||
@@ -657,7 +657,6 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
|
||||
}
|
||||
|
||||
static int action_mount(DissectedImage *m, LoopDevice *d) {
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@@ -666,8 +665,7 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
|
||||
r = dissected_image_decrypt_interactively(
|
||||
m, NULL,
|
||||
&arg_verity_settings,
|
||||
arg_flags,
|
||||
&di);
|
||||
arg_flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -679,19 +677,15 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to unlock loopback block device: %m");
|
||||
|
||||
if (di) {
|
||||
r = decrypted_image_relinquish(di);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM devices: %m");
|
||||
}
|
||||
r = dissected_image_relinquish(m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
|
||||
|
||||
loop_device_relinquish(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_copy(DissectedImage *m, LoopDevice *d) {
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
|
||||
_cleanup_(rmdir_and_freep) char *created_dir = NULL;
|
||||
_cleanup_free_ char *temp = NULL;
|
||||
int r;
|
||||
@@ -702,8 +696,7 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
|
||||
r = dissected_image_decrypt_interactively(
|
||||
m, NULL,
|
||||
&arg_verity_settings,
|
||||
arg_flags,
|
||||
&di);
|
||||
arg_flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -731,13 +724,9 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to unlock loopback block device: %m");
|
||||
|
||||
if (di) {
|
||||
r = decrypted_image_relinquish(di);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM devices: %m");
|
||||
}
|
||||
|
||||
loop_device_relinquish(d);
|
||||
r = dissected_image_relinquish(m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
|
||||
|
||||
if (arg_action == ACTION_COPY_FROM) {
|
||||
_cleanup_close_ int source_fd = -1, target_fd = -1;
|
||||
|
||||
@@ -1311,7 +1311,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
int r;
|
||||
|
||||
@@ -1349,8 +1348,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_FSCK |
|
||||
DISSECT_IMAGE_GROWFS,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2095,7 +2095,6 @@ static int wait_for_change(sd_journal *j, int poll_fd) {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
bool previous_boot_id_valid = false, first_line = true, ellipsized = false, need_seek = false;
|
||||
bool use_cursor = false, after_cursor = false;
|
||||
@@ -2125,8 +2124,7 @@ int main(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_RELAX_VAR_CHECK |
|
||||
(arg_action == ACTION_UPDATE_CATALOG ? DISSECT_IMAGE_FSCK|DISSECT_IMAGE_GROWFS : DISSECT_IMAGE_READ_ONLY),
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -125,7 +125,6 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
@@ -148,8 +147,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_FSCK |
|
||||
DISSECT_IMAGE_GROWFS,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -5443,7 +5443,6 @@ static int run(int argc, char *argv[]) {
|
||||
_cleanup_(release_lock_file) LockFile tree_global_lock = LOCK_FILE_INIT, tree_local_lock = LOCK_FILE_INIT;
|
||||
char tmprootdir[] = "/tmp/nspawn-root-XXXXXX";
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
|
||||
_cleanup_(fw_ctx_freep) FirewallContext *fw_ctx = NULL;
|
||||
pid_t pid = 0;
|
||||
@@ -5786,8 +5785,7 @@ static int run(int argc, char *argv[]) {
|
||||
dissected_image,
|
||||
NULL,
|
||||
&arg_verity_settings,
|
||||
0,
|
||||
&decrypted_image);
|
||||
0);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
|
||||
@@ -5257,7 +5257,6 @@ static int determine_auto_size(Context *c) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(context_freep) Context* context = NULL;
|
||||
_cleanup_free_ char *node = NULL;
|
||||
@@ -5299,8 +5298,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_USR_NO_ROOT |
|
||||
DISSECT_IMAGE_REQUIRE_ROOT,
|
||||
&mounted_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2109,8 +2109,7 @@ int dissected_image_decrypt(
|
||||
DissectedImage *m,
|
||||
const char *passphrase,
|
||||
const VeritySettings *verity,
|
||||
DissectImageFlags flags,
|
||||
DecryptedImage **ret) {
|
||||
DissectImageFlags flags) {
|
||||
|
||||
#if HAVE_LIBCRYPTSETUP
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *d = NULL;
|
||||
@@ -2131,11 +2130,8 @@ int dissected_image_decrypt(
|
||||
if (verity && verity->root_hash && verity->root_hash_size < sizeof(sd_id128_t))
|
||||
return -EINVAL;
|
||||
|
||||
if (!m->encrypted && !m->verity_ready) {
|
||||
if (ret)
|
||||
*ret = NULL;
|
||||
if (!m->encrypted && !m->verity_ready)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if HAVE_LIBCRYPTSETUP
|
||||
r = decrypted_image_new(&d);
|
||||
@@ -2168,8 +2164,6 @@ int dissected_image_decrypt(
|
||||
}
|
||||
|
||||
m->decrypted_image = TAKE_PTR(d);
|
||||
if (ret)
|
||||
*ret = decrypted_image_ref(m->decrypted_image);
|
||||
|
||||
return 1;
|
||||
#else
|
||||
@@ -2181,8 +2175,7 @@ int dissected_image_decrypt_interactively(
|
||||
DissectedImage *m,
|
||||
const char *passphrase,
|
||||
const VeritySettings *verity,
|
||||
DissectImageFlags flags,
|
||||
DecryptedImage **ret) {
|
||||
DissectImageFlags flags) {
|
||||
|
||||
_cleanup_strv_free_erase_ char **z = NULL;
|
||||
int n = 3, r;
|
||||
@@ -2191,7 +2184,7 @@ int dissected_image_decrypt_interactively(
|
||||
n--;
|
||||
|
||||
for (;;) {
|
||||
r = dissected_image_decrypt(m, passphrase, verity, flags, ret);
|
||||
r = dissected_image_decrypt(m, passphrase, verity, flags);
|
||||
if (r >= 0)
|
||||
return r;
|
||||
if (r == -EKEYREJECTED)
|
||||
@@ -2213,7 +2206,7 @@ int dissected_image_decrypt_interactively(
|
||||
}
|
||||
}
|
||||
|
||||
int decrypted_image_relinquish(DecryptedImage *d) {
|
||||
static int decrypted_image_relinquish(DecryptedImage *d) {
|
||||
assert(d);
|
||||
|
||||
/* Turns on automatic removal after the last use ended for all DM devices of this image, and sets a
|
||||
@@ -2239,6 +2232,23 @@ int decrypted_image_relinquish(DecryptedImage *d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dissected_image_relinquish(DissectedImage *m) {
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
||||
if (m->decrypted_image) {
|
||||
r = decrypted_image_relinquish(m->decrypted_image);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (m->loop)
|
||||
loop_device_relinquish(m->loop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *build_auxiliary_path(const char *image, const char *suffix) {
|
||||
const char *e;
|
||||
char *n;
|
||||
@@ -2979,12 +2989,10 @@ int mount_image_privately_interactively(
|
||||
const char *image,
|
||||
DissectImageFlags flags,
|
||||
char **ret_directory,
|
||||
LoopDevice **ret_loop_device,
|
||||
DecryptedImage **ret_decrypted_image) {
|
||||
LoopDevice **ret_loop_device) {
|
||||
|
||||
_cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
|
||||
_cleanup_(rmdir_and_freep) char *created_dir = NULL;
|
||||
_cleanup_free_ char *temp = NULL;
|
||||
@@ -2997,7 +3005,6 @@ int mount_image_privately_interactively(
|
||||
assert(image);
|
||||
assert(ret_directory);
|
||||
assert(ret_loop_device);
|
||||
assert(ret_decrypted_image);
|
||||
|
||||
r = verity_settings_load(&verity, image, NULL, NULL);
|
||||
if (r < 0)
|
||||
@@ -3024,7 +3031,7 @@ int mount_image_privately_interactively(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dissected_image_decrypt_interactively(dissected_image, NULL, &verity, flags, &decrypted_image);
|
||||
r = dissected_image_decrypt_interactively(dissected_image, NULL, &verity, flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -3046,17 +3053,12 @@ int mount_image_privately_interactively(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (decrypted_image) {
|
||||
r = decrypted_image_relinquish(decrypted_image);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM devices: %m");
|
||||
}
|
||||
|
||||
loop_device_relinquish(d);
|
||||
r = dissected_image_relinquish(dissected_image);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
|
||||
|
||||
*ret_directory = TAKE_PTR(created_dir);
|
||||
*ret_loop_device = TAKE_PTR(d);
|
||||
*ret_decrypted_image = TAKE_PTR(decrypted_image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3100,7 +3102,6 @@ int verity_dissect_and_mount(
|
||||
const char *required_sysext_scope) {
|
||||
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *dissected_image = NULL;
|
||||
_cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
|
||||
DissectImageFlags dissect_image_flags;
|
||||
@@ -3152,8 +3153,7 @@ int verity_dissect_and_mount(
|
||||
dissected_image,
|
||||
NULL,
|
||||
&verity,
|
||||
dissect_image_flags,
|
||||
&decrypted_image);
|
||||
dissect_image_flags);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to decrypt dissected image: %m");
|
||||
|
||||
@@ -3199,13 +3199,9 @@ int verity_dissect_and_mount(
|
||||
return log_debug_errno(r, "Failed to compare image %s extension-release metadata with the root's os-release: %m", dissected_image->image_name);
|
||||
}
|
||||
|
||||
if (decrypted_image) {
|
||||
r = decrypted_image_relinquish(decrypted_image);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to relinquish decrypted image: %m");
|
||||
}
|
||||
|
||||
loop_device_relinquish(loop_device);
|
||||
r = dissected_image_relinquish(dissected_image);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to relinquish dissected image: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -275,8 +275,8 @@ int dissect_loop_device_and_warn(LoopDevice *loop, const VeritySettings *verity,
|
||||
DissectedImage* dissected_image_unref(DissectedImage *m);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);
|
||||
|
||||
int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const VeritySettings *verity, DissectImageFlags flags, DecryptedImage **ret);
|
||||
int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const VeritySettings *verity, DissectImageFlags flags, DecryptedImage **ret);
|
||||
int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const VeritySettings *verity, DissectImageFlags flags);
|
||||
int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const VeritySettings *verity, DissectImageFlags flags);
|
||||
int dissected_image_mount(DissectedImage *m, const char *dest, uid_t uid_shift, uid_t uid_range, DissectImageFlags flags);
|
||||
int dissected_image_mount_and_warn(DissectedImage *m, const char *where, uid_t uid_shift, uid_t uid_range, DissectImageFlags flags);
|
||||
|
||||
@@ -285,7 +285,8 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
|
||||
DecryptedImage* decrypted_image_ref(DecryptedImage *p);
|
||||
DecryptedImage* decrypted_image_unref(DecryptedImage *p);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);
|
||||
int decrypted_image_relinquish(DecryptedImage *d);
|
||||
|
||||
int dissected_image_relinquish(DissectedImage *m);
|
||||
|
||||
const char* partition_designator_to_string(PartitionDesignator d) _const_;
|
||||
PartitionDesignator partition_designator_from_string(const char *name) _pure_;
|
||||
@@ -299,6 +300,6 @@ bool dissected_image_verity_candidate(const DissectedImage *image, PartitionDesi
|
||||
bool dissected_image_verity_ready(const DissectedImage *image, PartitionDesignator d);
|
||||
bool dissected_image_verity_sig_ready(const DissectedImage *image, PartitionDesignator d);
|
||||
|
||||
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device, DecryptedImage **ret_decrypted_image);
|
||||
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device);
|
||||
|
||||
int verity_dissect_and_mount(int src_fd, const char *src, const char *dest, const MountOptions *options, const char *required_host_os_release_id, const char *required_host_os_release_version_id, const char *required_host_os_release_sysext_level, const char *required_sysext_scope);
|
||||
|
||||
@@ -514,7 +514,6 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
|
||||
case IMAGE_BLOCK: {
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL;
|
||||
_cleanup_(verity_settings_done) VeritySettings verity_settings = VERITY_SETTINGS_DEFAULT;
|
||||
DissectImageFlags flags =
|
||||
DISSECT_IMAGE_READ_ONLY |
|
||||
@@ -558,8 +557,7 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
|
||||
r = dissected_image_decrypt_interactively(
|
||||
m, NULL,
|
||||
&verity_settings,
|
||||
flags,
|
||||
&di);
|
||||
flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -572,13 +570,9 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (di) {
|
||||
r = decrypted_image_relinquish(di);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM devices: %m");
|
||||
}
|
||||
|
||||
loop_device_relinquish(d);
|
||||
r = dissected_image_relinquish(m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -855,17 +855,14 @@ static int reboot_now(void) {
|
||||
static int process_image(
|
||||
bool ro,
|
||||
char **ret_mounted_dir,
|
||||
LoopDevice **ret_loop_device,
|
||||
DecryptedImage **ret_decrypted_image) {
|
||||
LoopDevice **ret_loop_device) {
|
||||
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret_mounted_dir);
|
||||
assert(ret_loop_device);
|
||||
assert(ret_decrypted_image);
|
||||
|
||||
if (!arg_image)
|
||||
return 0;
|
||||
@@ -883,8 +880,7 @@ static int process_image(
|
||||
DISSECT_IMAGE_GENERIC_ROOT |
|
||||
DISSECT_IMAGE_REQUIRE_ROOT,
|
||||
&mounted_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -894,14 +890,12 @@ static int process_image(
|
||||
|
||||
*ret_mounted_dir = TAKE_PTR(mounted_dir);
|
||||
*ret_loop_device = TAKE_PTR(loop_device);
|
||||
*ret_decrypted_image = TAKE_PTR(decrypted_image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verb_list(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(context_freep) Context* context = NULL;
|
||||
const char *version;
|
||||
@@ -910,7 +904,7 @@ static int verb_list(int argc, char **argv, void *userdata) {
|
||||
assert(argc <= 2);
|
||||
version = argc >= 2 ? argv[1] : NULL;
|
||||
|
||||
r = process_image(/* ro= */ true, &mounted_dir, &loop_device, &decrypted_image);
|
||||
r = process_image(/* ro= */ true, &mounted_dir, &loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -926,14 +920,13 @@ static int verb_list(int argc, char **argv, void *userdata) {
|
||||
|
||||
static int verb_check_new(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(context_freep) Context* context = NULL;
|
||||
int r;
|
||||
|
||||
assert(argc <= 1);
|
||||
|
||||
r = process_image(/* ro= */ true, &mounted_dir, &loop_device, &decrypted_image);
|
||||
r = process_image(/* ro= */ true, &mounted_dir, &loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -952,14 +945,13 @@ static int verb_check_new(int argc, char **argv, void *userdata) {
|
||||
|
||||
static int verb_vacuum(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(context_freep) Context* context = NULL;
|
||||
int r;
|
||||
|
||||
assert(argc <= 1);
|
||||
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device, &decrypted_image);
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -972,7 +964,6 @@ static int verb_vacuum(int argc, char **argv, void *userdata) {
|
||||
|
||||
static int verb_update(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(context_freep) Context* context = NULL;
|
||||
_cleanup_free_ char *booted_version = NULL;
|
||||
@@ -993,7 +984,7 @@ static int verb_update(int argc, char **argv, void *userdata) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENODATA), "/etc/os-release lacks IMAGE_VERSION field.");
|
||||
}
|
||||
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device, &decrypted_image);
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1096,7 +1087,6 @@ static int component_name_valid(const char *c) {
|
||||
|
||||
static int verb_components(int argc, char **argv, void *userdata) {
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *mounted_dir = NULL;
|
||||
_cleanup_(set_freep) Set *names = NULL;
|
||||
_cleanup_free_ char **z = NULL; /* We use simple free() rather than strv_free() here, since set_free() will free the strings for us */
|
||||
@@ -1106,7 +1096,7 @@ static int verb_components(int argc, char **argv, void *userdata) {
|
||||
|
||||
assert(argc <= 1);
|
||||
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device, &decrypted_image);
|
||||
r = process_image(/* ro= */ false, &mounted_dir, &loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2081,7 +2081,6 @@ static int read_credential_lines(void) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
#ifndef STANDALONE
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
#endif
|
||||
_cleanup_close_ int lock = -1;
|
||||
@@ -2116,8 +2115,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_FSCK |
|
||||
DISSECT_IMAGE_GROWFS,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -3838,7 +3838,6 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_array_hash_ops, char, string_
|
||||
static int run(int argc, char *argv[]) {
|
||||
#ifndef STANDALONE
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
|
||||
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
|
||||
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
|
||||
#endif
|
||||
_cleanup_strv_free_ char **config_dirs = NULL;
|
||||
@@ -3922,8 +3921,7 @@ static int run(int argc, char *argv[]) {
|
||||
DISSECT_IMAGE_FSCK |
|
||||
DISSECT_IMAGE_GROWFS,
|
||||
&unlink_dir,
|
||||
&loop_device,
|
||||
&decrypted_image);
|
||||
&loop_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user