psusensor: Check active state before activation

The activate() function of PSUSensor is not only called in the sensor's
constructor, but also directly from outside by the createSensors()
function in PSUSensorMain in case of a power state change. The power
state change matches include watches on both chassis state and host
state, which will be triggered more than one on a power change. This
works fine for PSU sensors which are present in the off state of host.
However, as the sensor type list expands to support more drivers that
function the same way, some types are not available during host-off.
Therefore, when host goes off and on again, those sensors will be
activated repeatedly following the power change signal and cause error
on inputDev, leading to coredump [1].

This commit checks activation state of a sensor before activating it.

Tested:

1. Configure one PSU sensor with "PowerState": "On" in EM
2. BMC boots with host On
3. Turn off host
4. Turn on host
=> No coredump, the sensor is successfully activated and runs again

[1] Journal log:
psusensor: terminate called after throwing an instance of
'boost::wrapexcept<boost::system::system_error>'

psusensor:   what():  open: Already open [asio.misc:1 at
/usr/include/boost/asio/detail/impl/io_uring_file_service.ipp:53:5 in
function 'boost::system::error_code
boost::asio::detail::io_uring_file_service::open(implementation_type&,
const char*, boost::asio::file_base::flags,
boost::system::error_code&)']

Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: I0e02ea9973112ad56cf92a250aca7dc71d0893e2
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 3c02b93..4d410fe 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -125,6 +125,11 @@
 void PSUSensor::activate(const std::string& newPath,
                          const std::shared_ptr<I2CDevice>& newI2CDevice)
 {
+    if (isActive())
+    {
+        // Avoid activating an active sensor
+        return;
+    }
     path = newPath;
     i2cDevice = newI2CDevice;
     inputDev.open(path, boost::asio::random_access_file::read_only);