utils: Deduplicate library loading

This prevents us from accidentally initializing a blob module twice.

Change-Id: Iee4dea66962f3a5a376a72ae22f3fca69b33264f
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/utils.cpp b/utils.cpp
index d3e2d67..fa2bf6a 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -25,6 +25,7 @@
 #include <phosphor-logging/log.hpp>
 #include <regex>
 #include <string>
+#include <unordered_set>
 #include <vector>
 
 namespace blobs
@@ -40,6 +41,7 @@
 void loadLibraries(ManagerInterface* manager, const std::string& path,
                    const internal::DlSysInterface* sys)
 {
+    std::unordered_set<HandlerFactory> seen;
     void* libHandle = NULL;
     HandlerFactory factory;
 
@@ -69,6 +71,14 @@
             continue;
         }
 
+        // We may have duplicate libraries in the blobs directory that we only
+        // want to initialize once.
+        if (seen.count(factory) > 0)
+        {
+            continue;
+        }
+        seen.emplace(factory);
+
         try
         {
             std::unique_ptr<GenericBlobInterface> result = factory();