1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #include "DeviceMgmt.hpp"
18 #include "HwmonTempSensor.hpp"
19 #include "SensorPaths.hpp"
20 #include "Thresholds.hpp"
21 #include "Utils.hpp"
22 
23 #include <boost/asio/error.hpp>
24 #include <boost/asio/io_context.hpp>
25 #include <boost/asio/post.hpp>
26 #include <boost/asio/steady_timer.hpp>
27 #include <boost/container/flat_map.hpp>
28 #include <boost/container/flat_set.hpp>
29 #include <sdbusplus/asio/connection.hpp>
30 #include <sdbusplus/asio/object_server.hpp>
31 #include <sdbusplus/bus.hpp>
32 #include <sdbusplus/bus/match.hpp>
33 #include <sdbusplus/message.hpp>
34 #include <sdbusplus/message/native_types.hpp>
35 
36 #include <algorithm>
37 #include <array>
38 #include <chrono>
39 #include <cstddef>
40 #include <cstdint>
41 #include <filesystem>
42 #include <functional>
43 #include <ios>
44 #include <iostream>
45 #include <memory>
46 #include <optional>
47 #include <regex>
48 #include <string>
49 #include <system_error>
50 #include <utility>
51 #include <variant>
52 #include <vector>
53 
54 static constexpr float pollRateDefault = 0.5;
55 
56 static constexpr double maxValuePressure = 120000;      // Pascals
57 static constexpr double minValuePressure = 30000;       // Pascals
58 
59 static constexpr double maxValueRelativeHumidity = 100; // PercentRH
60 static constexpr double minValueRelativeHumidity = 0;   // PercentRH
61 
62 static constexpr double maxValueTemperature = 127;      // DegreesC
63 static constexpr double minValueTemperature = -128;     // DegreesC
64 
65 namespace fs = std::filesystem;
66 
67 static const I2CDeviceTypeMap sensorTypes{
68     {"ADM1021", I2CDeviceType{"adm1021", true}},
69     {"DPS310", I2CDeviceType{"dps310", false}},
70     {"EMC1403", I2CDeviceType{"emc1403", true}},
71     {"EMC1412", I2CDeviceType{"emc1412", true}},
72     {"EMC1413", I2CDeviceType{"emc1413", true}},
73     {"EMC1414", I2CDeviceType{"emc1414", true}},
74     {"HDC1080", I2CDeviceType{"hdc1080", false}},
75     {"JC42", I2CDeviceType{"jc42", true}},
76     {"LM75A", I2CDeviceType{"lm75a", true}},
77     {"LM95234", I2CDeviceType{"lm95234", true}},
78     {"MAX31725", I2CDeviceType{"max31725", true}},
79     {"MAX31730", I2CDeviceType{"max31730", true}},
80     {"MAX6581", I2CDeviceType{"max6581", true}},
81     {"MAX6654", I2CDeviceType{"max6654", true}},
82     {"MAX6639", I2CDeviceType{"max6639", true}},
83     {"MCP9600", I2CDeviceType{"mcp9600", false}},
84     {"NCT6779", I2CDeviceType{"nct6779", true}},
85     {"NCT7802", I2CDeviceType{"nct7802", true}},
86     {"PT5161L", I2CDeviceType{"pt5161l", true}},
87     {"SBTSI", I2CDeviceType{"sbtsi", true}},
88     {"SI7020", I2CDeviceType{"si7020", false}},
89     {"TMP100", I2CDeviceType{"tmp100", true}},
90     {"TMP112", I2CDeviceType{"tmp112", true}},
91     {"TMP175", I2CDeviceType{"tmp175", true}},
92     {"TMP421", I2CDeviceType{"tmp421", true}},
93     {"TMP432", I2CDeviceType{"tmp432", true}},
94     {"TMP441", I2CDeviceType{"tmp441", true}},
95     {"TMP461", I2CDeviceType{"tmp461", true}},
96     {"TMP464", I2CDeviceType{"tmp464", true}},
97     {"TMP468", I2CDeviceType{"tmp468", true}},
98     {"TMP75", I2CDeviceType{"tmp75", true}},
99     {"W83773G", I2CDeviceType{"w83773g", true}},
100 };
101 
102 static struct SensorParams
getSensorParameters(const std::filesystem::path & path)103     getSensorParameters(const std::filesystem::path& path)
104 {
105     // offset is to default to 0 and scale to 1, see lore
106     // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
107     struct SensorParams tmpSensorParameters = {
108         .minValue = minValueTemperature,
109         .maxValue = maxValueTemperature,
110         .offsetValue = 0.0,
111         .scaleValue = 1.0,
112         .units = sensor_paths::unitDegreesC,
113         .typeName = "temperature"};
114 
115     // For IIO RAW sensors we get a raw_value, an offset, and scale
116     // to compute the value = (raw_value + offset) * scale
117     // with a _raw IIO device we need to get the
118     // offsetValue and scaleValue from the driver
119     // these are used to compute the reading in
120     // units that have yet to be scaled for D-Bus.
121     const std::string pathStr = path.string();
122     if (pathStr.ends_with("_raw"))
123     {
124         std::string pathOffsetStr =
125             pathStr.substr(0, pathStr.size() - 4) + "_offset";
126         std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
127         // In case there is nothing to read skip this device
128         // This is not an error condition see lore
129         // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
130         if (tmpOffsetValue)
131         {
132             tmpSensorParameters.offsetValue = *tmpOffsetValue;
133         }
134 
135         std::string pathScaleStr =
136             pathStr.substr(0, pathStr.size() - 4) + "_scale";
137         std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
138         // In case there is nothing to read skip this device
139         // This is not an error condition see lore
140         // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
141         if (tmpScaleValue)
142         {
143             tmpSensorParameters.scaleValue = *tmpScaleValue;
144         }
145     }
146 
147     // Temperatures are read in milli degrees Celsius, we need
148     // degrees Celsius. Pressures are read in kilopascal, we need
149     // Pascals.  On D-Bus for Open BMC we use the International
150     // System of Units without prefixes. Links to the kernel
151     // documentation:
152     // https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
153     // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
154     if (path.filename() == "in_pressure_input" ||
155         path.filename() == "in_pressure_raw")
156     {
157         tmpSensorParameters.minValue = minValuePressure;
158         tmpSensorParameters.maxValue = maxValuePressure;
159         // Pressures are read in kilopascal, we need Pascals.
160         tmpSensorParameters.scaleValue *= 1000.0;
161         tmpSensorParameters.typeName = "pressure";
162         tmpSensorParameters.units = sensor_paths::unitPascals;
163     }
164     else if (path.filename() == "in_humidityrelative_input" ||
165              path.filename() == "in_humidityrelative_raw")
166     {
167         tmpSensorParameters.minValue = minValueRelativeHumidity;
168         tmpSensorParameters.maxValue = maxValueRelativeHumidity;
169         // Relative Humidity are read in milli-percent, we need percent.
170         tmpSensorParameters.scaleValue *= 0.001;
171         tmpSensorParameters.typeName = "humidity";
172         tmpSensorParameters.units = sensor_paths::unitPercentRH;
173     }
174     else
175     {
176         // Temperatures are read in milli degrees Celsius,
177         // we need degrees Celsius.
178         tmpSensorParameters.scaleValue *= 0.001;
179     }
180 
181     return tmpSensorParameters;
182 }
183 
184 struct SensorConfigKey
185 {
186     uint64_t bus;
187     uint64_t addr;
operator <SensorConfigKey188     bool operator<(const SensorConfigKey& other) const
189     {
190         if (bus != other.bus)
191         {
192             return bus < other.bus;
193         }
194         return addr < other.addr;
195     }
196 };
197 
198 struct SensorConfig
199 {
200     std::string sensorPath;
201     SensorData sensorData;
202     std::string interface;
203     SensorBaseConfigMap config;
204     std::vector<std::string> name;
205 };
206 
207 using SensorConfigMap =
208     boost::container::flat_map<SensorConfigKey, SensorConfig>;
209 
210 static SensorConfigMap
buildSensorConfigMap(const ManagedObjectType & sensorConfigs)211     buildSensorConfigMap(const ManagedObjectType& sensorConfigs)
212 {
213     SensorConfigMap configMap;
214     for (const auto& [path, cfgData] : sensorConfigs)
215     {
216         for (const auto& [intf, cfg] : cfgData)
217         {
218             auto busCfg = cfg.find("Bus");
219             auto addrCfg = cfg.find("Address");
220             if ((busCfg == cfg.end()) || (addrCfg == cfg.end()))
221             {
222                 continue;
223             }
224 
225             if ((std::get_if<uint64_t>(&busCfg->second) == nullptr) ||
226                 (std::get_if<uint64_t>(&addrCfg->second) == nullptr))
227             {
228                 std::cerr << path.str << " Bus or Address invalid\n";
229                 continue;
230             }
231 
232             std::vector<std::string> hwmonNames;
233             auto nameCfg = cfg.find("Name");
234             if (nameCfg != cfg.end())
235             {
236                 hwmonNames.push_back(std::get<std::string>(nameCfg->second));
237                 size_t i = 1;
238                 while (true)
239                 {
240                     auto sensorNameCfg = cfg.find("Name" + std::to_string(i));
241                     if (sensorNameCfg == cfg.end())
242                     {
243                         break;
244                     }
245                     hwmonNames.push_back(
246                         std::get<std::string>(sensorNameCfg->second));
247                     i++;
248                 }
249             }
250 
251             SensorConfigKey key = {std::get<uint64_t>(busCfg->second),
252                                    std::get<uint64_t>(addrCfg->second)};
253             SensorConfig val = {path.str, cfgData, intf, cfg, hwmonNames};
254 
255             auto [it, inserted] = configMap.emplace(key, std::move(val));
256             if (!inserted)
257             {
258                 std::cerr << path.str << ": ignoring duplicate entry for {"
259                           << key.bus << ", 0x" << std::hex << key.addr
260                           << std::dec << "}\n";
261             }
262         }
263     }
264     return configMap;
265 }
266 
createSensors(boost::asio::io_context & io,sdbusplus::asio::object_server & objectServer,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors,std::shared_ptr<sdbusplus::asio::connection> & dbusConnection,const std::shared_ptr<boost::container::flat_set<std::string>> & sensorsChanged,bool activateOnly)267 void createSensors(
268     boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
269     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
270         sensors,
271     std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
272     const std::shared_ptr<boost::container::flat_set<std::string>>&
273         sensorsChanged,
274     bool activateOnly)
275 {
276     auto getter = std::make_shared<GetSensorConfiguration>(
277         dbusConnection,
278         [&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
279          activateOnly](const ManagedObjectType& sensorConfigurations) {
280             bool firstScan = sensorsChanged == nullptr;
281 
282             SensorConfigMap configMap =
283                 buildSensorConfigMap(sensorConfigurations);
284 
285             auto devices =
286                 instantiateDevices(sensorConfigurations, sensors, sensorTypes);
287 
288             // IIO _raw devices look like this on sysfs:
289             //     /sys/bus/iio/devices/iio:device0/in_temp_raw
290             //     /sys/bus/iio/devices/iio:device0/in_temp_offset
291             //     /sys/bus/iio/devices/iio:device0/in_temp_scale
292             //
293             // Other IIO devices look like this on sysfs:
294             //     /sys/bus/iio/devices/iio:device1/in_temp_input
295             //     /sys/bus/iio/devices/iio:device1/in_pressure_input
296             std::vector<fs::path> paths;
297             fs::path root("/sys/bus/iio/devices");
298             findFiles(root, R"(in_temp\d*_(input|raw))", paths);
299             findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
300             findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
301             findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
302 
303             // iterate through all found temp and pressure sensors,
304             // and try to match them with configuration
305             for (auto& path : paths)
306             {
307                 std::smatch match;
308                 const std::string pathStr = path.string();
309                 auto directory = path.parent_path();
310                 fs::path device;
311 
312                 std::string deviceName;
313                 std::error_code ec;
314                 if (pathStr.starts_with("/sys/bus/iio/devices"))
315                 {
316                     device = fs::canonical(directory, ec);
317                     if (ec)
318                     {
319                         std::cerr << "Fail to find device in path [" << pathStr
320                                   << "]\n";
321                         continue;
322                     }
323                     deviceName = device.parent_path().stem();
324                 }
325                 else
326                 {
327                     device = fs::canonical(directory / "device", ec);
328                     if (ec)
329                     {
330                         std::cerr << "Fail to find device in path [" << pathStr
331                                   << "]\n";
332                         continue;
333                     }
334                     deviceName = device.stem();
335                 }
336 
337                 uint64_t bus = 0;
338                 uint64_t addr = 0;
339                 if (!getDeviceBusAddr(deviceName, bus, addr))
340                 {
341                     continue;
342                 }
343 
344                 auto thisSensorParameters = getSensorParameters(path);
345                 auto findSensorCfg = configMap.find({bus, addr});
346                 if (findSensorCfg == configMap.end())
347                 {
348                     continue;
349                 }
350 
351                 const std::string& interfacePath =
352                     findSensorCfg->second.sensorPath;
353                 auto findI2CDev = devices.find(interfacePath);
354 
355                 std::shared_ptr<I2CDevice> i2cDev;
356                 if (findI2CDev != devices.end())
357                 {
358                     // If we're only looking to activate newly-instantiated i2c
359                     // devices and this sensor's underlying device was already
360                     // there before this call, there's nothing more to do here.
361                     if (activateOnly && !findI2CDev->second.second)
362                     {
363                         continue;
364                     }
365                     i2cDev = findI2CDev->second.first;
366                 }
367 
368                 const SensorData& sensorData = findSensorCfg->second.sensorData;
369                 std::string sensorType = findSensorCfg->second.interface;
370                 auto pos = sensorType.find_last_of('.');
371                 if (pos != std::string::npos)
372                 {
373                     sensorType = sensorType.substr(pos + 1);
374                 }
375                 const SensorBaseConfigMap& baseConfigMap =
376                     findSensorCfg->second.config;
377                 std::vector<std::string>& hwmonName =
378                     findSensorCfg->second.name;
379 
380                 // Temperature has "Name", pressure has "Name1"
381                 auto findSensorName = baseConfigMap.find("Name");
382                 int index = 1;
383                 if (thisSensorParameters.typeName == "pressure" ||
384                     thisSensorParameters.typeName == "humidity")
385                 {
386                     findSensorName = baseConfigMap.find("Name1");
387                     index = 2;
388                 }
389 
390                 if (findSensorName == baseConfigMap.end())
391                 {
392                     std::cerr << "could not determine configuration name for "
393                               << deviceName << "\n";
394                     continue;
395                 }
396                 std::string sensorName =
397                     std::get<std::string>(findSensorName->second);
398                 // on rescans, only update sensors we were signaled by
399                 auto findSensor = sensors.find(sensorName);
400                 if (!firstScan && findSensor != sensors.end())
401                 {
402                     bool found = false;
403                     auto it = sensorsChanged->begin();
404                     while (it != sensorsChanged->end())
405                     {
406                         if (it->ends_with(findSensor->second->name))
407                         {
408                             it = sensorsChanged->erase(it);
409                             findSensor->second = nullptr;
410                             found = true;
411                             break;
412                         }
413                         ++it;
414                     }
415                     if (!found)
416                     {
417                         continue;
418                     }
419                 }
420 
421                 std::vector<thresholds::Threshold> sensorThresholds;
422 
423                 if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
424                                                nullptr, &index))
425                 {
426                     std::cerr << "error populating thresholds for "
427                               << sensorName << " index " << index << "\n";
428                 }
429 
430                 float pollRate = getPollRate(baseConfigMap, pollRateDefault);
431                 PowerState readState = getPowerState(baseConfigMap);
432 
433                 auto permitSet = getPermitSet(baseConfigMap);
434                 auto& sensor = sensors[sensorName];
435                 if (!activateOnly)
436                 {
437                     sensor = nullptr;
438                 }
439                 auto hwmonFile = getFullHwmonFilePath(directory.string(),
440                                                       "temp1", permitSet);
441                 if (pathStr.starts_with("/sys/bus/iio/devices"))
442                 {
443                     hwmonFile = pathStr;
444                 }
445                 if (hwmonFile)
446                 {
447                     if (sensor != nullptr)
448                     {
449                         sensor->activate(*hwmonFile, i2cDev);
450                     }
451                     else
452                     {
453                         sensor = std::make_shared<HwmonTempSensor>(
454                             *hwmonFile, sensorType, objectServer,
455                             dbusConnection, io, sensorName,
456                             std::move(sensorThresholds), thisSensorParameters,
457                             pollRate, interfacePath, readState, i2cDev);
458                         sensor->setupRead();
459                     }
460                 }
461                 hwmonName.erase(
462                     remove(hwmonName.begin(), hwmonName.end(), sensorName),
463                     hwmonName.end());
464 
465                 // Looking for keys like "Name1" for temp2_input,
466                 // "Name2" for temp3_input, etc.
467                 int i = 0;
468                 while (true)
469                 {
470                     ++i;
471                     auto findKey =
472                         baseConfigMap.find("Name" + std::to_string(i));
473                     if (findKey == baseConfigMap.end())
474                     {
475                         break;
476                     }
477                     std::string sensorName =
478                         std::get<std::string>(findKey->second);
479                     hwmonFile = getFullHwmonFilePath(
480                         directory.string(), "temp" + std::to_string(i + 1),
481                         permitSet);
482                     if (pathStr.starts_with("/sys/bus/iio/devices"))
483                     {
484                         continue;
485                     }
486                     if (hwmonFile)
487                     {
488                         // To look up thresholds for these additional sensors,
489                         // match on the Index property in the threshold data
490                         // where the index comes from the sysfs file we're on,
491                         // i.e. index = 2 for temp2_input.
492                         int index = i + 1;
493                         std::vector<thresholds::Threshold> thresholds;
494 
495                         if (!parseThresholdsFromConfig(sensorData, thresholds,
496                                                        nullptr, &index))
497                         {
498                             std::cerr
499                                 << "error populating thresholds for "
500                                 << sensorName << " index " << index << "\n";
501                         }
502 
503                         auto& sensor = sensors[sensorName];
504                         if (!activateOnly)
505                         {
506                             sensor = nullptr;
507                         }
508 
509                         if (sensor != nullptr)
510                         {
511                             sensor->activate(*hwmonFile, i2cDev);
512                         }
513                         else
514                         {
515                             sensor = std::make_shared<HwmonTempSensor>(
516                                 *hwmonFile, sensorType, objectServer,
517                                 dbusConnection, io, sensorName,
518                                 std::move(thresholds), thisSensorParameters,
519                                 pollRate, interfacePath, readState, i2cDev);
520                             sensor->setupRead();
521                         }
522                     }
523 
524                     hwmonName.erase(
525                         remove(hwmonName.begin(), hwmonName.end(), sensorName),
526                         hwmonName.end());
527                 }
528                 if (hwmonName.empty())
529                 {
530                     configMap.erase(findSensorCfg);
531                 }
532             }
533         });
534     std::vector<std::string> types(sensorTypes.size());
535     for (const auto& [type, dt] : sensorTypes)
536     {
537         types.push_back(type);
538     }
539     getter->getConfiguration(types);
540 }
541 
interfaceRemoved(sdbusplus::message_t & message,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors)542 void interfaceRemoved(
543     sdbusplus::message_t& message,
544     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
545         sensors)
546 {
547     if (message.is_method_error())
548     {
549         std::cerr << "interfacesRemoved callback method error\n";
550         return;
551     }
552 
553     sdbusplus::message::object_path path;
554     std::vector<std::string> interfaces;
555 
556     message.read(path, interfaces);
557 
558     // If the xyz.openbmc_project.Confguration.X interface was removed
559     // for one or more sensors, delete those sensor objects.
560     auto sensorIt = sensors.begin();
561     while (sensorIt != sensors.end())
562     {
563         if (sensorIt->second && (sensorIt->second->configurationPath == path) &&
564             (std::find(interfaces.begin(), interfaces.end(),
565                        sensorIt->second->configInterface) != interfaces.end()))
566         {
567             sensorIt = sensors.erase(sensorIt);
568         }
569         else
570         {
571             sensorIt++;
572         }
573     }
574 }
575 
powerStateChanged(PowerState type,bool newState,boost::container::flat_map<std::string,std::shared_ptr<HwmonTempSensor>> & sensors,boost::asio::io_context & io,sdbusplus::asio::object_server & objectServer,std::shared_ptr<sdbusplus::asio::connection> & dbusConnection)576 static void powerStateChanged(
577     PowerState type, bool newState,
578     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
579         sensors,
580     boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
581     std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
582 {
583     if (newState)
584     {
585         createSensors(io, objectServer, sensors, dbusConnection, nullptr, true);
586     }
587     else
588     {
589         for (auto& [path, sensor] : sensors)
590         {
591             if (sensor != nullptr && sensor->readState == type)
592             {
593                 sensor->deactivate();
594             }
595         }
596     }
597 }
598 
main()599 int main()
600 {
601     boost::asio::io_context io;
602     auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
603     sdbusplus::asio::object_server objectServer(systemBus, true);
604     objectServer.add_manager("/xyz/openbmc_project/sensors");
605     systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
606 
607     boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
608         sensors;
609     auto sensorsChanged =
610         std::make_shared<boost::container::flat_set<std::string>>();
611 
612     auto powerCallBack = [&sensors, &io, &objectServer,
613                           &systemBus](PowerState type, bool state) {
614         powerStateChanged(type, state, sensors, io, objectServer, systemBus);
615     };
616     setupPowerMatchCallback(systemBus, powerCallBack);
617 
618     boost::asio::post(io, [&]() {
619         createSensors(io, objectServer, sensors, systemBus, nullptr, false);
620     });
621 
622     boost::asio::steady_timer filterTimer(io);
623     std::function<void(sdbusplus::message_t&)> eventHandler =
624         [&](sdbusplus::message_t& message) {
625             if (message.is_method_error())
626             {
627                 std::cerr << "callback method error\n";
628                 return;
629             }
630             sensorsChanged->insert(message.get_path());
631             // this implicitly cancels the timer
632             filterTimer.expires_after(std::chrono::seconds(1));
633 
634             filterTimer.async_wait([&](const boost::system::error_code& ec) {
635                 if (ec == boost::asio::error::operation_aborted)
636                 {
637                     /* we were canceled*/
638                     return;
639                 }
640                 if (ec)
641                 {
642                     std::cerr << "timer error\n";
643                     return;
644                 }
645                 createSensors(io, objectServer, sensors, systemBus,
646                               sensorsChanged, false);
647             });
648         };
649 
650     std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
651         setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
652     setupManufacturingModeMatch(*systemBus);
653 
654     // Watch for entity-manager to remove configuration interfaces
655     // so the corresponding sensors can be removed.
656     auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match_t>(
657         static_cast<sdbusplus::bus_t&>(*systemBus),
658         "type='signal',member='InterfacesRemoved',arg0path='" +
659             std::string(inventoryPath) + "/'",
660         [&sensors](sdbusplus::message_t& msg) {
661             interfaceRemoved(msg, sensors);
662         });
663 
664     matches.emplace_back(std::move(ifaceRemovedMatch));
665 
666     io.run();
667 }
668