Commit 57191ead authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Kernel.py: wait for thread when exiting

Wait for thread loop to return when exiting
parent 38074386
...@@ -51,9 +51,9 @@ class Kernel(metaclass=ABCMeta): ...@@ -51,9 +51,9 @@ class Kernel(metaclass=ABCMeta):
self.tree_logger = Main.logger.getChild('KernelTree') self.tree_logger = Main.logger.getChild('KernelTree')
# receive signals from kernel with a background thread # receive signals from kernel with a background thread
handler_thread = Thread(target=self.handler) self.handler_thread = Thread(target=self.handler)
handler_thread.daemon = True self.handler_thread.daemon = True
handler_thread.start() self.handler_thread.start()
''' '''
Structure to create/remove virtual interfaces Structure to create/remove virtual interfaces
...@@ -177,9 +177,14 @@ class Kernel(metaclass=ABCMeta): ...@@ -177,9 +177,14 @@ class Kernel(metaclass=ABCMeta):
raise NotImplementedError raise NotImplementedError
@abstractmethod @abstractmethod
def exit(self): def close_socket(self):
raise NotImplementedError raise NotImplementedError
def exit(self):
self.running = False
self.close_socket()
self.handler_thread.join()
@abstractmethod @abstractmethod
def handler(self): def handler(self):
raise NotImplementedError raise NotImplementedError
...@@ -412,12 +417,15 @@ class Kernel4(Kernel): ...@@ -412,12 +417,15 @@ class Kernel4(Kernel):
if len(self.routing[kernel_entry.source_ip]) == 0: if len(self.routing[kernel_entry.source_ip]) == 0:
self.routing.pop(kernel_entry.source_ip) self.routing.pop(kernel_entry.source_ip)
def exit(self): def close_socket(self):
self.running = False with socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IGMP) as s:
s.sendto(b'', ('', 0))
self.socket.close()
def exit(self):
# MRT DONE # MRT DONE
self.socket.setsockopt(socket.IPPROTO_IP, self.MRT_DONE, 1) self.socket.setsockopt(socket.IPPROTO_IP, self.MRT_DONE, 1)
self.socket.close() super().exit()
''' '''
...@@ -660,12 +668,15 @@ class Kernel6(Kernel): ...@@ -660,12 +668,15 @@ class Kernel6(Kernel):
if len(self.routing[kernel_entry.source_ip]) == 0: if len(self.routing[kernel_entry.source_ip]) == 0:
self.routing.pop(kernel_entry.source_ip) self.routing.pop(kernel_entry.source_ip)
def exit(self): def close_socket(self):
self.running = False with socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6) as s:
s.sendto(b'0000', ('', 0))
self.socket.close()
def exit(self):
# MRT DONE # MRT DONE
self.socket.setsockopt(socket.IPPROTO_IPV6, self.MRT6_DONE, 1) self.socket.setsockopt(socket.IPPROTO_IPV6, self.MRT6_DONE, 1)
self.socket.close() super().exit()
''' '''
/* /*
......
...@@ -179,10 +179,8 @@ def main(): ...@@ -179,10 +179,8 @@ def main():
if args.start: if args.start:
start() start()
sys.exit(0)
elif args.stop: elif args.stop:
client_socket(args) client_socket(args)
sys.exit(0)
elif args.config: elif args.config:
try: try:
from pimdm import Config from pimdm import Config
...@@ -190,21 +188,18 @@ def main(): ...@@ -190,21 +188,18 @@ def main():
pim_globals.MULTICAST_TABLE_ID, pim_globals.UNICAST_TABLE_ID = Config.get_vrfs(conf_file_path) pim_globals.MULTICAST_TABLE_ID, pim_globals.UNICAST_TABLE_ID = Config.get_vrfs(conf_file_path)
start(conf_file_path) start(conf_file_path)
except (ImportError, ModuleNotFoundError): except (ImportError, ModuleNotFoundError):
sys.exit("PYYAML needs to be installed. Execute \"pip3 install pyyaml\"") raise Exception("PYYAML needs to be installed. Execute \"pip3 install pyyaml\"")
elif args.verbose: elif args.verbose:
os.system("tail -f {}".format(PROCESS_LOG_STDOUT_FILE.format(pim_globals.MULTICAST_TABLE_ID))) os.system("tail -f {}".format(PROCESS_LOG_STDOUT_FILE.format(pim_globals.MULTICAST_TABLE_ID)))
sys.exit(0)
elif args.multicast_routes: elif args.multicast_routes:
if args.ipv4 or not args.ipv6: if args.ipv4 or not args.ipv6:
os.system("ip mroute show table " + str(pim_globals.MULTICAST_TABLE_ID)) os.system("ip mroute show table " + str(pim_globals.MULTICAST_TABLE_ID))
elif args.ipv6: elif args.ipv6:
os.system("ip -6 mroute show table " + str(pim_globals.MULTICAST_TABLE_ID)) os.system("ip -6 mroute show table " + str(pim_globals.MULTICAST_TABLE_ID))
sys.exit(0)
elif not is_running(): elif not is_running():
print("PIM-DM is not running") print("PIM-DM is not running")
parser.print_usage() parser.print_usage()
sys.exit(0) else:
client_socket(args) client_socket(args)
def process_file_path(): def process_file_path():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment