bugfix: EINTRs caught
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 12 Jun 2011 10:37:23 +0000 (12:37 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 12 Jun 2011 10:37:23 +0000 (12:37 +0200)
src/nepi/testbeds/netns/execute.py
src/nepi/testbeds/ns3/execute.py
src/nepi/util/server.py

index a76547a..9ac839f 100644 (file)
@@ -12,6 +12,9 @@ class TestbedController(testbed_impl.TestbedController):
     from nepi.util.tunchannel_impl import TunChannel
     
     class HostLock(object):
+        # This class is used as a lock to prevent concurrency issues with more
+        # than one instance of netns running in the same machine. Both in 
+        # different processes or different threads.
         taken = False
         processcond = threading.Condition()
         
index 754c206..5f9bb72 100644 (file)
@@ -55,6 +55,7 @@ class TestbedController(testbed_impl.TestbedController):
         self._condition = threading.Condition()
         self._simulator_thread = threading.Thread(target = self._simulator_run,
                 args = [self._condition])
+        self._simulator_thread.setDaemon(True)
         self._simulator_thread.start()
 
     def stop(self, time = TIME_NOW):
@@ -130,10 +131,11 @@ class TestbedController(testbed_impl.TestbedController):
                 element.Cleanup()
         self._elements.clear()
         if self.ns3:
-            #self.ns3.Simulator.Stop()
-            self._stop_simulation("0s")
-            if self._simulator_thread:
-                self._simulator_thread.join()
+            self.ns3.Simulator.Stop()
+            #self._stop_simulation("0s")
+        # TODO!!!! SHOULD WAIT UNTIL THE THREAD FINISHES
+        #   if self._simulator_thread:
+        #       self._simulator_thread.join()
             self.ns3.Simulator.Destroy()
         self._ns3 = None
         sys.stdout.flush()
index aa39343..0491b55 100644 (file)
@@ -32,8 +32,6 @@ if hasattr(os, "devnull"):
 else:
     DEV_NULL = "/dev/null"
 
-
-
 SHELL_SAFE = re.compile('^[-a-zA-Z0-9_=+:.,/]*$')
 
 def shell_escape(s):
@@ -88,7 +86,15 @@ class Server(object):
         pid1 = os.fork()
         if pid1 > 0:
             os.close(w)
-            os.read(r, 1)
+            while True:
+                try:
+                    os.read(r, 1)
+                except OSError, e: # pragma: no cover
+                    if e.errno == errno.EINTR:
+                        continue
+                    else:
+                        raise
+                break
             os.close(r)
             # os.waitpid avoids leaving a <defunc> (zombie) process
             st = os.waitpid(pid1, 0)[1]