Do all of dhcp scapy startup in the executor (#57392)

This commit is contained in:
J. Nick Koston 2021-10-09 21:00:28 -10:00 committed by GitHub
parent 49d97e13de
commit be8724a6f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,6 +276,10 @@ class DHCPWatcher(WatcherBase):
self._sniffer.stop()
async def async_start(self):
"""Start watching for dhcp packets."""
await self.hass.async_add_executor_job(self._start)
def _start(self):
"""Start watching for dhcp packets."""
# Local import because importing from scapy has side effects such as opening
# sockets
@ -319,7 +323,7 @@ class DHCPWatcher(WatcherBase):
conf.sniff_promisc = 0
try:
await self.hass.async_add_executor_job(_verify_l2socket_setup, FILTER)
_verify_l2socket_setup(FILTER)
except (Scapy_Exception, OSError) as ex:
if os.geteuid() == 0:
_LOGGER.error("Cannot watch for dhcp packets: %s", ex)
@ -330,7 +334,7 @@ class DHCPWatcher(WatcherBase):
return
try:
await self.hass.async_add_executor_job(_verify_working_pcap, FILTER)
_verify_working_pcap(FILTER)
except (Scapy_Exception, ImportError) as ex:
_LOGGER.error(
"Cannot watch for dhcp packets without a functional packet filter: %s",