]> git.puffer.fish Git - mirror/frr.git/commitdiff
munet: import 0.12.15
authorChristian Hopps <chopps@labn.net>
Thu, 20 Apr 2023 23:21:59 +0000 (19:21 -0400)
committerChristian Hopps <chopps@labn.net>
Sat, 22 Apr 2023 17:10:52 +0000 (13:10 -0400)
Signed-off-by: Christian Hopps <chopps@labn.net>
tests/topotests/munet/cli.py
tests/topotests/munet/mutini.py

index 45db3990c7847b0d6a4e09b3645bd6fd6677b3d1..f58ea99d67b739965926064ef16c2593fbf76b75 100644 (file)
@@ -24,8 +24,17 @@ import tempfile
 import termios
 import tty
 
-from . import linux
-from .config import list_to_dict_with_key
+
+try:
+    from . import linux
+    from .config import list_to_dict_with_key
+except ImportError:
+    # We cannot use relative imports and still run this module directly as a script, and
+    # there are some use cases where we want to run this file as a script.
+    sys.path.append(os.path.dirname(os.path.realpath(__file__)))
+    import linux
+
+    from config import list_to_dict_with_key
 
 
 ENDMARKER = b"\x00END\x00"
@@ -609,7 +618,16 @@ async def doline(
         return True
 
     await run_command(
-        unet, outf, nline, execfmt, banner, hosts, toplevel, kinds, ns_only, interactive
+        unet,
+        outf,
+        nline,
+        execfmt,
+        banner,
+        hosts,
+        toplevel,
+        kinds,
+        ns_only,
+        interactive,
     )
 
     return True
@@ -657,10 +675,10 @@ async def cli_client(sockpath, prompt="munet> "):
 
 async def local_cli(unet, outf, prompt, histfile, background):
     """Implement the user-side CLI for local munet."""
-    if unet:
-        completer = Completer(unet)
-        readline.parse_and_bind("tab: complete")
-        readline.set_completer(completer.complete)
+    assert unet is not None
+    completer = Completer(unet)
+    readline.parse_and_bind("tab: complete")
+    readline.set_completer(completer.complete)
 
     print("\n--- Munet CLI Starting ---\n\n")
     while True:
@@ -669,8 +687,6 @@ async def local_cli(unet, outf, prompt, histfile, background):
             if line is None:
                 return
 
-            assert unet is not None
-
             if not await doline(unet, line, outf, background):
                 return
         except KeyboardInterrupt:
@@ -706,10 +722,19 @@ async def cli_client_connected(unet, background, reader, writer):
             break
         line = line.decode("utf-8").strip()
 
-        # def writef(x):
-        #     writer.write(x.encode("utf-8"))
+        class EncodingFile:
+            """Wrap a writer to encode in utf-8."""
+
+            def __init__(self, writer):
+                self.writer = writer
+
+            def write(self, x):
+                self.writer.write(x.encode("utf-8"))
+
+            def flush(self):
+                self.writer.flush()
 
-        if not await doline(unet, line, writer, background, notty=True):
+        if not await doline(unet, line, EncodingFile(writer), background, notty=True):
             logging.debug("server closing cli connection")
             return
 
index e805f3245dd49543a05b176032269824b061ef8b..e5f9931714000ffad9894b7140bde067d0861635 100755 (executable)
@@ -296,8 +296,12 @@ def be_init(new_pg, exec_args):
             # No exec so we are the "child".
             new_process_group()
 
+        # Reap children as init process
+        vdebug("installing local handler for SIGCHLD")
+        signal.signal(signal.SIGCHLD, sig_sigchld)
+
         while True:
-            logging.info("parent: waiting to reap zombies")
+            logging.info("init: waiting to reap zombies")
             linux.pause()
         # NOTREACHED