* Hashtable with registered objects (name => object)
*/
hashtable_t *objects;
+
+ /**
+ * Integrity check failed?
+ */
+ bool integrity_failed;
+
+ /**
+ * Number of times we have been initialized
+ */
+ refcount_t ref;
};
/**
* library instance
*/
-library_t *lib;
+library_t *lib = NULL;
/**
* Deinitialize library
private_library_t *this = (private_library_t*)lib;
bool detailed;
+ if (!this || !ref_put(&this->ref))
+ { /* have more users */
+ return;
+ }
+
detailed = lib->settings->get_bool(lib->settings,
"libstrongswan.leak_detective.detailed", TRUE);
private_library_t *this;
printf_hook_t *pfh;
+ if (lib)
+ { /* already initialized, increase refcount */
+ this = (private_library_t*)lib;
+ ref_get(&this->ref);
+ return !this->integrity_failed;
+ }
+
INIT(this,
.public = {
.get = _get,
.set = _set,
},
+ .ref = 1,
);
lib = &this->public;
if (!lib->integrity->check(lib->integrity, "libstrongswan", library_init))
{
DBG1(DBG_LIB, "integrity check of libstrongswan failed");
- return FALSE;
+ this->integrity_failed = TRUE;
}
#else /* !INTEGRITY_TEST */
DBG1(DBG_LIB, "integrity test enabled, but not supported");
- return FALSE;
+ this->integrity_failed = TRUE;
#endif /* INTEGRITY_TEST */
}
- return TRUE;
+ return !this->integrity_failed;
}
/**
* Initialize library, creates "lib" instance.
*
+ * library_init() may be called multiple times in a single process, but each
+ * caller should call library_deinit() for each call to library_init().
+ *
* @param settings file to read settings from, may be NULL for default
* @return FALSE if integrity check failed
*/