dbus-sensor: Fix the GPIO sensors hitting coredump

Reduce the diff made in
https://gbmc-review.git.corp.google.com/c/meta-gbmc-staging/+/4300 that
seems to be causing more issues.

Tested:
`xyz.openbmc_project.gpiosensor.service` doesn't hit coredump anymore.
It hits it every 20~ seconds before this change.

Always get the same value of sensors.
```
for i in {1..30}; do ipmitool sdr elist all > /tmp/attempt_$i
wc -l /tmp/attempt* | cut -d '/' -f1  | sort | uniq -c
      1         8
      2         9
      1        13
      1       292
     25       294
      1      7681 total
```

I canceled the last 5 so they have less.
```
      292 /tmp/attempt_26
       13 /tmp/attempt_27
        9 /tmp/attempt_28
        9 /tmp/attempt_29
        8 /tmp/attempt_30
```

Google-Bug-Id: 280381395
Change-Id: I2cfd6dc2cb3d4a924532fb7559d637a2568c9c81
Signed-off-by: Willy Tu <wltu@google.com>
(cherry picked from commit cf26ffc8150e13d63fc1e00afa33e024e3934b87)
diff --git a/recipes-phosphor/sensors/dbus-sensors/0003-gpiosensor-a-dedicated-daemon-to-report-gpio-status-.patch b/recipes-phosphor/sensors/dbus-sensors/0003-gpiosensor-a-dedicated-daemon-to-report-gpio-status-.patch
index d261f94..992d0bc 100644
--- a/recipes-phosphor/sensors/dbus-sensors/0003-gpiosensor-a-dedicated-daemon-to-report-gpio-status-.patch
+++ b/recipes-phosphor/sensors/dbus-sensors/0003-gpiosensor-a-dedicated-daemon-to-report-gpio-status-.patch
@@ -1,8 +1,7 @@
-From e5f58b7ee98816be67cb1c25f01dee4e4aeb3e90 Mon Sep 17 00:00:00 2001
+From e517228b9ba2683d9e6ca8f129805a987dd6b2e6 Mon Sep 17 00:00:00 2001
 From: Gaurav Gandhi <gauravgandhi@google.com>
 Date: Mon, 13 Feb 2023 18:23:56 -0800
-Subject: [PATCH] gpiosensor: a dedicated daemon to report gpio status to
- dbus
+Subject: [PATCH] gpiosensor: a dedicated daemon to report gpio status to dbus
 
 The daemon will read the given gpio status and report to dbus. One can
 consume the gpio signal and behave differently.
@@ -20,17 +19,16 @@
 Signed-off-by: Cody Smith <scody@google.com>
 In-Review: https://gerrit.openbmc-project.xyz/c/openbmc/dbus-sensors/+/45997/37
 Change-Id: Ife901358751eac46b4a52a878feabcb556fb1224
-
 ---
  docs/gpio-based-presence-detection.md         | 120 +++++++++++
  include/GPIOPresenceSensor.hpp                | 110 ++++++++++
  meson_options.txt                             |   1 +
  service_files/meson.build                     |   1 +
  .../xyz.openbmc_project.gpiosensor.service    |  13 ++
- src/GPIOPresenceSensor.cpp                    | 106 ++++++++++
+ src/GPIOPresenceSensor.cpp                    | 105 ++++++++++
  src/GPIOPresenceSensorMain.cpp                | 188 ++++++++++++++++++
  src/meson.build                               |  17 ++
- 8 files changed, 556 insertions(+)
+ 8 files changed, 555 insertions(+)
  create mode 100644 docs/gpio-based-presence-detection.md
  create mode 100644 include/GPIOPresenceSensor.hpp
  create mode 100644 service_files/xyz.openbmc_project.gpiosensor.service
@@ -324,10 +322,10 @@
 +WantedBy=multi-user.target
 diff --git a/src/GPIOPresenceSensor.cpp b/src/GPIOPresenceSensor.cpp
 new file mode 100644
-index 0000000..54233f8
+index 0000000..870b4b4
 --- /dev/null
 +++ b/src/GPIOPresenceSensor.cpp
-@@ -0,0 +1,106 @@
+@@ -0,0 +1,105 @@
 +#include <GPIOPresenceSensor.hpp>
 +
 +#include <cerrno>
@@ -347,12 +345,11 @@
 +
 +int GPIOPresence::readLine(std::string_view lineLabel)
 +{
-+    auto gpio = gpioLines.find(std::string(lineLabel));
-+    if (gpio == gpioLines.end())
++    if (gpioLines.find(std::string(lineLabel)) == gpioLines.end())
 +    {
 +        addInputLine(lineLabel);
 +    }
-+    return gpio->second.get_value();
++    return gpioLines[std::string(lineLabel)].get_value();
 +}
 +
 +void GPIOPresence::addObj(
@@ -629,10 +626,10 @@
 +    io.run();
 +}
 diff --git a/src/meson.build b/src/meson.build
-index 665517a..6b4da70 100644
+index e2af923..a19030b 100644
 --- a/src/meson.build
 +++ b/src/meson.build
-@@ -218,6 +218,23 @@ if get_option('psu').enabled()
+@@ -180,6 +180,23 @@ if get_option('psu').enabled()
      )
  endif
 
@@ -657,5 +654,5 @@
      executable(
          'externalsensor',
 --
-2.40.1.495.gc816e09b53d-goog
+2.40.1.521.gf1e218fcd8-goog
 
diff --git a/recipes-phosphor/sensors/dbus-sensors/0004-Feature-Add-association-interfaces-to-a-target-EM.patch b/recipes-phosphor/sensors/dbus-sensors/0004-Feature-Add-association-interfaces-to-a-target-EM.patch
index 795bac3..8b1f3dd 100644
--- a/recipes-phosphor/sensors/dbus-sensors/0004-Feature-Add-association-interfaces-to-a-target-EM.patch
+++ b/recipes-phosphor/sensors/dbus-sensors/0004-Feature-Add-association-interfaces-to-a-target-EM.patch
@@ -1,4 +1,4 @@
-From 88218e5d334839d5630614b60952784889315a76 Mon Sep 17 00:00:00 2001
+From febe200fdf9115bd327a86ad621e963def1b5f09 Mon Sep 17 00:00:00 2001
 From: Cody Smith <scody@google.com>
 Date: Fri, 18 Feb 2022 13:20:45 +0000
 Subject: [PATCH] Feature: Add association interfaces to a target EM
@@ -31,12 +31,11 @@
 Signed-off-by: Cody Smith <scody@google.com>
 In-Review: https://gerrit.openbmc-project.xyz/c/openbmc/dbus-sensors/+/51360/12
 Change-Id: I0572d124a8e9b9fedbdfb30d41fe399e005f5c03
-
 ---
- include/GPIOPresenceSensor.hpp | 17 ++++++-
+ include/GPIOPresenceSensor.hpp | 17 +++++-
  src/GPIOPresenceSensor.cpp     |  4 +-
- src/GPIOPresenceSensorMain.cpp | 93 ++++++++++++++++++++++++++++++----
- 3 files changed, 101 insertions(+), 13 deletions(-)
+ src/GPIOPresenceSensorMain.cpp | 94 +++++++++++++++++++++++++++++-----
+ 3 files changed, 101 insertions(+), 14 deletions(-)
 
 diff --git a/include/GPIOPresenceSensor.hpp b/include/GPIOPresenceSensor.hpp
 index a9f49a0..fa32a20 100644
@@ -92,10 +91,10 @@
      };
 
 diff --git a/src/GPIOPresenceSensor.cpp b/src/GPIOPresenceSensor.cpp
-index 54233f8..ba5ff51 100644
+index 870b4b4..2d48491 100644
 --- a/src/GPIOPresenceSensor.cpp
 +++ b/src/GPIOPresenceSensor.cpp
-@@ -27,10 +27,12 @@ int GPIOPresence::readLine(std::string_view lineLabel)
+@@ -26,10 +26,12 @@ int GPIOPresence::readLine(std::string_view lineLabel)
 
  void GPIOPresence::addObj(
      std::unique_ptr<sdbusplus::asio::dbus_interface> statusIfc,
@@ -110,7 +109,7 @@
 
  void GPIOPresence::removeObj(std::string_view objPath)
 diff --git a/src/GPIOPresenceSensorMain.cpp b/src/GPIOPresenceSensorMain.cpp
-index 8b22d25..f3d2d43 100644
+index 8b22d25..f556900 100644
 --- a/src/GPIOPresenceSensorMain.cpp
 +++ b/src/GPIOPresenceSensorMain.cpp
 @@ -1,8 +1,10 @@
@@ -193,21 +192,23 @@
                  callback(objPath.str, found->first, config);
              }
              catch (std::exception& e)
-@@ -62,7 +104,7 @@ void setupInterfaceAdded(sdbusplus::asio::connection* conn,
+@@ -62,23 +104,24 @@ void setupInterfaceAdded(sdbusplus::asio::connection* conn,
 
      // call the user callback for all the device that is already available
      conn->async_method_call(
 -        [cb](const boost::system::error_code ec,
+-             ManagedObjectType managedObjs) {
 +        [callback = cb](const boost::system::error_code ec,
-              ManagedObjectType managedObjs) {
++                        ManagedObjectType managedObjs) {
          if (ec)
          {
-@@ -70,15 +112,15 @@ void setupInterfaceAdded(sdbusplus::asio::connection* conn,
+             return;
          }
          for (auto& obj : managedObjs)
          {
 -            auto& item = obj.second;
 +            SensorData& item = obj.second;
++
              auto found = item.find(interfaces::emGPIOCableSensingIfc);
              if (found != item.end())
              {
@@ -221,7 +222,7 @@
                  }
                  catch (std::exception& e)
                  {
-@@ -103,7 +145,7 @@ void setupInterfaceRemoved(sdbusplus::asio::connection* conn,
+@@ -103,7 +146,7 @@ void setupInterfaceRemoved(sdbusplus::asio::connection* conn,
                             OnInterfaceRemovedCallback&& cb)
  {
      // Listen to the interface removed event.
@@ -230,14 +231,7 @@
          [callback = std::move(cb)](sdbusplus::message::message msg) {
          sdbusplus::message::object_path objPath;
          msg.read(objPath);
-@@ -157,19 +199,48 @@ int main()
-         sdbusplus::message::object_path inventoryPath(
-             gpiopresencesensing::inventoryObjPath);
-         sdbusplus::message::object_path objPath = inventoryPath / config.name;
-+
-         std::cout << "New config received " << objPath.str << std::endl;
-+
-         if (!controller->hasObj(objPath.str))
+@@ -162,14 +205,41 @@ int main()
          {
              controller->removeObj(objPath.str);
          }
@@ -282,5 +276,5 @@
          // It is possible there are more EM config in the pipeline.
          // Therefore, delay the main loop by 10 seconds to wait for more
 --
-2.40.1.495.gc816e09b53d-goog
+2.40.1.521.gf1e218fcd8-goog