Fix CPU detect logic to use a bus setting from CPU configs.

This commit fixes the CPU detect logic to make that use a bus
setting from its corresponding config.

Change-Id: I93bad8ae9efd0065ee35b3125b6c0ab707b42903
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/sensors/src/CPUSensorMain.cpp b/sensors/src/CPUSensorMain.cpp
index 7231453..5ad7b9b 100644
--- a/sensors/src/CPUSensorMain.cpp
+++ b/sensors/src/CPUSensorMain.cpp
@@ -59,7 +59,7 @@
     }
 };
 
-static constexpr const char* peciDev = "/dev/peci-0";
+static constexpr const char* peciDev = "/dev/peci-";
 static constexpr const unsigned int rankNumMax = 8;
 
 namespace fs = std::experimental::filesystem;
@@ -357,17 +357,19 @@
                boost::container::flat_set<CPUConfig>& configs,
                std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
 {
-    auto file = open(peciDev, O_RDWR);
-    if (file < 0)
-    {
-        std::cerr << "unable to open " << peciDev << "\n";
-        std::exit(EXIT_FAILURE);
-    }
-
     size_t rescanDelaySeconds = 0;
     bool keepPinging = false;
+
     for (CPUConfig& config : configs)
     {
+        std::string peciDevPath = peciDev + std::to_string(config.bus);
+        auto file = open(peciDevPath.c_str(), O_RDWR | O_CLOEXEC);
+        if (file < 0)
+        {
+            std::cerr << "unable to open " << peciDevPath << "\n";
+            std::exit(EXIT_FAILURE);
+        }
+
         State state;
         struct peci_ping_msg msg;
         msg.addr = config.addr;
@@ -410,6 +412,8 @@
             state = State::OFF;
         }
 
+        close(file);
+
         if (config.state != state)
         {
             if (config.state == State::OFF)
@@ -448,8 +452,6 @@
         }
     }
 
-    close(file);
-
     if (rescanDelaySeconds)
     {
         std::this_thread::sleep_for(std::chrono::seconds(rescanDelaySeconds));