+/*
+ * This function only does something once when store->use_fallbacks == 1,
+ * and then sets store->use_fallbacks = 0, so the second call and so on is
+ * effectively a no-op.
+ */
+static void provider_activate_fallbacks(struct provider_store_st *store)
+{
+ if (store->use_fallbacks) {
+ int num_provs = sk_OSSL_PROVIDER_num(store->providers);
+ int activated_fallback_count = 0;
+ int i;
+
+ for (i = 0; i < num_provs; i++) {
+ OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(store->providers, i);
+
+ /*
+ * Activated fallback providers get an extra refcount, to
+ * simulate a regular load.
+ * Note that we don't care if the activation succeeds or not,
+ * other than to maintain a correct refcount. If the activation
+ * doesn't succeed, then any future attempt to use the fallback
+ * provider will fail anyway.
+ */
+ if (prov->flag_fallback) {
+ if (ossl_provider_up_ref(prov)) {
+ if (!provider_activate(prov)) {
+ ossl_provider_free(prov);
+ } else {
+ prov->flag_activated_as_fallback = 1;
+ activated_fallback_count++;
+ }
+ }
+ }
+ }
+
+ /*
+ * We assume that all fallbacks have been added to the store before
+ * any fallback is activated.
+ * TODO: We may have to reconsider this, IF we find ourselves adding
+ * fallbacks after any previous fallback has been activated.
+ */
+ if (activated_fallback_count > 0)
+ store->use_fallbacks = 0;
+ }
+}
+