1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
3
4 #include "perform_scan.hpp"
5
6 #include "perform_probe.hpp"
7 #include "utils.hpp"
8
9 #include <boost/asio/steady_timer.hpp>
10 #include <phosphor-logging/lg2.hpp>
11
12 #include <cerrno>
13 #include <charconv>
14 #include <flat_map>
15 #include <flat_set>
16
17 using GetSubTreeType = std::vector<
18 std::pair<std::string,
19 std::vector<std::pair<std::string, std::vector<std::string>>>>>;
20
21 constexpr const int32_t maxMapperDepth = 0;
22
23 struct DBusInterfaceInstance
24 {
25 std::string busName;
26 std::string path;
27 std::string interface;
28 };
29
getInterfaces(const DBusInterfaceInstance & instance,const std::vector<std::shared_ptr<probe::PerformProbe>> & probeVector,const std::shared_ptr<scan::PerformScan> & scan,boost::asio::io_context & io,size_t retries=5)30 void getInterfaces(
31 const DBusInterfaceInstance& instance,
32 const std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector,
33 const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io,
34 size_t retries = 5)
35 {
36 if (retries == 0U)
37 {
38 lg2::error("retries exhausted on {BUSNAME} {PATH} {INTF}", "BUSNAME",
39 instance.busName, "PATH", instance.path, "INTF",
40 instance.interface);
41 return;
42 }
43
44 scan->_em.systemBus->async_method_call(
45 [instance, scan, probeVector, retries,
46 &io](boost::system::error_code& errc,
47 const DBusInterface& resp) mutable {
48 if (errc)
49 {
50 // EBADR indicates the D-Bus object was removed between
51 // GetSubTree and GetAll. This corresponds to
52 // org.freedesktop.DBus.Error.UnknownObject and is expected
53 // during concurrent device removal. Skip retry to avoid
54 // unnecessary delays.
55 if (errc.value() == EBADR)
56 {
57 lg2::info("D-Bus object removed during scan, skipping: "
58 "{BUSNAME} {PATH} {INTF}",
59 "BUSNAME", instance.busName, "PATH",
60 instance.path, "INTF", instance.interface);
61 return;
62 }
63
64 lg2::error("error calling getall on {BUSNAME} {PATH} {INTF}",
65 "BUSNAME", instance.busName, "PATH", instance.path,
66 "INTF", instance.interface);
67
68 auto timer = std::make_shared<boost::asio::steady_timer>(io);
69 timer->expires_after(std::chrono::seconds(2));
70
71 timer->async_wait([timer, instance, scan, probeVector, retries,
72 &io](const boost::system::error_code&) {
73 getInterfaces(instance, probeVector, scan, io, retries - 1);
74 });
75 return;
76 }
77
78 scan->dbusProbeObjects[std::string(instance.path)]
79 [std::string(instance.interface)] = resp;
80 },
81 instance.busName, instance.path, "org.freedesktop.DBus.Properties",
82 "GetAll", instance.interface);
83 }
84
processDbusObjects(std::vector<std::shared_ptr<probe::PerformProbe>> & probeVector,const std::shared_ptr<scan::PerformScan> & scan,const GetSubTreeType & interfaceSubtree,boost::asio::io_context & io)85 static void processDbusObjects(
86 std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector,
87 const std::shared_ptr<scan::PerformScan>& scan,
88 const GetSubTreeType& interfaceSubtree, boost::asio::io_context& io)
89 {
90 for (const auto& [path, object] : interfaceSubtree)
91 {
92 // Get a PropertiesChanged callback for all interfaces on this path.
93 scan->_em.registerCallback(path);
94
95 for (const auto& [busname, ifaces] : object)
96 {
97 for (const std::string& iface : ifaces)
98 {
99 // The 3 default org.freedeskstop interfaces (Peer,
100 // Introspectable, and Properties) are returned by
101 // the mapper but don't have properties, so don't bother
102 // with the GetAll call to save some cycles.
103 if (!iface.starts_with("org.freedesktop"))
104 {
105 getInterfaces({busname, path, iface}, probeVector, scan,
106 io);
107 }
108 }
109 }
110 }
111 }
112
113 // Populates scan->dbusProbeObjects with all interfaces and properties
114 // for the paths that own the interfaces passed in.
findDbusObjects(std::vector<std::shared_ptr<probe::PerformProbe>> && probeVector,std::flat_set<std::string,std::less<>> && interfaces,const std::shared_ptr<scan::PerformScan> & scan,boost::asio::io_context & io,size_t retries=5)115 void findDbusObjects(
116 std::vector<std::shared_ptr<probe::PerformProbe>>&& probeVector,
117 std::flat_set<std::string, std::less<>>&& interfaces,
118 const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io,
119 size_t retries = 5)
120 {
121 // Filter out interfaces already obtained.
122 for (const auto& [path, probeInterfaces] : scan->dbusProbeObjects)
123 {
124 for (const auto& [interface, _] : probeInterfaces)
125 {
126 interfaces.erase(interface);
127 }
128 }
129 if (interfaces.empty())
130 {
131 return;
132 }
133
134 // find all connections in the mapper that expose a specific type
135 scan->_em.systemBus->async_method_call(
136 [interfaces, probeVector{std::move(probeVector)}, scan, retries,
137 &io](boost::system::error_code& ec,
138 const GetSubTreeType& interfaceSubtree) mutable {
139 if (ec)
140 {
141 if (ec.value() == ENOENT)
142 {
143 return; // wasn't found by mapper
144 }
145 lg2::error("Error communicating to mapper.");
146
147 if (retries == 0U)
148 {
149 // if we can't communicate to the mapper something is very
150 // wrong
151 std::exit(EXIT_FAILURE);
152 }
153
154 auto timer = std::make_shared<boost::asio::steady_timer>(io);
155 timer->expires_after(std::chrono::seconds(10));
156
157 timer->async_wait(
158 [timer, interfaces{std::move(interfaces)}, scan,
159 probeVector{std::move(probeVector)}, retries,
160 &io](const boost::system::error_code&) mutable {
161 findDbusObjects(std::move(probeVector),
162 std::move(interfaces), scan, io,
163 retries - 1);
164 });
165 return;
166 }
167
168 processDbusObjects(probeVector, scan, interfaceSubtree, io);
169 },
170 "xyz.openbmc_project.ObjectMapper",
171 "/xyz/openbmc_project/object_mapper",
172 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", maxMapperDepth,
173 interfaces);
174 }
175
getRecordName(const DBusInterface & probe,const std::string & probeName)176 static std::string getRecordName(const DBusInterface& probe,
177 const std::string& probeName)
178 {
179 if (probe.empty())
180 {
181 return probeName;
182 }
183
184 // use an array so alphabetical order from the flat_map is maintained
185 auto device = nlohmann::json::array();
186 for (const auto& devPair : probe)
187 {
188 device.push_back(devPair.first);
189 std::visit([&device](auto&& v) { device.push_back(v); },
190 devPair.second);
191 }
192
193 // hashes are hard to distinguish, use the non-hashed version if we want
194 // debug
195 // return probeName + device.dump();
196
197 return std::to_string(std::hash<std::string>{}(probeName + device.dump()));
198 }
199
PerformScan(EntityManager & em,nlohmann::json & missingConfigurations,std::vector<nlohmann::json> & configurations,boost::asio::io_context & io,std::function<void ()> && callback)200 scan::PerformScan::PerformScan(
201 EntityManager& em, nlohmann::json& missingConfigurations,
202 std::vector<nlohmann::json>& configurations, boost::asio::io_context& io,
203 std::function<void()>&& callback) :
204 _em(em), _missingConfigurations(missingConfigurations),
205 _configurations(configurations), _callback(std::move(callback)), io(io)
206 {}
207
pruneRecordExposes(nlohmann::json & record)208 static void pruneRecordExposes(nlohmann::json& record)
209 {
210 auto findExposes = record.find("Exposes");
211 if (findExposes == record.end())
212 {
213 return;
214 }
215
216 auto copy = nlohmann::json::array();
217 for (auto& expose : *findExposes)
218 {
219 if (!expose.is_null())
220 {
221 copy.emplace_back(expose);
222 }
223 }
224 *findExposes = copy;
225 }
226
recordDiscoveredIdentifiers(std::set<nlohmann::json> & usedNames,std::list<size_t> & indexes,const std::string & probeName,const nlohmann::json & record)227 static void recordDiscoveredIdentifiers(
228 std::set<nlohmann::json>& usedNames, std::list<size_t>& indexes,
229 const std::string& probeName, const nlohmann::json& record)
230 {
231 size_t indexIdx = probeName.find('$');
232 if (indexIdx == std::string::npos)
233 {
234 return;
235 }
236
237 auto nameIt = record.find("Name");
238 if (nameIt == record.end())
239 {
240 lg2::error("Last JSON Illegal");
241 return;
242 }
243
244 int index = 0;
245 auto str = nameIt->get<std::string>().substr(indexIdx);
246 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
247 const char* endPtr = str.data() + str.size();
248 auto [p, ec] = std::from_chars(str.data(), endPtr, index);
249 if (ec != std::errc())
250 {
251 return; // non-numeric replacement
252 }
253
254 usedNames.insert(nameIt.value());
255
256 auto usedIt = std::find(indexes.begin(), indexes.end(), index);
257 if (usedIt != indexes.end())
258 {
259 indexes.erase(usedIt);
260 }
261 }
262
extractExposeActionRecordNames(std::vector<std::string> & matches,const std::string & exposeKey,nlohmann::json & exposeValue)263 static bool extractExposeActionRecordNames(std::vector<std::string>& matches,
264 const std::string& exposeKey,
265 nlohmann::json& exposeValue)
266 {
267 const std::string* exposeValueStr =
268 exposeValue.get_ptr<const std::string*>();
269 if (exposeValueStr != nullptr)
270 {
271 matches.emplace_back(*exposeValueStr);
272 return true;
273 }
274
275 const nlohmann::json::array_t* exarr =
276 exposeValue.get_ptr<const nlohmann::json::array_t*>();
277 if (exarr != nullptr)
278 {
279 for (const auto& value : *exarr)
280 {
281 if (!value.is_string())
282 {
283 lg2::error("Value is invalid type {VALUE}", "VALUE", value);
284 break;
285 }
286 matches.emplace_back(value);
287 }
288
289 return true;
290 }
291
292 lg2::error("Value is invalid type {KEY}", "KEY", exposeKey);
293 return false;
294 }
295
findExposeActionRecord(std::vector<std::string> & matches,const nlohmann::json & record)296 static std::optional<std::vector<std::string>::iterator> findExposeActionRecord(
297 std::vector<std::string>& matches, const nlohmann::json& record)
298 {
299 const auto& name = (record)["Name"].get_ref<const std::string&>();
300 auto compare = [&name](const std::string& s) { return s == name; };
301 auto matchIt = std::find_if(matches.begin(), matches.end(), compare);
302
303 if (matchIt == matches.end())
304 {
305 return std::nullopt;
306 }
307
308 return matchIt;
309 }
310
applyBindExposeAction(nlohmann::json::object_t & exposedObject,nlohmann::json::object_t & expose,const std::string & propertyName)311 static void applyBindExposeAction(nlohmann::json::object_t& exposedObject,
312 nlohmann::json::object_t& expose,
313 const std::string& propertyName)
314 {
315 if (propertyName.starts_with("Bind"))
316 {
317 std::string bind = propertyName.substr(sizeof("Bind") - 1);
318 exposedObject["Status"] = "okay";
319 expose[bind] = exposedObject;
320 }
321 }
322
applyDisableExposeAction(nlohmann::json::object_t & exposedObject,const std::string & propertyName)323 static void applyDisableExposeAction(nlohmann::json::object_t& exposedObject,
324 const std::string& propertyName)
325 {
326 if (propertyName == "DisableNode")
327 {
328 exposedObject["Status"] = "disabled";
329 }
330 }
331
applyConfigExposeActions(std::vector<std::string> & matches,nlohmann::json::object_t & expose,const std::string & propertyName,nlohmann::json::array_t & configExposes)332 static void applyConfigExposeActions(
333 std::vector<std::string>& matches, nlohmann::json::object_t& expose,
334 const std::string& propertyName, nlohmann::json::array_t& configExposes)
335 {
336 for (auto& exposedObject : configExposes)
337 {
338 auto match = findExposeActionRecord(matches, exposedObject);
339 if (match)
340 {
341 matches.erase(*match);
342 nlohmann::json::object_t* exposedObjectObj =
343 exposedObject.get_ptr<nlohmann::json::object_t*>();
344 if (exposedObjectObj == nullptr)
345 {
346 lg2::error("Exposed object wasn't a object: {JSON}", "JSON",
347 exposedObject.dump());
348 continue;
349 }
350
351 applyBindExposeAction(*exposedObjectObj, expose, propertyName);
352 applyDisableExposeAction(*exposedObjectObj, propertyName);
353 }
354 }
355 }
356
applyExposeActions(nlohmann::json & systemConfiguration,const std::string & recordName,nlohmann::json::object_t & expose,const std::string & exposeKey,nlohmann::json & exposeValue)357 static void applyExposeActions(
358 nlohmann::json& systemConfiguration, const std::string& recordName,
359 nlohmann::json::object_t& expose, const std::string& exposeKey,
360 nlohmann::json& exposeValue)
361 {
362 bool isBind = exposeKey.starts_with("Bind");
363 bool isDisable = exposeKey == "DisableNode";
364 bool isExposeAction = isBind || isDisable;
365
366 if (!isExposeAction)
367 {
368 return;
369 }
370
371 std::vector<std::string> matches;
372
373 if (!extractExposeActionRecordNames(matches, exposeKey, exposeValue))
374 {
375 return;
376 }
377
378 for (const auto& [configId, config] : systemConfiguration.items())
379 {
380 // don't disable ourselves
381 if (isDisable && configId == recordName)
382 {
383 continue;
384 }
385
386 auto configListFind = config.find("Exposes");
387 if (configListFind == config.end())
388 {
389 continue;
390 }
391
392 nlohmann::json::array_t* configList =
393 configListFind->get_ptr<nlohmann::json::array_t*>();
394 if (configList == nullptr)
395 {
396 continue;
397 }
398 applyConfigExposeActions(matches, expose, exposeKey, *configList);
399 }
400
401 if (!matches.empty())
402 {
403 lg2::error(
404 "configuration file dependency error, could not find {KEY} {VALUE}",
405 "KEY", exposeKey, "VALUE", exposeValue);
406 }
407 }
408
generateDeviceName(const std::set<nlohmann::json> & usedNames,const DBusObject & dbusObject,size_t foundDeviceIdx,const std::string & nameTemplate,std::optional<std::string> & replaceStr)409 static std::string generateDeviceName(
410 const std::set<nlohmann::json>& usedNames, const DBusObject& dbusObject,
411 size_t foundDeviceIdx, const std::string& nameTemplate,
412 std::optional<std::string>& replaceStr)
413 {
414 nlohmann::json copyForName = nameTemplate;
415 std::optional<std::string> replaceVal = em_utils::templateCharReplace(
416 copyForName, dbusObject, foundDeviceIdx, replaceStr);
417
418 if (!replaceStr && replaceVal)
419 {
420 if (usedNames.contains(nameTemplate))
421 {
422 replaceStr = replaceVal;
423 em_utils::templateCharReplace(copyForName, dbusObject,
424 foundDeviceIdx, replaceStr);
425 }
426 }
427
428 if (replaceStr)
429 {
430 lg2::error(
431 "Duplicates found, replacing {STR} with found device index. Consider fixing template to not have duplicates",
432 "STR", *replaceStr);
433 }
434 const std::string* ret = copyForName.get_ptr<const std::string*>();
435 if (ret == nullptr)
436 {
437 lg2::error("Device name wasn't a string: ${JSON}", "JSON",
438 copyForName.dump());
439 return "";
440 }
441 return *ret;
442 }
applyTemplateAndExposeActions(const std::string & recordName,const DBusObject & dbusObject,size_t foundDeviceIdx,const std::optional<std::string> & replaceStr,nlohmann::json & value,nlohmann::json & systemConfiguration)443 static void applyTemplateAndExposeActions(
444 const std::string& recordName, const DBusObject& dbusObject,
445 size_t foundDeviceIdx, const std::optional<std::string>& replaceStr,
446 nlohmann::json& value, nlohmann::json& systemConfiguration)
447 {
448 nlohmann::json::object_t* exposeObj =
449 value.get_ptr<nlohmann::json::object_t*>();
450 if (exposeObj == nullptr)
451 {
452 return;
453 }
454 for (auto& [key, value] : *exposeObj)
455 {
456 em_utils::templateCharReplace(value, dbusObject, foundDeviceIdx,
457 replaceStr);
458
459 applyExposeActions(systemConfiguration, recordName, *exposeObj, key,
460 value);
461 }
462 };
463
updateSystemConfiguration(const nlohmann::json & recordRef,const std::string & probeName,FoundDevices & foundDevices)464 void scan::PerformScan::updateSystemConfiguration(
465 const nlohmann::json& recordRef, const std::string& probeName,
466 FoundDevices& foundDevices)
467 {
468 _passed = true;
469 passedProbes.push_back(probeName);
470
471 std::set<nlohmann::json> usedNames;
472 std::list<size_t> indexes(foundDevices.size());
473 std::iota(indexes.begin(), indexes.end(), 1);
474
475 // copy over persisted configurations and make sure we remove
476 // indexes that are already used
477 for (auto itr = foundDevices.begin(); itr != foundDevices.end();)
478 {
479 std::string recordName = getRecordName(itr->interface, probeName);
480
481 auto record = _em.systemConfiguration.find(recordName);
482 if (record == _em.systemConfiguration.end())
483 {
484 record = _em.lastJson.find(recordName);
485 if (record == _em.lastJson.end())
486 {
487 itr++;
488 continue;
489 }
490
491 pruneRecordExposes(*record);
492
493 _em.systemConfiguration[recordName] = *record;
494 }
495 _missingConfigurations.erase(recordName);
496
497 // We've processed the device, remove it and advance the
498 // iterator
499 itr = foundDevices.erase(itr);
500 recordDiscoveredIdentifiers(usedNames, indexes, probeName, *record);
501 }
502
503 std::optional<std::string> replaceStr;
504
505 DBusObject emptyObject;
506 DBusInterface emptyInterface;
507 emptyObject.emplace(std::string{}, emptyInterface);
508
509 for (const auto& [foundDevice, path] : foundDevices)
510 {
511 // Need all interfaces on this path so that template
512 // substitutions can be done with any of the contained
513 // properties. If the probe that passed didn't use an
514 // interface, such as if it was just TRUE, then
515 // templateCharReplace will just get passed in an empty
516 // map.
517 auto objectIt = dbusProbeObjects.find(path);
518 const DBusObject& dbusObject = (objectIt == dbusProbeObjects.end())
519 ? emptyObject
520 : objectIt->second;
521
522 const nlohmann::json::object_t* recordPtr =
523 recordRef.get_ptr<const nlohmann::json::object_t*>();
524 if (recordPtr == nullptr)
525 {
526 lg2::error("Failed to parse record {JSON}", "JSON",
527 recordRef.dump());
528 continue;
529 }
530 nlohmann::json::object_t record = *recordPtr;
531 std::string recordName = getRecordName(foundDevice, probeName);
532 size_t foundDeviceIdx = indexes.front();
533 indexes.pop_front();
534
535 // check name first so we have no duplicate names
536 auto getName = record.find("Name");
537 if (getName == record.end())
538 {
539 lg2::error("Record Missing Name! {JSON}", "JSON", recordRef.dump());
540 continue; // this should be impossible at this level
541 }
542
543 const std::string* name = getName->second.get_ptr<const std::string*>();
544 if (name == nullptr)
545 {
546 lg2::error("Name wasn't a string: {JSON}", "JSON",
547 recordRef.dump());
548 continue;
549 }
550
551 std::string deviceName = generateDeviceName(
552 usedNames, dbusObject, foundDeviceIdx, *name, replaceStr);
553
554 record["Name"] = deviceName;
555
556 usedNames.insert(deviceName);
557
558 for (auto& keyPair : record)
559 {
560 if (keyPair.first != "Name")
561 {
562 // "Probe" string does not contain template variables
563 // Handle left-over variables for "Exposes" later below
564 const bool handleLeftOver =
565 (keyPair.first != "Probe") && (keyPair.first != "Exposes");
566 em_utils::templateCharReplace(keyPair.second, dbusObject,
567 foundDeviceIdx, replaceStr,
568 handleLeftOver);
569 }
570 }
571
572 // insert into configuration temporarily to be able to
573 // reference ourselves
574
575 _em.systemConfiguration[recordName] = record;
576
577 auto findExpose = record.find("Exposes");
578 if (findExpose == record.end())
579 {
580 continue;
581 }
582
583 nlohmann::json::array_t* exposeArr =
584 findExpose->second.get_ptr<nlohmann::json::array_t*>();
585 if (exposeArr != nullptr)
586 {
587 for (auto& value : *exposeArr)
588 {
589 applyTemplateAndExposeActions(recordName, dbusObject,
590 foundDeviceIdx, replaceStr, value,
591 _em.systemConfiguration);
592 }
593 }
594 else
595 {
596 applyTemplateAndExposeActions(
597 recordName, dbusObject, foundDeviceIdx, replaceStr,
598 findExpose->second, _em.systemConfiguration);
599 }
600
601 // If we end up here and the path is empty, we have Probe: "True"
602 // and we dont want that to show up in the associations.
603 if (!path.empty())
604 {
605 auto boardType = record.find("Type")->second.get<std::string>();
606 auto boardName = record.find("Name")->second.get<std::string>();
607 std::string boardInventoryPath =
608 em_utils::buildInventorySystemPath(boardName, boardType);
609 _em.topology.addProbePath(boardInventoryPath, path);
610 }
611
612 // overwrite ourselves with cleaned up version
613 _em.systemConfiguration[recordName] = record;
614 _missingConfigurations.erase(recordName);
615 }
616 }
617
run()618 void scan::PerformScan::run()
619 {
620 std::flat_set<std::string, std::less<>> dbusProbeInterfaces;
621 std::vector<std::shared_ptr<probe::PerformProbe>> dbusProbePointers;
622
623 for (auto it = _configurations.begin(); it != _configurations.end();)
624 {
625 // check for poorly formatted fields, probe must be an array
626 auto findProbe = it->find("Probe");
627 if (findProbe == it->end())
628 {
629 lg2::error("configuration file missing probe:\n {JSON}", "JSON",
630 *it);
631 it = _configurations.erase(it);
632 continue;
633 }
634
635 auto findName = it->find("Name");
636 if (findName == it->end())
637 {
638 lg2::error("configuration file missing name:\n {JSON}", "JSON",
639 *it);
640 it = _configurations.erase(it);
641 continue;
642 }
643
644 const std::string* probeName = findName->get_ptr<const std::string*>();
645 if (probeName == nullptr)
646 {
647 lg2::error("Name wasn't a string? {JSON}", "JSON", *it);
648 it = _configurations.erase(it);
649 continue;
650 }
651
652 if (std::find(passedProbes.begin(), passedProbes.end(), *probeName) !=
653 passedProbes.end())
654 {
655 it = _configurations.erase(it);
656 continue;
657 }
658
659 nlohmann::json& recordRef = *it;
660 std::vector<std::string> probeCommand;
661 nlohmann::json::array_t* probeCommandArrayPtr =
662 findProbe->get_ptr<nlohmann::json::array_t*>();
663 if (probeCommandArrayPtr != nullptr)
664 {
665 for (const auto& probe : *probeCommandArrayPtr)
666 {
667 const std::string* probeStr =
668 probe.get_ptr<const std::string*>();
669 if (probeStr == nullptr)
670 {
671 lg2::error("Probe statement wasn't a string, can't parse");
672 return;
673 }
674 probeCommand.push_back(*probeStr);
675 }
676 }
677 else
678 {
679 const std::string* probeStr =
680 findProbe->get_ptr<const std::string*>();
681 if (probeStr == nullptr)
682 {
683 lg2::error("Probe statement wasn't a string, can't parse");
684 return;
685 }
686 probeCommand.push_back(*probeStr);
687 }
688
689 // store reference to this to children to makes sure we don't get
690 // destroyed too early
691 auto thisRef = shared_from_this();
692 auto probePointer = std::make_shared<probe::PerformProbe>(
693 recordRef, probeCommand, *probeName, thisRef);
694
695 // parse out dbus probes by discarding other probe types, store in a
696 // map
697 for (const std::string& probe : probeCommand)
698 {
699 if (probe::findProbeType(probe))
700 {
701 continue;
702 }
703 // syntax requires probe before first open brace
704 auto findStart = probe.find('(');
705 std::string interface = probe.substr(0, findStart);
706 dbusProbeInterfaces.emplace(interface);
707 dbusProbePointers.emplace_back(probePointer);
708 }
709 it++;
710 }
711
712 // probe vector stores a shared_ptr to each PerformProbe that cares
713 // about a dbus interface
714 findDbusObjects(std::move(dbusProbePointers),
715 std::move(dbusProbeInterfaces), shared_from_this(), io);
716 }
717
~PerformScan()718 scan::PerformScan::~PerformScan()
719 {
720 if (_passed)
721 {
722 auto nextScan = std::make_shared<PerformScan>(
723 _em, _missingConfigurations, _configurations, io,
724 std::move(_callback));
725 nextScan->passedProbes = std::move(passedProbes);
726 nextScan->dbusProbeObjects = std::move(dbusProbeObjects);
727 boost::asio::post(_em.io, [nextScan]() { nextScan->run(); });
728 }
729 else
730 {
731 _callback();
732 }
733 }
734