]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Associate ports to application path to prevent from killing *all* applications
authorCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 5 Apr 2017 15:50:08 +0000 (17:50 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 5 Apr 2017 15:50:08 +0000 (17:50 +0200)
bin/PortManager.py

index 7e83d4696e5f6705b6db2e4329227693ce16ff5a..ced2ad296a56f28f7c2f388c0e63bb196362eaea 100644 (file)
@@ -76,19 +76,22 @@ def _getConfigurationFilename():
 
   from salome_utils import generateFileName
   portmanager_config = generateFileName(omniorbUserPath,
-                                        prefix="omniORB",
+                                        prefix="salome",
                                         suffix="PortManager",
                                         extension="cfg",
                                         hidden=True)
   import tempfile
   temp = tempfile.NamedTemporaryFile()
-  lock_file = os.path.join(os.path.dirname(temp.name), ".omniORB_PortManager.lock")
+  lock_file = os.path.join(os.path.dirname(temp.name), ".salome_PortManager.lock")
   temp.close()
 
   return (portmanager_config, lock_file)
 #
 
-def __isPortUsed(port, busy_ports):
+def __isPortUsed(port, config):
+  busy_ports = []
+  for ports in config.values():
+    busy_ports += ports
   return (port in busy_ports) or __isNetworkConnectionActiveOnPort(port)
 #
 
@@ -139,7 +142,7 @@ def getPort(preferedPort=None):
     __acquire_lock(lock)
 
     # read config
-    config = {'busy_ports':[]}
+    config = {}
     logger.debug("read configuration file")
     try:
       with open(config_file, 'r') as f:
@@ -148,14 +151,18 @@ def getPort(preferedPort=None):
       logger.info("Problem loading PortManager file: %s"%config_file)
       # In this case config dictionary is reset
 
-    logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
+    logger.debug("load config: %s"%str(config))
+    appli_path = os.getenv("ABSOLUTE_APPLI_PATH", "unknown")
+    try:
+        config[appli_path]
+    except KeyError:
+        config[appli_path] = []
 
     # append port
-    busy_ports = config["busy_ports"]
     port = preferedPort
-    if not port or __isPortUsed(port, busy_ports):
+    if not port or __isPortUsed(port, config):
       port = __PORT_MIN_NUMBER
-      while __isPortUsed(port, busy_ports):
+      while __isPortUsed(port, config):
         if port == __PORT_MAX_NUMBER:
           msg  = "\n"
           msg += "Can't find a free port to launch omniNames\n"
@@ -164,10 +171,10 @@ def getPort(preferedPort=None):
         logger.debug("Port %s seems to be busy"%str(port))
         port = port + 1
     logger.debug("found free port: %s"%str(port))
-    config["busy_ports"].append(port)
+    config[appli_path].append(port)
 
-    # write config, for this application only (i.e. no 'other' ports)
-    logger.debug("write busy_ports: %s"%str(config["busy_ports"]))
+    # write config
+    logger.debug("write config: %s"%str(config))
     try:
       with open(config_file, 'w') as f:
         pickle.dump(config, f)
@@ -194,7 +201,7 @@ def releasePort(port):
     __acquire_lock(lock)
 
     # read config
-    config = {'busy_ports':[]}
+    config = {}
     logger.debug("read configuration file")
     try:
       with open(config_file, 'r') as f:
@@ -202,14 +209,19 @@ def releasePort(port):
     except IOError: # empty file
       pass
 
-    logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
+    logger.debug("load config: %s"%str(config))
+    appli_path = os.getenv("ABSOLUTE_APPLI_PATH", "unknown")
+    try:
+        config[appli_path]
+    except KeyError:
+        config[appli_path] = []
 
     # remove port from list
-    ports_info = config["busy_ports"]
-    config["busy_ports"] = [x for x in ports_info if x != port]
+    ports_info = config[appli_path]
+    config[appli_path] = [x for x in ports_info if x != port]
 
-    # write config, for this application only (i.e. no 'other' ports)
-    logger.debug("write busy_ports: %s"%str(config["busy_ports"]))
+    # write config
+    logger.debug("write config: %s"%str(config))
     try:
       with open(config_file, 'w') as f:
         pickle.dump(config, f)
@@ -232,7 +244,7 @@ def getBusyPorts():
     __acquire_lock(lock)
 
     # read config
-    config = {'busy_ports':[]}
+    config = {}
     logger.debug("read configuration file")
     try:
       with open(config_file, 'r') as f:
@@ -240,15 +252,20 @@ def getBusyPorts():
     except IOError: # empty file
       pass
 
-    logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
+    logger.debug("load config: %s"%str(config))
+    appli_path = os.getenv("ABSOLUTE_APPLI_PATH", "unknown")
+    try:
+        config[appli_path]
+    except KeyError:
+        config[appli_path] = []
 
     # Scan all possible ports to determine which ones are owned by other applications
     ports_info = { 'this': [], 'other': [] }
-    busy_ports = config["busy_ports"]
+    my_busy_ports = config[appli_path]
     for port in range(__PORT_MIN_NUMBER, __PORT_MAX_NUMBER):
-      if __isPortUsed(port, busy_ports):
+      if __isPortUsed(port, config):
         logger.debug("Port %s seems to be busy"%str(port))
-        if port in busy_ports:
+        if port in my_busy_ports:
           ports_info["this"].append(port)
         else:
           ports_info["other"].append(port)