2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import os, sys, string
26 # -----------------------------------------------------------------------------
28 # Definition des classes d'objets pour le lancement des Server CORBA
32 """Generic class for CORBA server launch"""
38 if self.args.get('xterm'):
39 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
41 def __init__(self,args):
49 if self.args.get('xterm'):
50 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
51 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
52 + os.getenv("LD_LIBRARY_PATH")]
53 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
54 command = myargs + self.CMD
55 #print "command = ", command
56 if sys.platform == "win32":
58 #cmd_str = "\"" + string.join(command, " ") + "\""
60 #pid = win32pm.spawnpid( cmd_str )
61 pid = win32pm.spawnpid( string.join(command, " "), '-nc' )
62 #pid = win32pm.spawnpid( string.join(command, " ") )
64 #pid = os.spawnvp(os.P_NOWAIT, command[0], command)
65 pid=self.daemonize(command)
67 #store process pid if it really exists
68 process_id[pid]=self.CMD
72 def daemonize(self,args):
73 # to daemonize a process need to do the UNIX double-fork magic
74 # see Stevens, "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177)
75 # and UNIX Programming FAQ 1.7 How do I get my program to act like a daemon?
76 # http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
78 c2pread, c2pwrite = os.pipe()
84 #receive real pid from child
85 data=os.read(c2pread,24) #read 24 bytes
86 os.waitpid(pid,0) #remove zombie
88 # return : first parent
99 # decouple from parent environment
103 # do second fork : second child not a session leader
107 #send real pid to parent
108 os.write(c2pwrite,"%d" % pid)
110 # exit from second parent
113 print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
114 os.write(c2pwrite,"-1")
119 os.close(0) #close stdin
120 os.open("/dev/null", os.O_RDWR) # redirect standard input (0) to /dev/null
122 os.execvp(args[0], args)
124 print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror)