libxbps: use a new bool in struct xbps_handle to track successful initialization.
(cherry picked from commit 03374950680f6a839b1ee2df8e3a4e1dfb110fa8)
This commit is contained in:
		| @@ -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 *, ...); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user