From 53d259b3c30cc1323901b47f830c4a1102b94369 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 25 May 2017 10:20:27 -0400 Subject: [PATCH] lib: Define an autocleanup for RPM signal handling Allows us to convert the metadata download func to new code style, and is generally in line with our cleanup-focused philosophy on code, life, and the meaning of the universe. Closes: #789 Approved by: jlebon --- src/libpriv/rpmostree-core.c | 28 ++++++++++++---------------- src/libpriv/rpmostree-rpm-util.h | 11 +++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index 4dbaa141..65a90485 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -354,7 +354,7 @@ rpmostree_context_new_system (GCancellable *cancellable, #endif self->hifctx = dnf_context_new (); - _rpmostree_reset_rpm_sighandlers (); + g_auto(RpmSighandlerResetCleanup) rpmsigreset = { 0, }; dnf_context_set_http_proxy (self->hifctx, g_getenv ("http_proxy")); dnf_context_set_repo_dir (self->hifctx, "/etc/yum.repos.d"); @@ -889,26 +889,21 @@ rpmostree_context_download_metadata (RpmOstreeContext *self, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; - guint progress_sigid; - glnx_unref_object DnfState *hifstate = dnf_state_new (); - g_assert (!self->empty); - progress_sigid = g_signal_connect (hifstate, "percentage-changed", - G_CALLBACK (on_hifstate_percentage_changed), - "Downloading metadata:"); + g_autoptr(DnfState) hifstate = dnf_state_new (); + guint progress_sigid = g_signal_connect (hifstate, "percentage-changed", + G_CALLBACK (on_hifstate_percentage_changed), + "Downloading metadata:"); + + g_auto(RpmSighandlerResetCleanup) rpmsigreset = { 0, }; if (!dnf_context_setup_sack (self->hifctx, hifstate, error)) - goto out; + return FALSE; g_signal_handler_disconnect (hifstate, progress_sigid); rpmostree_output_percent_progress_end (); - - ret = TRUE; - out: - _rpmostree_reset_rpm_sighandlers (); - return ret; + return TRUE; } static void @@ -2483,8 +2478,9 @@ rpmostree_context_assemble_tmprootfs (RpmOstreeContext *self, } } - rpmtsOrder (ordering_ts); - _rpmostree_reset_rpm_sighandlers (); + { g_auto(RpmSighandlerResetCleanup) rpmsigreset = { 0, }; + rpmtsOrder (ordering_ts); + } rpmostree_output_task_begin ("Overlaying"); diff --git a/src/libpriv/rpmostree-rpm-util.h b/src/libpriv/rpmostree-rpm-util.h index 3e35a8dc..ac3577ee 100644 --- a/src/libpriv/rpmostree-rpm-util.h +++ b/src/libpriv/rpmostree-rpm-util.h @@ -128,6 +128,17 @@ rpmostree_print_transaction (DnfContext *context); void _rpmostree_reset_rpm_sighandlers (void); +/* This cleanup struct wraps _rpmostree_reset_rpm_sighandlers() */ +typedef struct { + gpointer unused; +} RpmSighandlerResetCleanup; +static inline void +cleanup_rpmsighandler_reset(RpmSighandlerResetCleanup *cleanup) +{ + _rpmostree_reset_rpm_sighandlers (); +} +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(RpmSighandlerResetCleanup, cleanup_rpmsighandler_reset); + GVariant * rpmostree_fcap_to_xattr_variant (const char *fcap);