IntelCPUSensor: use libpeci to open peciFd

To stay consistent with libpeci usage we should use
dedicated functions to open PECI file descriptors
when using peci-legacy.

Tested: hwmons are successfully created in the same way
they were created opening peciFd directly

Change-Id: I924c3fdc8029f47aed80480ebc03d2dca71d134f
Signed-off-by: Oleksandr Shulzhenko <oleksandr.shulzhenko.viktorovych@intel.com>
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index 9e48184..1fc75af 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -480,6 +480,7 @@
 {
     size_t rescanDelaySeconds = 0;
     static bool keepPinging = false;
+    int peciFd = -1;
 
     for (CPUConfig& config : cpuConfigs)
     {
@@ -490,9 +491,11 @@
 
         std::string peciDevPath = peciDev + std::to_string(config.bus);
 
+        peci_SetDevName(peciDevPath.data());
+
         // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
-        auto file = open(peciDevPath.c_str(), O_RDWR | O_CLOEXEC);
-        if (file < 0)
+        if ((peci_Lock(&peciFd, PECI_NO_WAIT) != PECI_CC_SUCCESS) ||
+            (peciFd < 0))
         {
             std::cerr << "unable to open " << peciDevPath << " "
                       << std::strerror(errno) << "\n";
@@ -501,7 +504,6 @@
             return;
         }
 
-        peci_SetDevName(peciDevPath.data());
         State newState = State::OFF;
 
         // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
@@ -592,6 +594,8 @@
         }
     }
 
+    peci_Unlock(peciFd);
+
     if (rescanDelaySeconds != 0U)
     {
         creationTimer.expires_after(std::chrono::seconds(rescanDelaySeconds));