From 49eb3b15d50e5eb4d0d7451ad8f3487de8db242d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 23 Jan 2025 16:18:48 -0500 Subject: [PATCH] container: Do rpmdb cleanup in outer scope Prep for the next change which ensures we cleanup rpmdb leftovers; we can't do that while possibly holding an open reference. Signed-off-by: Colin Walters --- src/libpriv/rpmostree-container.cxx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libpriv/rpmostree-container.cxx b/src/libpriv/rpmostree-container.cxx index 825bee64b9..16b5f4c140 100644 --- a/src/libpriv/rpmostree-container.cxx +++ b/src/libpriv/rpmostree-container.cxx @@ -32,19 +32,15 @@ #include -gboolean -rpmostree_container_rebuild (rpmostreecxx::Treefile &treefile, GCancellable *cancellable, - GError **error) +static gboolean +container_rebuild_inner (int rootfs_fd, rpmostreecxx::Treefile &treefile, GCancellable *cancellable, + GError **error) { CXX_TRY (treefile.validate_for_container (), error); g_autoptr (RpmOstreeContext) ctx = rpmostree_context_new_container (); rpmostree_context_set_treefile (ctx, treefile); - glnx_autofd int rootfs_fd = -1; - if (!glnx_opendirat (AT_FDCWD, "/", TRUE, &rootfs_fd, error)) - return FALSE; - // Forcibly turn this on for the container flow because it's the only sane // way for installing RPM packages that invoke useradd/groupadd to work. g_setenv ("RPMOSTREE_EXP_BRIDGE_SYSUSERS", "1", TRUE); @@ -78,6 +74,22 @@ rpmostree_container_rebuild (rpmostreecxx::Treefile &treefile, GCancellable *can CXX_TRY (fs_prep->undo (), error); + return TRUE; +} + +gboolean +rpmostree_container_rebuild (rpmostreecxx::Treefile &treefile, GCancellable *cancellable, + GError **error) +{ + + glnx_autofd int rootfs_fd = -1; + if (!glnx_opendirat (AT_FDCWD, "/", TRUE, &rootfs_fd, error)) + return FALSE; + + // Do this in a new scope to ensure we teardown our connection to the rpmdb + if (!container_rebuild_inner (rootfs_fd, treefile, cancellable, error)) + return FALSE; + CXX_TRY (rpmostreecxx::postprocess_cleanup_rpmdb (rootfs_fd), error); return TRUE;