Fix `ostree admin kargs edit-in-place` assertion when deployments
are pending This is to support pending deployments instead of rasing assertion. For example: ``` $ sudo rpm-ostree kargs --append=foo=bar $ sudo ostree admin kargs edit-in-place --append-if-missing=foobar ``` After reboot we get both `foo=bar foobar`. Fix https://github.com/ostreedev/ostree/issues/2679
This commit is contained in:
parent
93a6d7bea2
commit
37aa2ac287
|
|
@ -3614,8 +3614,37 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self,
|
||||||
if (!_ostree_sysroot_ensure_writable (self, error))
|
if (!_ostree_sysroot_ensure_writable (self, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
g_assert (!ostree_deployment_is_staged (deployment));
|
// handle staged deployment
|
||||||
|
if (ostree_deployment_is_staged (deployment))
|
||||||
|
{
|
||||||
|
/* Read the staged state from disk */
|
||||||
|
glnx_autofd int fd = -1;
|
||||||
|
if (!glnx_openat_rdonly (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, TRUE, &fd, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
g_autoptr(GBytes) contents = ot_fd_readall_or_mmap (fd, 0, error);
|
||||||
|
if (!contents)
|
||||||
|
return FALSE;
|
||||||
|
g_autoptr(GVariant) staged_deployment_data =
|
||||||
|
g_variant_new_from_bytes ((GVariantType*)"a{sv}", contents, TRUE);
|
||||||
|
g_autoptr(GVariantDict) staged_deployment_dict =
|
||||||
|
g_variant_dict_new (staged_deployment_data);
|
||||||
|
|
||||||
|
g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (kargs_str);
|
||||||
|
g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs);
|
||||||
|
|
||||||
|
g_variant_dict_insert (staged_deployment_dict, "kargs", "^a&s", kargs_strv);
|
||||||
|
g_autoptr(GVariant) new_staged_deployment_data = g_variant_dict_end (staged_deployment_dict);
|
||||||
|
|
||||||
|
if (!glnx_file_replace_contents_at (fd, _OSTREE_SYSROOT_RUNSTATE_STAGED,
|
||||||
|
g_variant_get_data (new_staged_deployment_data),
|
||||||
|
g_variant_get_size (new_staged_deployment_data),
|
||||||
|
GLNX_FILE_REPLACE_NODATASYNC,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment);
|
OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment);
|
||||||
ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str);
|
ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str);
|
||||||
|
|
||||||
|
|
@ -3633,6 +3662,7 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self,
|
||||||
bootconf_dfd, bootconf_name,
|
bootconf_dfd, bootconf_name,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,19 @@ set -xeuo pipefail
|
||||||
|
|
||||||
. ${KOLA_EXT_DATA}/libinsttest.sh
|
. ${KOLA_EXT_DATA}/libinsttest.sh
|
||||||
|
|
||||||
|
case "${AUTOPKGTEST_REBOOT_MARK:-}" in
|
||||||
|
"")
|
||||||
|
sudo rpm-ostree kargs --append=somedummykarg=1
|
||||||
sudo ostree admin kargs edit-in-place --append-if-missing=testarg
|
sudo ostree admin kargs edit-in-place --append-if-missing=testarg
|
||||||
assert_file_has_content /boot/loader/entries/ostree-* testarg
|
assert_file_has_content /boot/loader/entries/ostree-* testarg
|
||||||
|
/tmp/autopkgtest-reboot "2"
|
||||||
echo "ok test `kargs edit-in-place --append-if-missing`"
|
;;
|
||||||
|
"2")
|
||||||
|
assert_file_has_content_literal /proc/cmdline somedummykarg=1
|
||||||
|
assert_file_has_content_literal /proc/cmdline testarg
|
||||||
|
echo "ok test with stage: kargs edit-in-place --append-if-missing"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
fatal "Unexpected AUTOPKGTEST_REBOOT_MARK=${AUTOPKGTEST_REBOOT_MARK}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue