Revision 3c9a0742 daemons/ganeti-noded
b/daemons/ganeti-noded | ||
---|---|---|
366 | 366 |
pid = os.fork() |
367 | 367 |
except OSError, e: |
368 | 368 |
raise Exception, "%s [%d]" % (e.strerror, e.errno) |
369 |
if (pid == 0): # The first child.
|
|
369 |
if (pid == 0): # The first child.
|
|
370 | 370 |
os.setsid() |
371 | 371 |
try: |
372 |
pid = os.fork() # Fork a second child.
|
|
372 |
pid = os.fork() # Fork a second child.
|
|
373 | 373 |
except OSError, e: |
374 | 374 |
raise Exception, "%s [%d]" % (e.strerror, e.errno) |
375 |
if (pid == 0): # The second child.
|
|
375 |
if (pid == 0): # The second child.
|
|
376 | 376 |
os.chdir(WORKDIR) |
377 | 377 |
os.umask(UMASK) |
378 | 378 |
else: |
379 | 379 |
# exit() or _exit()? See below. |
380 |
os._exit(0) # Exit parent (the first child) of the second child.
|
|
380 |
os._exit(0) # Exit parent (the first child) of the second child.
|
|
381 | 381 |
else: |
382 |
os._exit(0) # Exit parent of the first child.
|
|
382 |
os._exit(0) # Exit parent of the first child.
|
|
383 | 383 |
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] |
384 | 384 |
if (maxfd == resource.RLIM_INFINITY): |
385 | 385 |
maxfd = MAXFD |
... | ... | |
388 | 388 |
for fd in range(0, maxfd): |
389 | 389 |
try: |
390 | 390 |
os.close(fd) |
391 |
except OSError: # ERROR, fd wasn't open to begin with (ignored)
|
|
391 |
except OSError: # ERROR, fd wasn't open to begin with (ignored)
|
|
392 | 392 |
pass |
393 | 393 |
os.open(REDIRECT_TO, os.O_RDWR|os.O_CREAT|os.O_APPEND) # standard input (0) |
394 | 394 |
# Duplicate standard input to standard output and standard error. |
395 |
os.dup2(0, 1) # standard output (1)
|
|
396 |
os.dup2(0, 2) # standard error (2)
|
|
395 |
os.dup2(0, 1) # standard output (1)
|
|
396 |
os.dup2(0, 2) # standard error (2)
|
|
397 | 397 |
return(0) |
398 | 398 |
|
399 | 399 |
|
Also available in: Unified diff