Back to index

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

List of all members.

Public Member Functions

def __init__
def initArgs
def run
def daemonize

Static Public Member Functions

def set_server_launch_mode

Public Attributes

 args
 CMD
 PID
 ARGS

Static Public Attributes

string server_launch_mode = "daemon"

Detailed Description

Definition at line 195 of file runSalome.py.


Constructor & Destructor Documentation

def runSalome.ContainerCPPServer.__init__ (   self,
  args 
)

Reimplemented from server.Server.

Definition at line 196 of file runSalome.py.

00196 
00197     def __init__(self,args):
00198         self.args=args
00199         self.initArgs()
00200         self.CMD=['SALOME_Container','FactoryServer']
00201 
00202 # ---


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:

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

Reimplemented in nameserver.NamingServer.

Definition at line 39 of file server.py.

00039 
00040     def initArgs(self):
00041         self.PID=None
00042         self.CMD=[]
00043         self.ARGS=[]
00044         if self.args.get('xterm'):
00045           if sys.platform != "win32":
00046             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
00047           else:
00048             self.ARGS=['cmd', '/c', 'start  cmd.exe', '/K']

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.

Reimplemented from server.Server.

Definition at line 197 of file runSalome.py.

Reimplemented from server.Server.

Definition at line 199 of file runSalome.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.


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