20
21
raise Exception("%s [%d]" % (e.strerror, e.errno))
22
if pid == 0: # The first child.
23
if (pid == 0): # The first child.
26
pid = os.fork() # Fork a second child.
27
pid = os.fork() # Fork a second child.
28
raise Exception("%s [%d]" % (e.strerror, e.errno))
29
raise Exception, "%s [%d]" % (e.strerror, e.errno)
30
if pid == 0: # The second child.
31
if (pid == 0): # The second child.
33
os._exit(0) # Exit parent (the first child) of the second child.
35
os._exit(0) # Exit parent (the first child) of the second child.
35
os._exit(0) # Exit parent of the first child.
37
import resource # Resource usage information.
38
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
39
if (maxfd == resource.RLIM_INFINITY):
42
fd = os.open(REDIRECT_TO, os.O_RDONLY)
44
fd = os.open(REDIRECT_TO, os.O_WRONLY)
48
# Iterate through and close all other file descriptors.
49
for fd in range(3, maxfd):
52
except OSError: # ERROR, fd wasn't open to begin with (ignored)
37
os._exit(0) # Exit parent of the first child.
39
#import resource # Resource usage information.
40
#maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
41
#if (maxfd == resource.RLIM_INFINITY):
44
# Iterate through and close all file descriptors.
45
#for fd in range(3, maxfd):
48
# except OSError: # ERROR, fd wasn't open to begin with (ignored)
51
# This call to open is guaranteed to return the lowest file descriptor,
52
# which will be 0 (stdin), since it was closed above.
53
#os.open(REDIRECT_TO, os.O_RDWR) # standard input (0)
55
# Duplicate standard input to standard output and standard error.
56
#os.dup2(0, 1) # standard output (1)
57
#os.dup2(0, 2) # standard error (2)
55
59
f = open(pidfile, 'w')
56
f.write('%d\n' % os.getpid())
60
f.write('%d\n' % (os.getpid(),))
61
f.write('%s\n' % (home,))