Back to index

salome-kernel  6.5.0
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
nameserver.NamingServer Class Reference
Inheritance diagram for nameserver.NamingServer:
Inheritance graph
[legend]
Collaboration diagram for nameserver.NamingServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initNSArgs
def initArgs
def run
def daemonize

Static Public Member Functions

def set_server_launch_mode

Public Attributes

 CMD
 PID
 ARGS
 args

Static Public Attributes

string XTERM = ""
tuple USER = os.getenv('USER')
string USER = 'anonymous'
string LOGDIR = "/tmp/logs/"
string server_launch_mode = "daemon"

Detailed Description

Definition at line 33 of file nameserver.py.


Member Function Documentation

def server.Server.daemonize (   self,
  args 
) [inherited]

Definition at line 88 of file server.py.

00088 
00089     def daemonize(self,args):
00090         # to daemonize a process need to do the UNIX double-fork magic
00091         # see Stevens, "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177)
00092         # and UNIX Programming FAQ 1.7 How do I get my program to act like a daemon?
00093         #     http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
00094         #open a pipe
00095         c2pread, c2pwrite = os.pipe()
00096         #do first fork
00097         pid=os.fork()
00098         if pid > 0:
00099           #first parent
00100           os.close(c2pwrite)
00101           #receive real pid from child
00102           data=os.read(c2pread,24) #read 24 bytes
00103           os.waitpid(pid,0) #remove zombie
00104           os.close(c2pread)
00105           # return : first parent
00106           childpid=int(data)
00107           if childpid==-1:
00108             return None
00109           try:
00110             os.kill(childpid,0)
00111             return childpid
00112           except:
00113             return None
00114 
00115         #first child
00116         # decouple from parent environment
00117         os.setsid()
00118         os.close(c2pread)
00119 
00120         # do second fork : second child not a session leader
00121         try:
00122           pid = os.fork()
00123           if pid > 0:
00124             #send real pid to parent
00125             os.write(c2pwrite,"%d" % pid)
00126             os.close(c2pwrite)
00127             # exit from second parent
00128             os._exit(0)
00129         except OSError, e:
00130           print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
00131           os.write(c2pwrite,"-1")
00132           os.close(c2pwrite)
00133           sys.exit(1)
00134 
00135         #I am a daemon
00136         os.close(0) #close stdin
00137         os.open("/dev/null", os.O_RDWR)  # redirect standard input (0) to /dev/null
00138         try:
00139           os.execvp(args[0], args)
00140         except OSError, e:
00141           if args[0] != "notifd":
00142             print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror)
00143             pass
00144           os._exit(127)

Here is the caller graph for this function:

Reimplemented from server.Server.

Definition at line 124 of file nameserver.py.

00124 
00125    def initArgs(self):
00126         Server.initArgs(self)
00127         if sys.platform == "win32":
00128           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
00129         else:
00130           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
00131         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
00132         self.initNSArgs()
00133 
00134 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
00135 #    computer if this Container does not exist. Default is localhost.
00136 #    Others Containers are started with start_impl method of FactoryServer Container.
00137 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
00138 # Warning : on RedHat the file /etc/hosts contains by default a line like :
00139 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
00140 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
00141 #   computers only if the computer name is removed on that line like :
00142 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
00143 
00144 # To start dynamically Containers on several computers you need to
00145 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
00146 # example : ORBInitRef NameService=corbaname::dm2s0017
00147 
00148 # If you need to use several omniNames running on the same computer, you have to :
00149 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
00150 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
00151 #2. start omninames with this port number like in orbmodile.py
00152 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &

Here is the call graph for this function:

Definition at line 41 of file nameserver.py.

00041 
00042    def initNSArgs(self):
00043         if sys.platform == "win32":
00044           # temporarily using home directory for Namning Service logs
00045           # to be replaced with TEMP later...
00046           os.environ["BaseDir"]=os.environ["HOME"]
00047         else:
00048           os.environ["BaseDir"]="/tmp"
00049 
00050         try:
00051           os.mkdir(os.environ["BaseDir"] + "/logs")
00052           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
00053         except:
00054           #print "Can't create " + os.environ["BaseDir"] + "/logs"
00055           pass
00056 
00057         upath = os.environ["BaseDir"] + "/logs/";
00058         if sys.platform == "win32":
00059            upath += os.environ["Username"];
00060         else:
00061            upath += os.environ["USER"];
00062 
00063         try:
00064           os.mkdir(upath)
00065         except:
00066           #print "Can't create " + upath
00067           pass
00068 
00069         if verbose(): print "Name Service... ",
00070         #hname=os.environ["HOST"] #commands.getoutput("hostname")
00071         if sys.platform == "win32":
00072           hname=getShortHostName();
00073         else:
00074           hname = socket.gethostname();
00075         #print "hname=",hname
00076 
00077         f=open(os.environ["OMNIORB_CONFIG"])
00078         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
00079         if verbose(): print "ss = ", ss,
00080         f.close()
00081         sl=ss[0]
00082         ll = sl.split(':')
00083         aPort = ll[-1]
00084         #aPort=(ss.join().split(':'))[2];
00085         #aPort=re.findall("\d+", ss[0])[0]
00086 
00087         # \begin{E.A.}
00088         # put the log files of omniNames in different directory with port reference,
00089         # it is cleaner on linux and it is a fix for salome since it is impossible to
00090         # remove the log files if the corresponding omniNames has not been killed.
00091         # \end{E.A.}
00092         
00093         upath += "/omniNames_%s"%(aPort)
00094         try:
00095            os.mkdir(upath)
00096         except:
00097            #print "Can't create " + upath
00098            pass
00099         
00100         #os.system("touch " + upath + "/dummy")
00101         for fname in os.listdir(upath):
00102           try:
00103              os.remove(upath + "/" + fname)
00104           except:
00105             pass
00106         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
00107 
00108         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
00109         #print "sed command = ", aSedCommand
00110         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
00111         #print "port=", aPort
00112         if sys.platform == "win32":
00113           #print "start omniNames -start " + aPort + " -logdir " + upath
00114           self.CMD=['omniNames -start ' , aPort , ' -nohostname ', ' -logdir ' , '\"' + upath + '\"', ' -errlog', '\"' + upath+'/omniNameErrors.log' + '\"']
00115           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
00116         else:
00117           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
00118           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
00119           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
00120 
00121         if verbose(): print "... ok"
00122         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
00123 

Here is the call graph for this function:

Here is the caller graph for this function:

def server.Server.run (   self) [inherited]

Reimplemented in runSalome.InterpServer.

Definition at line 60 of file server.py.

00060 
00061     def run(self):
00062         global process_id
00063         myargs=self.ARGS
00064         if self.args.get('xterm'):
00065             # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
00066             if sys.platform != "win32":
00067               env_ld_library_path=['env', 'LD_LIBRARY_PATH='
00068                                    + os.getenv("LD_LIBRARY_PATH")]
00069               myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
00070         command = myargs + self.CMD
00071         #print "command = ", command
00072         if sys.platform == "win32":
00073           import win32pm
00074           #cmd_str = "\"" + string.join(command, " ") + "\""
00075           #print cmd_str
00076           #pid = win32pm.spawnpid( cmd_str )
00077           pid = win32pm.spawnpid( string.join(command, " "), '-nc' )
00078           #pid = win32pm.spawnpid( string.join(command, " ") )
00079         elif Server.server_launch_mode == "fork":
00080           pid = os.spawnvp(os.P_NOWAIT, command[0], command)
00081         else: # Server launch mode is daemon
00082           pid=self.daemonize(command)
00083         if pid is not None:
00084           #store process pid if it really exists
00085           process_id[pid]=self.CMD
00086         self.PID = pid
00087         return pid

Here is the call graph for this function:

def server.Server.set_server_launch_mode (   mode) [static, inherited]

Definition at line 54 of file server.py.

00054 
00055     def set_server_launch_mode(mode):
00056       if mode == "daemon" or mode == "fork":
00057         Server.server_launch_mode = mode
00058       else:
00059         raise Exception("Unsupported server launch mode: %s" % mode)


Member Data Documentation

server.Server.ARGS [inherited]

Definition at line 42 of file server.py.

server.Server.args [inherited]

Reimplemented from server.Server.

Definition at line 113 of file nameserver.py.

string nameserver.NamingServer.LOGDIR = "/tmp/logs/" [static]

Definition at line 39 of file nameserver.py.

server.Server.PID [inherited]

Reimplemented in runSalome.InterpServer.

Definition at line 40 of file server.py.

string server.Server.server_launch_mode = "daemon" [static, inherited]

Definition at line 37 of file server.py.

tuple nameserver.NamingServer.USER = os.getenv('USER') [static]

Definition at line 35 of file nameserver.py.

string nameserver.NamingServer.USER = 'anonymous' [static]

Definition at line 37 of file nameserver.py.

string nameserver.NamingServer.XTERM = "" [static]

Definition at line 34 of file nameserver.py.


The documentation for this class was generated from the following file: