From e370ff06254208974fa289989686cdbbe5525c8a Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 24 Sep 2012 10:50:23 +0200 Subject: [PATCH] libxbps: use a new bool in struct xbps_handle to track successful initialization. (cherry picked from commit 03374950680f6a839b1ee2df8e3a4e1dfb110fa8) --- include/xbps_api.h | 6 +++++- lib/initend.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 5d17425a..6173f529 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -81,7 +81,7 @@ /** * @def XBPS_PKGDB - * Filename for the master package database. + * Filename for the package database. */ #define XBPS_PKGDB "pkgdb.plist" @@ -562,6 +562,10 @@ struct xbps_handle { * - XBPS_FLAG_INSTALL_MANUAL */ int flags; + /** + * @private + */ + bool initialized; }; void xbps_dbg_printf(struct xbps_handle *, const char *, ...); diff --git a/lib/initend.c b/lib/initend.c index 2aedb482..39bb1329 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -40,8 +40,6 @@ * Use these functions to initialize some parameters before start * using libxbps and finalize usage to release resources at the end. */ -static bool xbps_initialized; - static char * set_cachedir(struct xbps_handle *xh) { @@ -121,6 +119,9 @@ xbps_init(struct xbps_handle *xhp) assert(xhp != NULL); + if (xhp->initialized) + return 0; + if (xhp->conffile == NULL) xhp->conffile = XBPS_CONF_DEF; @@ -207,7 +208,7 @@ xbps_init(struct xbps_handle *xhp) xhp->transaction_frequency_flush); xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine); - xbps_initialized = true; + xhp->initialized = true; return 0; } @@ -215,7 +216,9 @@ xbps_init(struct xbps_handle *xhp) void xbps_end(struct xbps_handle *xhp) { - if (!xbps_initialized) + assert(xhp); + + if (!xhp->initialized) return; xbps_pkgdb_release(xhp); @@ -227,8 +230,8 @@ xbps_end(struct xbps_handle *xhp) free(xhp->metadir_priv); free(xhp->un_machine); + xhp->initialized = false; xhp = NULL; - xbps_initialized = false; } static void