WLAN-Pi / wlanpi-profiler

Wi-Fi client capabilities analyzer tool built for the WLAN Pi
BSD 3-Clause "New" or "Revised" License
25 stars 9 forks source link

Send SIGINT and add exception handling when WLAN NIC is removed #4

Closed joshschmelzle closed 3 years ago

joshschmelzle commented 4 years ago

profiler2 version 0.0.1.dev1

when WLAN NIC is removed an OSError is thrown. handle exception and gracefully shut down. otherwise, user is forced to manually send SIGINT/Ctrl-C.

Process txbeacons:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/home/wlanpi/profiler2/profiler2/fakeap.py", line 110, in __init__
    self.every(self.beacon_interval, self.beacon)
  File "/home/wlanpi/profiler2/profiler2/fakeap.py", line 116, in every
    task()
  File "/home/wlanpi/profiler2/profiler2/fakeap.py", line 144, in beacon
    self.l2socket.send(frame)
  File "/usr/local/lib/python3.7/site-packages/scapy/arch/linux.py", line 559, in send
    return SuperSocket.send(self, x)
  File "/usr/local/lib/python3.7/site-packages/scapy/supersocket.py", line 49, in send
    sent = self.outs.send(sx)
OSError: [Errno 6] No such device or address
Exception ignored in: <function SuperSocket.__del__ at 0xffff9ba539e0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/scapy/supersocket.py", line 134, in __del__
    self.close()
  File "/usr/local/lib/python3.7/site-packages/scapy/arch/linux.py", line 514, in close
    set_promisc(self.ins, self.iface, 0)
  File "/usr/local/lib/python3.7/site-packages/scapy/arch/linux.py", line 165, in set_promisc
    mreq = struct.pack("IHH8s", get_if_index(iff), PACKET_MR_PROMISC, 0, b"")
  File "/usr/local/lib/python3.7/site-packages/scapy/arch/linux.py", line 380, in get_if_index
    return int(struct.unpack("I", get_if(iff, SIOCGIFINDEX)[16:20])[0])
  File "/usr/local/lib/python3.7/site-packages/scapy/arch/common.py", line 59, in get_if
    ifreq = ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
OSError: [Errno 19] No such device
joshschmelzle commented 4 years ago

Looks like I need to refactor the processes for graceful shutdown when this occurs. Something like this may work: https://stackoverflow.com/questions/1231599/python-multiprocessing-exit-elegantly-how

joshschmelzle commented 3 years ago

Done in f915db2b6332f5c170f1bdd669419580ce251e3f