diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-07-18 22:22:12 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-07-21 08:41:11 +0100 |
commit | 21a19e0e0bf1b39969f6f2ec37a5784d0069715b (patch) | |
tree | 892e7d22ec4cd9dd31196be3fa771803a6017352 | |
parent | 62bd2e365eedaa030fe71e74a0d96fb5b76ad3de (diff) | |
download | poky-21a19e0e0bf1b39969f6f2ec37a5784d0069715b.tar.gz |
bitbake: daemonize: Various fixes
Currently if this code is used with something like oeqa's xml logging
it fails as sys.stdout is an io stream. Add in try/except to handle
this case.
Add a waitpid() call to remove a zombie whilst forking.
Also, append to the logfile, don't overwrite it (otherwise
debugging can be a real pain when the server is restarting for
unknown reasons).
(Bitbake rev: 4e780fa19fc720948cf73133f56f7d837ad9283a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/daemonize.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py index ab4a954622..8380828a17 100644 --- a/bitbake/lib/bb/daemonize.py +++ b/bitbake/lib/bb/daemonize.py | |||
@@ -29,6 +29,7 @@ __version__ = "0.2" | |||
29 | # Standard Python modules. | 29 | # Standard Python modules. |
30 | import os # Miscellaneous OS interfaces. | 30 | import os # Miscellaneous OS interfaces. |
31 | import sys # System-specific parameters and functions. | 31 | import sys # System-specific parameters and functions. |
32 | import io | ||
32 | 33 | ||
33 | # Default daemon parameters. | 34 | # Default daemon parameters. |
34 | # File mode creation mask of the daemon. | 35 | # File mode creation mask of the daemon. |
@@ -124,6 +125,7 @@ def createDaemon(function, logfile): | |||
124 | # streams to be flushed twice and any temporary files may be unexpectedly | 125 | # streams to be flushed twice and any temporary files may be unexpectedly |
125 | # removed. It's therefore recommended that child branches of a fork() | 126 | # removed. It's therefore recommended that child branches of a fork() |
126 | # and the parent branch(es) of a daemon use _exit(). | 127 | # and the parent branch(es) of a daemon use _exit(). |
128 | os.waitpid(pid, 0) | ||
127 | return | 129 | return |
128 | 130 | ||
129 | # Close all open file descriptors. This prevents the child from keeping | 131 | # Close all open file descriptors. This prevents the child from keeping |
@@ -177,16 +179,18 @@ def createDaemon(function, logfile): | |||
177 | # os.dup2(0, 1) # standard output (1) | 179 | # os.dup2(0, 1) # standard output (1) |
178 | # os.dup2(0, 2) # standard error (2) | 180 | # os.dup2(0, 2) # standard error (2) |
179 | 181 | ||
180 | |||
181 | si = open('/dev/null', 'r') | ||
182 | so = open(logfile, 'w') | ||
183 | se = so | ||
184 | |||
185 | |||
186 | # Replace those fds with our own | 182 | # Replace those fds with our own |
183 | si = open('/dev/null', 'r') | ||
187 | os.dup2(si.fileno(), sys.stdin.fileno()) | 184 | os.dup2(si.fileno(), sys.stdin.fileno()) |
188 | os.dup2(so.fileno(), sys.stdout.fileno()) | 185 | |
189 | os.dup2(se.fileno(), sys.stderr.fileno()) | 186 | try: |
187 | so = open(logfile, 'a+') | ||
188 | se = so | ||
189 | os.dup2(so.fileno(), sys.stdout.fileno()) | ||
190 | os.dup2(se.fileno(), sys.stderr.fileno()) | ||
191 | except io.UnsupportedOperation: | ||
192 | sys.stdout = open(logfile, 'a+') | ||
193 | sys.stderr = sys.stdout | ||
190 | 194 | ||
191 | function() | 195 | function() |
192 | 196 | ||