| 440 | } |
| 441 | |
| 442 | void UMockdevDeviceManager::thread() |
| 443 | { |
| 444 | USBGUARD_LOG(Trace) << "Entering main loop."; |
| 445 | |
| 446 | try { |
| 447 | const int max_fd = std::max(_uevent_fd, std::max(_wakeup_fd, _inotify_fd)); |
| 448 | fd_set readset; |
| 449 | |
| 450 | while (!_thread.stopRequested()) { |
| 451 | struct timeval tv_timeout = { 5, 0 }; |
| 452 | FD_ZERO(&readset); |
| 453 | FD_SET(_uevent_fd, &readset); |
| 454 | FD_SET(_wakeup_fd, &readset); |
| 455 | FD_SET(_inotify_fd, &readset); |
| 456 | |
| 457 | switch (select(max_fd + 1, &readset, NULL, NULL, &tv_timeout)) { |
| 458 | case 1: |
| 459 | case 2: |
| 460 | case 3: |
| 461 | if (FD_ISSET(_wakeup_fd, &readset)) { |
| 462 | USBGUARD_LOG(Debug) << "Wakeup event."; |
| 463 | continue; |
| 464 | } |
| 465 | |
| 466 | if (FD_ISSET(_uevent_fd, &readset)) { |
| 467 | USBGUARD_LOG(Debug) << "UEvent read event."; |
| 468 | ueventProcessRead(); |
| 469 | } |
| 470 | |
| 471 | if (FD_ISSET(_inotify_fd, &readset)) { |
| 472 | USBGUARD_LOG(Debug) << "Inotify event."; |
| 473 | umockdevProcessInotify(); |
| 474 | } |
| 475 | |
| 476 | break; |
| 477 | |
| 478 | case 0: /* Timeout */ |
| 479 | continue; |
| 480 | |
| 481 | case -1: /* Error */ |
| 482 | default: |
| 483 | USBGUARD_LOG(Error) << "UMockdevDeviceManager thread: select failed: errno=" << errno; |
| 484 | _thread.stop(); |
| 485 | } |
| 486 | } /* Thread main loop */ |
| 487 | } |
| 488 | catch (const Exception& ex) { |
| 489 | USBGUARD_LOG(Error) << "UMockdevDeviceManager thread: " << ex.message(); |
| 490 | } |
| 491 | |
| 492 | USBGUARD_LOG(Trace) << "Leaving main loop."; |
| 493 | } |
| 494 | |
| 495 | void UMockdevDeviceManager::ueventProcessRead() |
| 496 | { |
nothing calls this directly
no test coverage detected