MCPcopy Create free account
hub / github.com/USBGuard/usbguard / umockdevProcessInotify

Method umockdevProcessInotify

src/Library/UMockdevDeviceManager.cpp:242–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240 }
241
242 void UMockdevDeviceManager::umockdevProcessInotify()
243 {
244 char buffer[sizeof (inotify_event) + NAME_MAX + 1] __attribute__((aligned(__alignof__(inotify_event))));
245
246 if (read (_inotify_fd, buffer, sizeof buffer) <= 0) {
247 USBGUARD_LOG(Warning) << "Inotify event read size mismatch";
248 return;
249 }
250
251 const struct inotify_event* const event = reinterpret_cast<inotify_event*>(buffer);
252
253 if (event->len <= 0 || event->len > NAME_MAX) {
254 USBGUARD_LOG(Warning) << "Inotify event pathname size is out-of-range.";
255 return;
256 }
257
258 std::string definitions_path(event->name, event->len);
259 USBGUARD_LOG(Debug) << "inotify: definitions_path= " << definitions_path << " event_mask=" << event->mask;
260
261 if (event->mask & IN_CREATE) {
262 USBGUARD_LOG(Debug) << "inotify: IN_CREATE";
263
264 for (const auto& sysfs_path : umockdevLoadFromFile(_umockdev_deviceroot + "/" + definitions_path)) {
265 umockdevAdd(_sysfs_path_map.at(sysfs_path));
266 //umockdev_testbed_uevent(_testbed.get(), sysfs_path.c_str(), "add");
267 }
268 }
269 else if (event->mask & IN_DELETE) {
270 USBGUARD_LOG(Debug) << "inotify: IN_DELETE";
271
272 for (const auto& sysfs_path : umockdevRemoveByFile(_umockdev_deviceroot + "/" + definitions_path)) {
273 umockdevRemove(_sysfs_path_map.at(sysfs_path));
274 //umockdev_testbed_uevent(_testbed.get(), sysfs_path.c_str(), "remove");
275 }
276 }
277 else {
278 USBGUARD_LOG(Debug) << "inotify: Ignoring event.";
279 }
280 }
281
282 std::vector<std::string> UMockdevDeviceManager::umockdevLoadFromFile(const std::string& definitions_path)
283 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected