* Public members of hydra_t.
*/
hydra_t public;
+
+ /**
+ * Integrity check failed?
+ */
+ bool integrity_failed;
+
+ /**
+ * Number of times we have been initialized
+ */
+ refcount_t ref;
};
/**
* Single instance of hydra_t.
*/
-hydra_t *hydra;
+hydra_t *hydra = NULL;
/**
* Described in header.
void libhydra_deinit()
{
private_hydra_t *this = (private_hydra_t*)hydra;
+
+ if (!this || !ref_put(&this->ref))
+ { /* have more users */
+ return;
+ }
+
this->public.attributes->destroy(this->public.attributes);
this->public.kernel_interface->destroy(this->public.kernel_interface);
free((void*)this->public.daemon);
{
private_hydra_t *this;
+ if (hydra)
+ { /* already initialized, increase refcount */
+ this = (private_hydra_t*)hydra;
+ ref_get(&this->ref);
+ return !this->integrity_failed;
+ }
+
INIT(this,
.public = {
.attributes = attribute_manager_create(),
.daemon = strdup(daemon ?: "libhydra"),
},
+ .ref = 1,
);
hydra = &this->public;
!lib->integrity->check(lib->integrity, "libhydra", libhydra_init))
{
DBG1(DBG_LIB, "integrity check of libhydra failed");
- return FALSE;
+ this->integrity_failed = TRUE;
}
- return TRUE;
+ return !this->integrity_failed;
}
*
* The daemon's name is used to load daemon-specific settings.
*
+ * libhydra_init() may be called multiple times in a single process, but each
+ * caller should call libhydra_deinit() for each call to libhydra_init().
+ *
* @param daemon name of the daemon that initializes the library
* @return FALSE if integrity check failed
*/