Revision 71ab9dbe
b/lib/utils/__init__.py | ||
---|---|---|
362 | 362 |
# Well, maybe child process failed |
363 | 363 |
os._exit(1) # pylint: disable-msg=W0212 |
364 | 364 |
finally: |
365 |
_CloseFDNoErr(errpipe_write)
|
|
365 |
CloseFdNoError(errpipe_write)
|
|
366 | 366 |
|
367 | 367 |
# Wait for daemon to be started (or an error message to |
368 | 368 |
# arrive) and read up to 100 KB as an error message |
369 | 369 |
errormsg = RetryOnSignal(os.read, errpipe_read, 100 * 1024) |
370 | 370 |
finally: |
371 |
_CloseFDNoErr(errpipe_read)
|
|
371 |
CloseFdNoError(errpipe_read)
|
|
372 | 372 |
finally: |
373 |
_CloseFDNoErr(pidpipe_write)
|
|
373 |
CloseFdNoError(pidpipe_write)
|
|
374 | 374 |
|
375 | 375 |
# Read up to 128 bytes for PID |
376 | 376 |
pidtext = RetryOnSignal(os.read, pidpipe_read, 128) |
377 | 377 |
finally: |
378 |
_CloseFDNoErr(pidpipe_read)
|
|
378 |
CloseFdNoError(pidpipe_read)
|
|
379 | 379 |
|
380 | 380 |
# Try to avoid zombies by waiting for child process |
381 | 381 |
try: |
... | ... | |
403 | 403 |
""" |
404 | 404 |
try: |
405 | 405 |
# Close parent's side |
406 |
_CloseFDNoErr(errpipe_read)
|
|
407 |
_CloseFDNoErr(pidpipe_read)
|
|
406 |
CloseFdNoError(errpipe_read)
|
|
407 |
CloseFdNoError(pidpipe_read)
|
|
408 | 408 |
|
409 | 409 |
# First child process |
410 | 410 |
SetupDaemonEnv() |
... | ... | |
1934 | 1934 |
return True, None |
1935 | 1935 |
|
1936 | 1936 |
|
1937 |
def _CloseFDNoErr(fd, retries=5):
|
|
1937 |
def CloseFdNoError(fd, retries=5):
|
|
1938 | 1938 |
"""Close a file descriptor ignoring errors. |
1939 | 1939 |
|
1940 | 1940 |
@type fd: int |
... | ... | |
1949 | 1949 |
except OSError, err: |
1950 | 1950 |
if err.errno != errno.EBADF: |
1951 | 1951 |
if retries > 0: |
1952 |
_CloseFDNoErr(fd, retries - 1)
|
|
1952 |
CloseFdNoError(fd, retries - 1)
|
|
1953 | 1953 |
# else either it's closed already or we're out of retries, so we |
1954 | 1954 |
# ignore this and go on |
1955 | 1955 |
|
... | ... | |
1983 | 1983 |
for fd in range(3, maxfd): |
1984 | 1984 |
if noclose_fds and fd in noclose_fds: |
1985 | 1985 |
continue |
1986 |
_CloseFDNoErr(fd)
|
|
1986 |
CloseFdNoError(fd)
|
|
1987 | 1987 |
|
1988 | 1988 |
|
1989 | 1989 |
def Daemonize(logfile): |
... | ... | |
2015 | 2015 |
# this might fail |
2016 | 2016 |
pid = os.fork() # Fork a second child. |
2017 | 2017 |
if (pid == 0): # The second child. |
2018 |
_CloseFDNoErr(rpipe)
|
|
2018 |
CloseFdNoError(rpipe)
|
|
2019 | 2019 |
else: |
2020 | 2020 |
# exit() or _exit()? See below. |
2021 | 2021 |
os._exit(0) # Exit parent (the first child) of the second child. |
2022 | 2022 |
else: |
2023 |
_CloseFDNoErr(wpipe)
|
|
2023 |
CloseFdNoError(wpipe)
|
|
2024 | 2024 |
# Wait for daemon to be started (or an error message to |
2025 | 2025 |
# arrive) and read up to 100 KB as an error message |
2026 | 2026 |
errormsg = RetryOnSignal(os.read, rpipe, 100 * 1024) |
... | ... | |
2820 | 2820 |
|
2821 | 2821 |
""" |
2822 | 2822 |
(fd, path) = tempfile.mkstemp(*args, **kwargs) |
2823 |
_CloseFDNoErr(fd)
|
|
2823 |
CloseFdNoError(fd)
|
|
2824 | 2824 |
return path |
2825 | 2825 |
|
2826 | 2826 |
|
Also available in: Unified diff